Skip to content

Commit 13f6797

Browse files
authored
[clang-format] Handle AttributeMacros in parseRecord() (#94189)
Fixes #94184.
1 parent 572b4e7 commit 13f6797

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

clang/lib/Format/UnwrappedLineParser.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3993,8 +3993,10 @@ void UnwrappedLineParser::parseRecord(bool ParseAsExpr) {
39933993
case tok::coloncolon:
39943994
break;
39953995
default:
3996-
if (!ClassName && Previous->is(tok::identifier))
3996+
if (!ClassName && Previous->is(tok::identifier) &&
3997+
Previous->isNot(TT_AttributeMacro)) {
39973998
ClassName = Previous;
3999+
}
39984000
}
39994001
}
40004002

clang/unittests/Format/TokenAnnotatorTest.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,14 @@ TEST_F(TokenAnnotatorTest, UnderstandsStructs) {
493493
Tokens = annotate("template <typename T, enum E e> struct S {};");
494494
ASSERT_EQ(Tokens.size(), 15u) << Tokens;
495495
EXPECT_TOKEN(Tokens[11], tok::l_brace, TT_StructLBrace);
496+
497+
auto Style = getLLVMStyle();
498+
Style.AttributeMacros.push_back("EXPORT");
499+
Tokens = annotate("struct EXPORT StructName {};", Style);
500+
ASSERT_EQ(Tokens.size(), 7u) << Tokens;
501+
EXPECT_TOKEN(Tokens[1], tok::identifier, TT_AttributeMacro);
502+
EXPECT_TOKEN(Tokens[3], tok::l_brace, TT_StructLBrace);
503+
EXPECT_TOKEN(Tokens[4], tok::r_brace, TT_StructRBrace);
496504
}
497505

498506
TEST_F(TokenAnnotatorTest, UnderstandsUnions) {

0 commit comments

Comments
 (0)