]> granicus.if.org Git - clang/commitdiff
Fix handling of macro definitions.
authorManuel Klimek <klimek@google.com>
Wed, 23 Jan 2013 14:37:36 +0000 (14:37 +0000)
committerManuel Klimek <klimek@google.com>
Wed, 23 Jan 2013 14:37:36 +0000 (14:37 +0000)
Now correctly formats:
 #define A (1)

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

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

index 1b39442610f4030df5ebb801b11671159f021104..ad641a29b1427e6474da1777efb345decd8760e6 100644 (file)
@@ -240,7 +240,8 @@ void UnwrappedLineParser::parsePPDefine() {
     return;
   }
   nextToken();
-  if (FormatTok.Tok.getKind() == tok::l_paren) {
+  if (FormatTok.Tok.getKind() == tok::l_paren &&
+      FormatTok.WhiteSpaceLength == 0) {
     parseParens();
   }
   addUnwrappedLine();
index 806a7eb9c08ade0d7a06fb5fbbc2f15a64390754..708b7d8086a3934d0a51558fa60db3a87179d903 100644 (file)
@@ -742,6 +742,10 @@ TEST_F(FormatTest, HashInMacroDefinition) {
   verifyFormat("#define A void # ## #", getLLVMStyleWithColumns(22));
 }
 
+TEST_F(FormatTest, RespectWhitespaceInMacroDefinitions) {
+  verifyFormat("#define A (1)");
+}
+
 TEST_F(FormatTest, IndentPreprocessorDirectivesAtZero) {
   EXPECT_EQ("{\n  {\n#define A\n  }\n}", format("{{\n#define A\n}}"));
 }