Author: djasper Date: Mon Sep 4 06:33:52 2017 New Revision: 312484 URL: http://llvm.org/viewvc/llvm-project?rev=312484&view=rev Log: clang-format: Fix indentation of macros in include guards (after r312125).
Before: #ifndef A_H #define A_H #define A() \ int i; \ int j; #endif // A_H After: #ifndef A_H #define A_H #define A() \ int i; \ int j; #endif // A_H Modified: cfe/trunk/lib/Format/UnwrappedLineParser.cpp cfe/trunk/unittests/Format/FormatTest.cpp Modified: cfe/trunk/lib/Format/UnwrappedLineParser.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/UnwrappedLineParser.cpp?rev=312484&r1=312483&r2=312484&view=diff ============================================================================== --- cfe/trunk/lib/Format/UnwrappedLineParser.cpp (original) +++ cfe/trunk/lib/Format/UnwrappedLineParser.cpp Mon Sep 4 06:33:52 2017 @@ -742,12 +742,11 @@ void UnwrappedLineParser::parsePPEndIf() // preprocessor indent. unsigned TokenPosition = Tokens->getPosition(); FormatToken *PeekNext = AllTokens[TokenPosition]; - if (FoundIncludeGuardStart && PPBranchLevel == -1 && PeekNext->is(tok::eof)) { - for (auto &Line : Lines) { + if (FoundIncludeGuardStart && PPBranchLevel == -1 && PeekNext->is(tok::eof) && + Style.IndentPPDirectives != FormatStyle::PPDIS_None) + for (auto &Line : Lines) if (Line.InPPDirective && Line.Level > 0) --Line.Level; - } - } } void UnwrappedLineParser::parsePPDefine() { Modified: cfe/trunk/unittests/Format/FormatTest.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=312484&r1=312483&r2=312484&view=diff ============================================================================== --- cfe/trunk/unittests/Format/FormatTest.cpp (original) +++ cfe/trunk/unittests/Format/FormatTest.cpp Mon Sep 4 06:33:52 2017 @@ -2332,7 +2332,6 @@ TEST_F(FormatTest, IndentPreprocessorDir "#define A 1\n" "#endif", Style); - Style.IndentPPDirectives = FormatStyle::PPDIS_AfterHash; verifyFormat("#ifdef _WIN32\n" "# define A 0\n" @@ -2493,6 +2492,15 @@ TEST_F(FormatTest, IndentPreprocessorDir "#\tdefine A 1\n" "#endif", Style); + + // Regression test: Multiline-macro inside include guards. + verifyFormat("#ifndef HEADER_H\n" + "#define HEADER_H\n" + "#define A() \\\n" + " int i; \\\n" + " int j;\n" + "#endif // HEADER_H", + getLLVMStyleWithColumns(20)); } TEST_F(FormatTest, FormatHashIfNotAtStartOfLine) { _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits