From a127512cb4bbfb187ccdb3ba296501efb997f440 Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Wed, 20 Mar 2013 10:23:53 +0000 Subject: [PATCH] Don't remove all indentation when in #defines. Otherwise, this can become hard to read. Before: #define A \ case 1: After: #define A \ case 1: llvm-svn: 177509 --- clang/lib/Format/UnwrappedLineParser.cpp | 2 +- clang/unittests/Format/FormatTest.cpp | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp index a438a53..b43cc07 100644 --- a/clang/lib/Format/UnwrappedLineParser.cpp +++ b/clang/lib/Format/UnwrappedLineParser.cpp @@ -574,7 +574,7 @@ void UnwrappedLineParser::parseLabel() { return; nextToken(); unsigned OldLineLevel = Line->Level; - if (Line->Level > 0) + if (Line->Level > 1 || (!Line->InPPDirective && Line->Level > 0)) --Line->Level; if (CommentsBeforeNextToken.empty() && FormatTok.Tok.is(tok::l_brace)) { parseBlock(/*MustBeDeclaration=*/ false); diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 18ba143..3253347 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -441,6 +441,11 @@ TEST_F(FormatTest, FormatsSwitchStatement) { " }\n" " break;\n" "}"); + verifyFormat("#define A \\\n" + " switch (x) { \\\n" + " case a: \\\n" + " foo = b; \\\n" + " }", getLLVMStyleWithColumns(20)); verifyGoogleFormat("switch (x) {\n" " case 1:\n" @@ -1209,7 +1214,7 @@ TEST_F(FormatTest, MacroDefinitionsWithIncompleteCode) { // FIXME: Improve formatting of case labels in macros. verifyFormat("#define SOMECASES \\\n" - "case 1: \\\n" + " case 1: \\\n" " case 2\n", getLLVMStyleWithColumns(20)); -- 2.7.4