From da9b85642632953df17160488a1aa4e37339484a Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Thu, 18 Jun 2015 15:45:17 +0000 Subject: [PATCH] clang-format: Better support functions with elaborated enum return types. Before, this wasn't formatted properly: enum ::C f() { return a; } git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@240021 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Format/UnwrappedLineParser.cpp | 2 ++ unittests/Format/FormatTest.cpp | 14 +++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/Format/UnwrappedLineParser.cpp b/lib/Format/UnwrappedLineParser.cpp index aa46e7464c..6846158fb3 100644 --- a/lib/Format/UnwrappedLineParser.cpp +++ b/lib/Format/UnwrappedLineParser.cpp @@ -1491,6 +1491,8 @@ void UnwrappedLineParser::parseEnum() { while (FormatTok->Tok.getIdentifierInfo() || FormatTok->isOneOf(tok::colon, tok::coloncolon, tok::less, tok::greater, tok::comma, tok::question)) { + if (FormatTok->is(tok::coloncolon)) + nextToken(); nextToken(); // We can have macros or attributes in between 'enum' and the enum name. if (FormatTok->is(tok::l_paren)) diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index ea5ff189da..122a1a6c5f 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -1996,7 +1996,6 @@ TEST_F(FormatTest, FormatsEnum) { verifyFormat("enum X E {} d;"); verifyFormat("enum __attribute__((...)) E {} d;"); verifyFormat("enum __declspec__((...)) E {} d;"); - verifyFormat("enum X f() {\n a();\n return 42;\n}"); verifyFormat("enum {\n" " Bar = Foo::value\n" "};", @@ -2025,6 +2024,19 @@ TEST_F(FormatTest, FormatsEnum) { " TWO\n" "};\n" "int i;"); + // Not enums. + verifyFormat("enum X f() {\n" + " a();\n" + " return 42;\n" + "}"); + verifyFormat("enum ::X f() {\n" + " a();\n" + " return 42;\n" + "}"); + verifyFormat("enum ns::X f() {\n" + " a();\n" + " return 42;\n" + "}"); } TEST_F(FormatTest, FormatsEnumsWithErrors) { -- 2.40.0