[clang] 853fb0a - [clang-format] Don't alter SpacesRequiredBefore of finalized tokens (#69897)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Oct 23 13:12:55 PDT 2023
Author: Owen Pan
Date: 2023-10-23T13:12:51-07:00
New Revision: 853fb0a8ac053a31fef3405d1d4dd545ad9a6167
URL: https://github.com/llvm/llvm-project/commit/853fb0a8ac053a31fef3405d1d4dd545ad9a6167
DIFF: https://github.com/llvm/llvm-project/commit/853fb0a8ac053a31fef3405d1d4dd545ad9a6167.diff
LOG: [clang-format] Don't alter SpacesRequiredBefore of finalized tokens (#69897)
Fixes #69237.
Added:
Modified:
clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/FormatTest.cpp
Removed:
################################################################################
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index a457ced9f886846..4a7378c24cda57b 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -3544,7 +3544,7 @@ void TokenAnnotator::calculateFormattingInformation(AnnotatedLine &Line) const {
}
}
}
- } else if (Current->SpacesRequiredBefore == 0 &&
+ } else if (!Current->Finalized && Current->SpacesRequiredBefore == 0 &&
spaceRequiredBefore(Line, *Current)) {
Current->SpacesRequiredBefore = 1;
}
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index 0a87cfc4f1d6af9..d5711782a23ef5b 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -26459,6 +26459,25 @@ TEST_F(FormatTest, AllowBreakBeforeNoexceptSpecifier) {
Style);
}
+TEST_F(FormatTest, PPBranchesInBracedInit) {
+ verifyFormat("A a_{kFlag1,\n"
+ "#if BUILD_FLAG\n"
+ " kFlag2,\n"
+ "#else\n"
+ " kFlag3,\n"
+ "#endif\n"
+ " kFlag4};",
+ "A a_{\n"
+ " kFlag1,\n"
+ "#if BUILD_FLAG\n"
+ " kFlag2,\n"
+ "#else\n"
+ " kFlag3,\n"
+ "#endif\n"
+ " kFlag4\n"
+ "};");
+}
+
} // namespace
} // namespace test
} // namespace format
More information about the cfe-commits
mailing list