[clang] [clang-format] Handle AttributeMacros in parseRecord() (PR #94189)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Jun 3 00:43:16 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang-format
Author: Owen Pan (owenca)
<details>
<summary>Changes</summary>
Fixes #<!-- -->94184.
---
Full diff: https://github.com/llvm/llvm-project/pull/94189.diff
2 Files Affected:
- (modified) clang/lib/Format/UnwrappedLineParser.cpp (+3-1)
- (modified) clang/unittests/Format/TokenAnnotatorTest.cpp (+8)
``````````diff
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp
index 053fd3d4df559..d6061c2666c2a 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -3993,8 +3993,10 @@ void UnwrappedLineParser::parseRecord(bool ParseAsExpr) {
case tok::coloncolon:
break;
default:
- if (!ClassName && Previous->is(tok::identifier))
+ if (!ClassName && Previous->is(tok::identifier) &&
+ Previous->isNot(TT_AttributeMacro)) {
ClassName = Previous;
+ }
}
}
diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp b/clang/unittests/Format/TokenAnnotatorTest.cpp
index a3b2569d80633..3d609a1f041bc 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -493,6 +493,14 @@ TEST_F(TokenAnnotatorTest, UnderstandsStructs) {
Tokens = annotate("template <typename T, enum E e> struct S {};");
ASSERT_EQ(Tokens.size(), 15u) << Tokens;
EXPECT_TOKEN(Tokens[11], tok::l_brace, TT_StructLBrace);
+
+ auto Style = getLLVMStyle();
+ Style.AttributeMacros.push_back("EXPORT");
+ Tokens = annotate("struct EXPORT StructName {};", Style);
+ ASSERT_EQ(Tokens.size(), 7u) << Tokens;
+ EXPECT_TOKEN(Tokens[1], tok::identifier, TT_AttributeMacro);
+ EXPECT_TOKEN(Tokens[3], tok::l_brace, TT_StructLBrace);
+ EXPECT_TOKEN(Tokens[4], tok::r_brace, TT_StructRBrace);
}
TEST_F(TokenAnnotatorTest, UnderstandsUnions) {
``````````
</details>
https://github.com/llvm/llvm-project/pull/94189
More information about the cfe-commits
mailing list