From: Daniel Jasper Date: Wed, 13 May 2015 11:35:53 +0000 (+0000) Subject: clang-format: Fix semicolon less macro-detection. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9d1d803853210988fcb5a62b5c7d9d06e60d77dd;p=clang clang-format: Fix semicolon less macro-detection. It was fooled by the comment. Before: SOME_UNRELATED_MACRO /*static*/ int i; After: SOME_UNRELATED_MACRO /*static*/ int i; git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@237246 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/UnwrappedLineParser.cpp b/lib/Format/UnwrappedLineParser.cpp index 6dee251a91..b596553bc0 100644 --- a/lib/Format/UnwrappedLineParser.cpp +++ b/lib/Format/UnwrappedLineParser.cpp @@ -863,7 +863,13 @@ void UnwrappedLineParser::parseStructuralElement() { bool FunctionLike = FormatTok->is(tok::l_paren); if (FunctionLike) parseParens(); - if (FormatTok->NewlinesBefore > 0 && + + bool FollowedByNewline = + CommentsBeforeNextToken.empty() + ? FormatTok->NewlinesBefore > 0 + : CommentsBeforeNextToken.front()->NewlinesBefore > 0; + + if (FollowedByNewline && (Text.size() >= 5 || FunctionLike) && tokenCanStartNewLine(FormatTok->Tok) && Text == Text.upper()) { addUnwrappedLine(); @@ -1748,14 +1754,12 @@ void UnwrappedLineParser::flushComments(bool NewlineBeforeNext) { I = CommentsBeforeNextToken.begin(), E = CommentsBeforeNextToken.end(); I != E; ++I) { - if (isOnNewLine(**I) && JustComments) { + if (isOnNewLine(**I) && JustComments) addUnwrappedLine(); - } pushToken(*I); } - if (NewlineBeforeNext && JustComments) { + if (NewlineBeforeNext && JustComments) addUnwrappedLine(); - } CommentsBeforeNextToken.clear(); } diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 105d1a1125..d6f0c08bf0 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -2804,6 +2804,10 @@ TEST_F(FormatTest, MacrosWithoutTrailingSemicolon) { "\n" " A() {\n}\n" "} ;")); + EXPECT_EQ("MACRO\n" + "/*static*/ int i;", + format("MACRO\n" + " /*static*/ int i;")); EXPECT_EQ("SOME_MACRO\n" "namespace {\n" "void f();\n"