From d053c5b43a91c9a6bbc32722c8196d131228d9fc Mon Sep 17 00:00:00 2001 From: Manuel Klimek Date: Wed, 23 Jan 2013 14:37:36 +0000 Subject: [PATCH] Fix handling of macro definitions. Now correctly formats: #define A (1) llvm-svn: 173264 --- clang/lib/Format/UnwrappedLineParser.cpp | 3 ++- clang/unittests/Format/FormatTest.cpp | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp index 1b39442610f4..ad641a29b142 100644 --- a/clang/lib/Format/UnwrappedLineParser.cpp +++ b/clang/lib/Format/UnwrappedLineParser.cpp @@ -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(); diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 806a7eb9c08a..708b7d8086a3 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -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}}")); }