]> granicus.if.org Git - clang/commitdiff
clang-format: Fix incorrect indentation in last line of macro definition
authorDaniel Jasper <djasper@google.com>
Thu, 19 May 2016 06:30:48 +0000 (06:30 +0000)
committerDaniel Jasper <djasper@google.com>
Thu, 19 May 2016 06:30:48 +0000 (06:30 +0000)
Before:
  #define MACRO(a) \
    if (a) {       \
      f();         \
    } else         \
    g()

After:
  #define MACRO(a) \
    if (a) {       \
      f();         \
    } else         \
      g()

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@270028 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Format/UnwrappedLineParser.cpp
unittests/Format/FormatTest.cpp

index c8e4cc4a1b627a98fcbcfbd51f86f6d773ccee9e..e14b2b44e8ea2ecb15f0e4c4d2dba1e96b60893e 100644 (file)
@@ -1430,6 +1430,8 @@ void UnwrappedLineParser::parseIfThenElse() {
       addUnwrappedLine();
       ++Line->Level;
       parseStructuralElement();
+      if (FormatTok->is(tok::eof))
+        addUnwrappedLine();
       --Line->Level;
     }
   } else if (NeedsUnwrappedLine) {
index aec801ccc98936ead9a31d631feede6ce9bac37c..27379b7d6c7e21dc829e7ce81c8d9e6bc9c7947c 100644 (file)
@@ -2767,6 +2767,12 @@ TEST_F(FormatTest, MacroDefinitionsWithIncompleteCode) {
                "  case 1:          \\\n"
                "  case 2\n",
                getLLVMStyleWithColumns(20));
+  verifyFormat("#define MACRO(a) \\\n"
+               "  if (a)         \\\n"
+               "    f();         \\\n"
+               "  else           \\\n"
+               "    g()",
+               getLLVMStyleWithColumns(18));
   verifyFormat("#define A template <typename T>");
   verifyIncompleteFormat("#define STR(x) #x\n"
                          "f(STR(this_is_a_string_literal{));");