[clang] eee536d - [clang-format] Don't format qualifiers in PPDirective
via cfe-commits
cfe-commits at lists.llvm.org
Mon Mar 28 14:28:34 PDT 2022
Author: owenca
Date: 2022-03-28T14:28:14-07:00
New Revision: eee536dd31859058dba8a0d17d3b5f61d530d3bc
URL: https://github.com/llvm/llvm-project/commit/eee536dd31859058dba8a0d17d3b5f61d530d3bc
DIFF: https://github.com/llvm/llvm-project/commit/eee536dd31859058dba8a0d17d3b5f61d530d3bc.diff
LOG: [clang-format] Don't format qualifiers in PPDirective
Fixes #54513
Differential Revision: https://reviews.llvm.org/D122548
Added:
Modified:
clang/lib/Format/QualifierAlignmentFixer.cpp
clang/unittests/Format/QualifierFixerTest.cpp
Removed:
################################################################################
diff --git a/clang/lib/Format/QualifierAlignmentFixer.cpp b/clang/lib/Format/QualifierAlignmentFixer.cpp
index 74802026690ef..fc37f18c790a4 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 167a30ec09d3f..cd796f48cb568 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);
}
More information about the cfe-commits
mailing list