From b9b27cd4beecd968271978d1bd5b380fcb2e8a31 Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Thu, 19 May 2016 06:30:48 +0000 Subject: [PATCH] clang-format: Fix incorrect indentation in last line of macro definition 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 | 2 ++ unittests/Format/FormatTest.cpp | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/lib/Format/UnwrappedLineParser.cpp b/lib/Format/UnwrappedLineParser.cpp index c8e4cc4a1b..e14b2b44e8 100644 --- a/lib/Format/UnwrappedLineParser.cpp +++ b/lib/Format/UnwrappedLineParser.cpp @@ -1430,6 +1430,8 @@ void UnwrappedLineParser::parseIfThenElse() { addUnwrappedLine(); ++Line->Level; parseStructuralElement(); + if (FormatTok->is(tok::eof)) + addUnwrappedLine(); --Line->Level; } } else if (NeedsUnwrappedLine) { diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index aec801ccc9..27379b7d6c 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -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 "); verifyIncompleteFormat("#define STR(x) #x\n" "f(STR(this_is_a_string_literal{));"); -- 2.40.0