Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Merge remote-tracking branch 'upstream/main' into parser-h-reorganiza…
…tion
  • Loading branch information
Endilll committed May 12, 2025
commit 56321ad0e649c56e1b4d46cf89d8d4f0b62a9aa1
16 changes: 15 additions & 1 deletion clang/include/clang/Parse/Parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -2274,7 +2274,8 @@ class Parser : public CodeCompletionHandler {
return false;
}

void MaybeParseMicrosoftAttributes(ParsedAttributes &Attrs) {
bool MaybeParseMicrosoftAttributes(ParsedAttributes &Attrs) {
bool AttrsParsed = false;
if ((getLangOpts().MicrosoftExt || getLangOpts().HLSL) &&
Tok.is(tok::l_square)) {
ParsedAttributes AttrsWithRange(AttrFactory);
Expand Down Expand Up @@ -3585,6 +3586,19 @@ class Parser : public CodeCompletionHandler {
/// \endverbatim
AccessSpecifier getAccessSpecifierIfPresent() const;

bool isCXX2CTriviallyRelocatableKeyword(Token Tok) const;
bool isCXX2CTriviallyRelocatableKeyword() const;
void ParseCXX2CTriviallyRelocatableSpecifier(SourceLocation &TRS);

bool isCXX2CReplaceableKeyword(Token Tok) const;
bool isCXX2CReplaceableKeyword() const;
void ParseCXX2CReplaceableSpecifier(SourceLocation &MRS);

/// 'final', a C++26 'trivially_relocatable_if_eligible',
/// 'replaceable_if_eligible', or Microsoft 'sealed' or 'abstract' contextual
/// keyword.
bool isClassCompatibleKeyword(Token Tok) const;

///@}

//
Expand Down
64 changes: 62 additions & 2 deletions clang/lib/Parse/ParseDeclCXX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2488,14 +2488,74 @@ bool Parser::isCXX11FinalKeyword() const {
Specifier == VirtSpecifiers::VS_Sealed;
}

bool Parser::isClassCompatibleKeyword() const {
VirtSpecifiers::Specifier Specifier = isCXX11VirtSpecifier();
bool Parser::isCXX2CTriviallyRelocatableKeyword(Token Tok) const {
if (!getLangOpts().CPlusPlus || Tok.isNot(tok::identifier))
return false;
if (!Ident_trivially_relocatable_if_eligible)
Ident_trivially_relocatable_if_eligible =
&PP.getIdentifierTable().get("trivially_relocatable_if_eligible");
IdentifierInfo *II = Tok.getIdentifierInfo();
return II == Ident_trivially_relocatable_if_eligible;
}

bool Parser::isCXX2CTriviallyRelocatableKeyword() const {
return isCXX2CTriviallyRelocatableKeyword(Tok);
}

void Parser::ParseCXX2CTriviallyRelocatableSpecifier(SourceLocation &TRS) {
assert(isCXX2CTriviallyRelocatableKeyword() &&
"expected a trivially_relocatable specifier");

Diag(Tok.getLocation(), getLangOpts().CPlusPlus26
? diag::warn_relocatable_keyword
: diag::ext_relocatable_keyword)
<< /*relocatable*/ 0;

TRS = ConsumeToken();
}

bool Parser::isCXX2CReplaceableKeyword(Token Tok) const {
if (!getLangOpts().CPlusPlus || Tok.isNot(tok::identifier))
return false;
if (!Ident_replaceable_if_eligible)
Ident_replaceable_if_eligible =
&PP.getIdentifierTable().get("replaceable_if_eligible");
IdentifierInfo *II = Tok.getIdentifierInfo();
return II == Ident_replaceable_if_eligible;
}

bool Parser::isCXX2CReplaceableKeyword() const {
return isCXX2CReplaceableKeyword(Tok);
}

void Parser::ParseCXX2CReplaceableSpecifier(SourceLocation &MRS) {
assert(isCXX2CReplaceableKeyword() &&
"expected a replaceable_if_eligible specifier");

Diag(Tok.getLocation(), getLangOpts().CPlusPlus26
? diag::warn_relocatable_keyword
: diag::ext_relocatable_keyword)
<< /*replaceable*/ 1;

MRS = ConsumeToken();
}

bool Parser::isClassCompatibleKeyword(Token Tok) const {
if (isCXX2CTriviallyRelocatableKeyword(Tok) || isCXX2CReplaceableKeyword(Tok))
return true;
VirtSpecifiers::Specifier Specifier = isCXX11VirtSpecifier(Tok);
return Specifier == VirtSpecifiers::VS_Final ||
Specifier == VirtSpecifiers::VS_GNU_Final ||
Specifier == VirtSpecifiers::VS_Sealed ||
Specifier == VirtSpecifiers::VS_Abstract;
}

bool Parser::isClassCompatibleKeyword() const {
return isClassCompatibleKeyword(Tok);
}

/// Parse a C++ member-declarator up to, but not including, the optional
/// brace-or-equal-initializer or pure-specifier.
bool Parser::ParseCXXMemberDeclaratorBeforeInitializer(
Declarator &DeclaratorInfo, VirtSpecifiers &VS, ExprResult &BitfieldSize,
LateParsedAttrList &LateParsedAttrs) {
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.