From f68ad12985dd957b0661f07a524b2645d33f41bc Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Fri, 19 Jun 2015 08:17:32 +0000 Subject: [PATCH] clang-format: Better fix to detect elaborated enum return types. The previous one (r240021) regressed: enum E Type::f() { .. } git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@240127 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Format/UnwrappedLineParser.cpp | 11 ++++++++--- unittests/Format/FormatTest.cpp | 4 ++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/Format/UnwrappedLineParser.cpp b/lib/Format/UnwrappedLineParser.cpp index 6846158fb3..ea1ca39870 100644 --- a/lib/Format/UnwrappedLineParser.cpp +++ b/lib/Format/UnwrappedLineParser.cpp @@ -1488,17 +1488,22 @@ void UnwrappedLineParser::parseEnum() { // Eat up enum class ... if (FormatTok->Tok.is(tok::kw_class) || FormatTok->Tok.is(tok::kw_struct)) nextToken(); + 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)) parseParens(); - if (FormatTok->is(tok::identifier)) + if (FormatTok->is(tok::identifier)) { nextToken(); + // If there are two identifiers in a row, this is likely an elaborate + // return type. In Java, this can be "implements", etc. + if (Style.Language == FormatStyle::LK_Cpp && + FormatTok->is(tok::identifier)) + return; + } } // Just a declaration or something is wrong. diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 418b7aceea..30bc5b2cd1 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -2029,6 +2029,10 @@ TEST_F(FormatTest, FormatsEnum) { " a();\n" " return 42;\n" "}"); + verifyFormat("enum X Type::f() {\n" + " a();\n" + " return 42;\n" + "}"); verifyFormat("enum ::X f() {\n" " a();\n" " return 42;\n" -- 2.40.0