From eee536dd31859058dba8a0d17d3b5f61d530d3bc Mon Sep 17 00:00:00 2001 From: owenca Date: Sun, 27 Mar 2022 13:19:02 -0700 Subject: [PATCH] [clang-format] Don't format qualifiers in PPDirective Fixes #54513 Differential Revision: https://reviews.llvm.org/D122548 --- clang/lib/Format/QualifierAlignmentFixer.cpp | 2 ++ clang/unittests/Format/QualifierFixerTest.cpp | 1 + 2 files changed, 3 insertions(+) diff --git a/clang/lib/Format/QualifierAlignmentFixer.cpp b/clang/lib/Format/QualifierAlignmentFixer.cpp index 74802026690e..fc37f18c790a 100644 --- a/clang/lib/Format/QualifierAlignmentFixer.cpp +++ b/clang/lib/Format/QualifierAlignmentFixer.cpp @@ -407,6 +407,8 @@ LeftRightQualifierAlignmentFixer::analyze( assert(QualifierToken != tok::identifier && "Unrecognised Qualifier"); for (AnnotatedLine *Line : AnnotatedLines) { + if (Line->InPPDirective) + continue; FormatToken *First = Line->First; assert(First); if (First->Finalized) diff --git a/clang/unittests/Format/QualifierFixerTest.cpp b/clang/unittests/Format/QualifierFixerTest.cpp index 167a30ec09d3..cd796f48cb56 100755 --- a/clang/unittests/Format/QualifierFixerTest.cpp +++ b/clang/unittests/Format/QualifierFixerTest.cpp @@ -815,6 +815,7 @@ TEST_F(QualifierFixerTest, NoOpQualifierReplacements) { ReplacementCount = 0; EXPECT_EQ(ReplacementCount, 0); verifyFormat("static const uint32 foo[] = {0, 31};", Style); + verifyFormat("#define MACRO static const", Style); EXPECT_EQ(ReplacementCount, 0); }