r177509 - Don't remove all indentation when in #defines.
Daniel Jasper
djasper at google.com
Wed Mar 20 03:23:54 PDT 2013
Author: djasper
Date: Wed Mar 20 05:23:53 2013
New Revision: 177509
URL: http://llvm.org/viewvc/llvm-project?rev=177509&view=rev
Log:
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:
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=177509&r1=177508&r2=177509&view=diff
==============================================================================
--- cfe/trunk/lib/Format/UnwrappedLineParser.cpp (original)
+++ cfe/trunk/lib/Format/UnwrappedLineParser.cpp Wed Mar 20 05:23:53 2013
@@ -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);
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=177509&r1=177508&r2=177509&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Wed Mar 20 05:23:53 2013
@@ -441,6 +441,11 @@ TEST_F(FormatTest, FormatsSwitchStatemen
" }\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, MacroDefinitionsWithI
// FIXME: Improve formatting of case labels in macros.
verifyFormat("#define SOMECASES \\\n"
- "case 1: \\\n"
+ " case 1: \\\n"
" case 2\n",
getLLVMStyleWithColumns(20));
More information about the cfe-commits
mailing list