Skip to content

[clang-format] Treat uppercase identifiers after struct as macros #124397

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion clang/lib/Format/UnwrappedLineParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4075,7 +4075,8 @@ void UnwrappedLineParser::parseRecord(bool ParseAsExpr) {
break;
default:
if (!JSPastExtendsOrImplements && !ClassName &&
Previous->is(tok::identifier) && Previous->isNot(TT_AttributeMacro)) {
Previous->is(tok::identifier) && Previous->isNot(TT_AttributeMacro) &&
Previous->TokenText != Previous->TokenText.upper()) {
ClassName = Previous;
}
}
Expand Down
9 changes: 8 additions & 1 deletion clang/unittests/Format/TokenAnnotatorTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -560,9 +560,16 @@ TEST_F(TokenAnnotatorTest, UnderstandsStructs) {
ASSERT_EQ(Tokens.size(), 15u) << Tokens;
EXPECT_TOKEN(Tokens[11], tok::l_brace, TT_StructLBrace);

constexpr StringRef Code{"struct EXPORT StructName {};"};

Tokens = annotate(Code);
ASSERT_EQ(Tokens.size(), 7u) << Tokens;
EXPECT_TOKEN(Tokens[3], tok::l_brace, TT_StructLBrace);
EXPECT_TOKEN(Tokens[4], tok::r_brace, TT_StructRBrace);

auto Style = getLLVMStyle();
Style.AttributeMacros.push_back("EXPORT");
Tokens = annotate("struct EXPORT StructName {};", Style);
Tokens = annotate(Code, Style);
ASSERT_EQ(Tokens.size(), 7u) << Tokens;
EXPECT_TOKEN(Tokens[1], tok::identifier, TT_AttributeMacro);
EXPECT_TOKEN(Tokens[3], tok::l_brace, TT_StructLBrace);
Expand Down
Loading