Skip to content

Commit 9452ee4

Browse files
authored
[clang-format] Treat uppercase identifiers after struct as macros (#124397)
This restores the behavior before llvmorg-20-init. Fixes #94184. Fixes #117477. Fixes #122690. Fixes #123142.
1 parent 6805d7e commit 9452ee4

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

clang/lib/Format/UnwrappedLineParser.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4075,7 +4075,8 @@ void UnwrappedLineParser::parseRecord(bool ParseAsExpr) {
40754075
break;
40764076
default:
40774077
if (!JSPastExtendsOrImplements && !ClassName &&
4078-
Previous->is(tok::identifier) && Previous->isNot(TT_AttributeMacro)) {
4078+
Previous->is(tok::identifier) && Previous->isNot(TT_AttributeMacro) &&
4079+
Previous->TokenText != Previous->TokenText.upper()) {
40794080
ClassName = Previous;
40804081
}
40814082
}

clang/unittests/Format/TokenAnnotatorTest.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -560,9 +560,16 @@ TEST_F(TokenAnnotatorTest, UnderstandsStructs) {
560560
ASSERT_EQ(Tokens.size(), 15u) << Tokens;
561561
EXPECT_TOKEN(Tokens[11], tok::l_brace, TT_StructLBrace);
562562

563+
constexpr StringRef Code{"struct EXPORT StructName {};"};
564+
565+
Tokens = annotate(Code);
566+
ASSERT_EQ(Tokens.size(), 7u) << Tokens;
567+
EXPECT_TOKEN(Tokens[3], tok::l_brace, TT_StructLBrace);
568+
EXPECT_TOKEN(Tokens[4], tok::r_brace, TT_StructRBrace);
569+
563570
auto Style = getLLVMStyle();
564571
Style.AttributeMacros.push_back("EXPORT");
565-
Tokens = annotate("struct EXPORT StructName {};", Style);
572+
Tokens = annotate(Code, Style);
566573
ASSERT_EQ(Tokens.size(), 7u) << Tokens;
567574
EXPECT_TOKEN(Tokens[1], tok::identifier, TT_AttributeMacro);
568575
EXPECT_TOKEN(Tokens[3], tok::l_brace, TT_StructLBrace);

0 commit comments

Comments
 (0)