浏览代码

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@312484 91177308-0d34-0410-b5e6-96231b3b80d8
Daniel Jasper 8 年之前
父节点
当前提交
c55c0db172
共有 2 个文件被更改,包括 12 次插入5 次删除
  1. 3 4
      lib/Format/UnwrappedLineParser.cpp
  2. 9 1
      unittests/Format/FormatTest.cpp

+ 3 - 4
lib/Format/UnwrappedLineParser.cpp

@@ -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() {

+ 9 - 1
unittests/Format/FormatTest.cpp

@@ -2332,7 +2332,6 @@ TEST_F(FormatTest, IndentPreprocessorDirectives) {
                "#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, IndentPreprocessorDirectives) {
                "#\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) {