]> granicus.if.org Git - clang/commitdiff
[clang-format] Fix incorrect formatting of keyword macro definition
authorOwen Pan <owenpiano@gmail.com>
Thu, 18 Apr 2019 20:17:08 +0000 (20:17 +0000)
committerOwen Pan <owenpiano@gmail.com>
Thu, 18 Apr 2019 20:17:08 +0000 (20:17 +0000)
See PR39719

Differential Revision: https://reviews.llvm.org/D60853

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

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

index 3760eb019591be7ddc2ec8d8f74f59c8124b7540..64890d5333c81155603a018d8ecb2b89a0c09ac2 100644 (file)
@@ -805,7 +805,7 @@ void UnwrappedLineParser::parsePPEndIf() {
 void UnwrappedLineParser::parsePPDefine() {
   nextToken();
 
-  if (FormatTok->Tok.getKind() != tok::identifier) {
+  if (!FormatTok->Tok.getIdentifierInfo()) {
     IncludeGuard = IG_Rejected;
     IncludeGuardToken = nullptr;
     parsePPUnknown();
index 2ac0078dac977baf670d6a2a7a0508e308da691d..be8566c754503ed4677bb08ec973754d67d43703 100644 (file)
@@ -2468,6 +2468,12 @@ TEST_F(FormatTest, HashInMacroDefinition) {
 TEST_F(FormatTest, RespectWhitespaceInMacroDefinitions) {
   EXPECT_EQ("#define A (x)", format("#define A (x)"));
   EXPECT_EQ("#define A(x)", format("#define A(x)"));
+
+  FormatStyle Style = getLLVMStyle();
+  Style.SpaceBeforeParens = FormatStyle::SBPO_Never;
+  verifyFormat("#define true ((foo)1)", Style);
+  Style.SpaceBeforeParens = FormatStyle::SBPO_Always;
+  verifyFormat("#define false((foo)0)", Style);
 }
 
 TEST_F(FormatTest, EmptyLinesInMacroDefinitions) {