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)

llvm-svn: 173264

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

index 1b39442..ad641a2 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 806a7eb..708b7d8 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}}"));
 }