[clang] [clang-format] Fix annotation of braces enclosing stringification (PR #102998)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Aug 12 20:59:14 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang-format
Author: Owen Pan (owenca)
<details>
<summary>Changes</summary>
Fixes #<!-- -->102937.
---
Full diff: https://github.com/llvm/llvm-project/pull/102998.diff
2 Files Affected:
- (modified) clang/lib/Format/UnwrappedLineParser.cpp (+3)
- (modified) clang/unittests/Format/TokenAnnotatorTest.cpp (+11)
``````````diff
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp
index cafbba0a0d0c5b..5f1a88d4bcd729 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -507,6 +507,9 @@ void UnwrappedLineParser::calculateBraceTypes(bool ExpectClassBody) {
if (!Line->InMacroBody && !Style.isTableGen()) {
// Skip PPDirective lines and comments.
while (NextTok->is(tok::hash)) {
+ NextTok = Tokens->getNextToken();
+ if (NextTok->is(tok::pp_not_keyword))
+ break;
do {
NextTok = Tokens->getNextToken();
} while (NextTok->NewlinesBefore == 0 && NextTok->isNot(tok::eof));
diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp b/clang/unittests/Format/TokenAnnotatorTest.cpp
index cbbe550a79ebc2..256bbd49c424fa 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -3216,6 +3216,17 @@ TEST_F(TokenAnnotatorTest, BraceKind) {
EXPECT_BRACE_KIND(Tokens[17], BK_Block);
EXPECT_BRACE_KIND(Tokens[22], BK_Block);
EXPECT_BRACE_KIND(Tokens[26], BK_Block);
+
+ Tokens = annotate("{\n"
+ "#define M(x) \\\n"
+ " return {#x};\n"
+ "}");
+ ASSERT_EQ(Tokens.size(), 15u) << Tokens;
+ EXPECT_TOKEN(Tokens[0], tok::l_brace, TT_BlockLBrace);
+ EXPECT_BRACE_KIND(Tokens[0], BK_Block);
+ EXPECT_BRACE_KIND(Tokens[8], BK_BracedInit);
+ EXPECT_BRACE_KIND(Tokens[11], BK_BracedInit);
+ EXPECT_BRACE_KIND(Tokens[13], BK_Block);
}
TEST_F(TokenAnnotatorTest, UnderstandsElaboratedTypeSpecifier) {
``````````
</details>
https://github.com/llvm/llvm-project/pull/102998
More information about the cfe-commits
mailing list