From a8be2fd148a0a94af1bc8d4f833b00814106aa4f Mon Sep 17 00:00:00 2001 From: Owen Pan Date: Thu, 18 Apr 2019 20:17:08 +0000 Subject: [PATCH] [clang-format] Fix incorrect formatting of keyword macro definition 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 | 2 +- unittests/Format/FormatTest.cpp | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/Format/UnwrappedLineParser.cpp b/lib/Format/UnwrappedLineParser.cpp index 3760eb0195..64890d5333 100644 --- a/lib/Format/UnwrappedLineParser.cpp +++ b/lib/Format/UnwrappedLineParser.cpp @@ -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(); diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 2ac0078dac..be8566c754 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -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) { -- 2.40.0