34#include "llvm/ADT/SmallSet.h"
35#include "llvm/ADT/SmallString.h"
36#include "llvm/ADT/StringSwitch.h"
53 DeclSpecContext DSC = getDeclSpecContextFromDeclaratorContext(Context);
54 if (DSC == DeclSpecContext::DSC_normal)
55 DSC = DeclSpecContext::DSC_type_specifier;
61 ParseSpecifierQualifierList(DS, AS, DSC);
69 if (AL.isDeclspecAttribute())
70 ToBeMoved.push_back(&AL);
79 ParseDeclarator(DeclaratorInfo);
91 if (Name.size() >= 4 && Name.starts_with(
"__") && Name.ends_with(
"__"))
92 return Name.drop_front(2).drop_back(2);
99#define CLANG_ATTR_LATE_PARSED_EXPERIMENTAL_EXT_LIST
101#include "clang/Parse/AttrParserStringSwitches.inc"
103#undef CLANG_ATTR_LATE_PARSED_EXPERIMENTAL_EXT_LIST
109#define CLANG_ATTR_LATE_PARSED_LIST
111#include "clang/Parse/AttrParserStringSwitches.inc"
113#undef CLANG_ATTR_LATE_PARSED_LIST
123 if (
SM.getFileID(StartLoc) !=
SM.getFileID(EndLoc))
126 bool AttrStartIsInMacro =
128 bool AttrEndIsInMacro =
130 return AttrStartIsInMacro && AttrEndIsInMacro;
133void Parser::ParseAttributes(
unsigned WhichAttrKinds,
ParsedAttributes &Attrs,
134 LateParsedAttrList *LateAttrs) {
140 if (WhichAttrKinds & PAKM_CXX11)
141 MoreToParse |= MaybeParseCXX11Attributes(Attrs);
142 if (WhichAttrKinds & PAKM_GNU)
143 MoreToParse |= MaybeParseGNUAttributes(Attrs, LateAttrs);
144 if (WhichAttrKinds & PAKM_Declspec)
145 MoreToParse |= MaybeParseMicrosoftDeclSpecs(Attrs);
146 }
while (MoreToParse);
192 assert(Tok.
is(tok::kw___attribute) &&
"Not a GNU attribute list!");
197 while (Tok.
is(tok::kw___attribute)) {
199 unsigned OldNumAttrs = Attrs.
size();
200 unsigned OldNumLateAttrs = LateAttrs ? LateAttrs->size() : 0;
202 if (ExpectAndConsume(tok::l_paren, diag::err_expected_lparen_after,
207 if (ExpectAndConsume(tok::l_paren, diag::err_expected_lparen_after,
"(")) {
220 if (Tok.
is(tok::code_completion)) {
232 if (Tok.
isNot(tok::l_paren)) {
233 Attrs.
addNew(AttrName, AttrNameLoc,
nullptr, AttrNameLoc,
nullptr, 0,
234 ParsedAttr::Form::GNU());
238 bool LateParse =
false;
241 else if (LateAttrs->lateAttrParseExperimentalExtOnly()) {
245 LateParse =
getLangOpts().ExperimentalLateParseAttributes &&
258 ParseGNUAttributeArgs(AttrName, AttrNameLoc, Attrs, &EndLoc,
nullptr,
264 LateParsedAttribute *LA =
265 new LateParsedAttribute(
this, *AttrName, AttrNameLoc);
266 LateAttrs->push_back(LA);
270 if (!ClassStack.empty() && !LateAttrs->parseSoon())
271 getCurrentClass().LateParsedDeclarations.push_back(LA);
275 LA->Toks.push_back(Tok);
278 ConsumeAndStoreUntil(tok::r_paren, LA->Toks,
true);
283 LA->Toks.push_back(Eof);
284 }
while (Tok.
is(tok::comma));
286 if (ExpectAndConsume(tok::r_paren))
289 if (ExpectAndConsume(tok::r_paren))
296 if (!
SM.isWrittenInBuiltinFile(
SM.getSpellingLoc(AttrTokLoc)) &&
299 StringRef FoundName =
303 for (
unsigned i = OldNumAttrs; i < Attrs.
size(); ++i)
304 Attrs[i].setMacroIdentifier(MacroII, ExpansionRange.
getBegin());
307 for (
unsigned i = OldNumLateAttrs; i < LateAttrs->size(); ++i)
308 (*LateAttrs)[i]->MacroII = MacroII;
321#define CLANG_ATTR_IDENTIFIER_ARG_LIST
323#include "clang/Parse/AttrParserStringSwitches.inc"
325#undef CLANG_ATTR_IDENTIFIER_ARG_LIST
333#define CLANG_ATTR_STRING_LITERAL_ARG_LIST
335#include "clang/Parse/AttrParserStringSwitches.inc"
337#undef CLANG_ATTR_STRING_LITERAL_ARG_LIST
344#define CLANG_ATTR_VARIADIC_IDENTIFIER_ARG_LIST
346#include "clang/Parse/AttrParserStringSwitches.inc"
348#undef CLANG_ATTR_VARIADIC_IDENTIFIER_ARG_LIST
355#define CLANG_ATTR_THIS_ISA_IDENTIFIER_ARG_LIST
357#include "clang/Parse/AttrParserStringSwitches.inc"
359#undef CLANG_ATTR_THIS_ISA_IDENTIFIER_ARG_LIST
366#define CLANG_ATTR_ACCEPTS_EXPR_PACK
368#include "clang/Parse/AttrParserStringSwitches.inc"
370#undef CLANG_ATTR_ACCEPTS_EXPR_PACK
377#define CLANG_ATTR_TYPE_ARG_LIST
379#include "clang/Parse/AttrParserStringSwitches.inc"
381#undef CLANG_ATTR_TYPE_ARG_LIST
388#define CLANG_ATTR_STRICT_IDENTIFIER_ARG_LIST
390#include "clang/Parse/AttrParserStringSwitches.inc"
392#undef CLANG_ATTR_STRICT_IDENTIFIER_ARG_LIST
400#define CLANG_ATTR_ARG_CONTEXT_LIST
402#include "clang/Parse/AttrParserStringSwitches.inc"
404#undef CLANG_ATTR_ARG_CONTEXT_LIST
408 assert(Tok.
is(tok::identifier) &&
"expected an identifier");
426 if (Tok.
isNot(tok::r_paren))
429 if (
Parens.consumeClose())
438 ScopeName, ScopeLoc,
T.get(), Form);
441 ScopeName, ScopeLoc,
nullptr, 0, Form);
445Parser::ParseUnevaluatedStringInAttribute(
const IdentifierInfo &AttrName) {
446 if (Tok.
is(tok::l_paren)) {
449 ExprResult Res = ParseUnevaluatedStringInAttribute(AttrName);
450 Paren.consumeClose();
453 if (!isTokenStringLiteral()) {
461bool Parser::ParseAttributeArgumentList(
464 bool SawError =
false;
469 Expr = ParseUnevaluatedStringInAttribute(AttrName);
471 Diag(Tok, diag::warn_cxx98_compat_generalized_initializer_lists);
472 Expr = ParseBraceInitializer();
478 if (Tok.
is(tok::ellipsis))
480 else if (Tok.
is(tok::code_completion)) {
491 if (
Expr.isInvalid()) {
501 Exprs.push_back(
Expr.get());
503 if (Tok.
isNot(tok::comma))
508 checkPotentialAngleBracketDelimiter(Comma);
515 for (
auto &
E : Exprs) {
524unsigned Parser::ParseAttributeArgsCommon(
533 bool AttributeIsTypeArgAttr =
535 bool AttributeHasVariadicIdentifierArg =
539 if (ChangeKWThisToIdent && Tok.
is(tok::kw_this))
543 if (Tok.
is(tok::identifier)) {
545 bool IsIdentifierArg =
546 AttributeHasVariadicIdentifierArg ||
557 IsIdentifierArg = Next.isOneOf(tok::r_paren, tok::comma);
561 ArgExprs.push_back(ParseIdentifierLoc());
565 if (!ArgExprs.empty() ? Tok.
is(tok::comma) : Tok.
isNot(tok::r_paren)) {
567 if (!ArgExprs.empty())
570 if (AttributeIsTypeArgAttr) {
578 TheParsedType =
T.get();
579 }
else if (AttributeHasVariadicIdentifierArg ||
589 if (ChangeKWThisToIdent && Tok.
is(tok::kw_this))
593 if (Tok.
is(tok::identifier)) {
594 ArgExprs.push_back(ParseIdentifierLoc());
612 ArgExprs.push_back(ArgExpr.
get());
628 ExprVector ParsedExprs;
632 if (ParseAttributeArgumentList(*AttrName, ParsedExprs, ArgProperties)) {
638 for (
size_t I = 0; I < ParsedExprs.size(); ++I) {
639 if (!isa<PackExpansionExpr>(ParsedExprs[I]))
644 diag::err_attribute_argument_parm_pack_not_supported)
651 ArgExprs.insert(ArgExprs.end(), ParsedExprs.begin(), ParsedExprs.end());
656 if (!ExpectAndConsume(tok::r_paren)) {
659 if (AttributeIsTypeArgAttr && !TheParsedType.
get().
isNull()) {
661 ScopeName, ScopeLoc, TheParsedType, Form);
664 ArgExprs.data(), ArgExprs.size(), Form);
671 return static_cast<unsigned>(ArgExprs.size() + !TheParsedType.
get().
isNull());
676void Parser::ParseGNUAttributeArgs(
681 assert(Tok.
is(tok::l_paren) &&
"Attribute arg list not starting with '('");
686 if (AttrKind == ParsedAttr::AT_Availability) {
687 ParseAvailabilityAttribute(*AttrName, AttrNameLoc, Attrs, EndLoc, ScopeName,
690 }
else if (AttrKind == ParsedAttr::AT_ExternalSourceSymbol) {
691 ParseExternalSourceSymbolAttribute(*AttrName, AttrNameLoc, Attrs, EndLoc,
692 ScopeName, ScopeLoc, Form);
694 }
else if (AttrKind == ParsedAttr::AT_ObjCBridgeRelated) {
695 ParseObjCBridgeRelatedAttribute(*AttrName, AttrNameLoc, Attrs, EndLoc,
696 ScopeName, ScopeLoc, Form);
698 }
else if (AttrKind == ParsedAttr::AT_SwiftNewType) {
699 ParseSwiftNewTypeAttribute(*AttrName, AttrNameLoc, Attrs, EndLoc, ScopeName,
702 }
else if (AttrKind == ParsedAttr::AT_TypeTagForDatatype) {
703 ParseTypeTagForDatatypeAttribute(*AttrName, AttrNameLoc, Attrs, EndLoc,
704 ScopeName, ScopeLoc, Form);
707 ParseAttributeWithTypeArg(*AttrName, AttrNameLoc, Attrs, ScopeName,
710 }
else if (AttrKind == ParsedAttr::AT_CountedBy ||
711 AttrKind == ParsedAttr::AT_CountedByOrNull ||
712 AttrKind == ParsedAttr::AT_SizedBy ||
713 AttrKind == ParsedAttr::AT_SizedByOrNull) {
714 ParseBoundsAttribute(*AttrName, AttrNameLoc, Attrs, ScopeName, ScopeLoc,
717 }
else if (AttrKind == ParsedAttr::AT_CXXAssume) {
718 ParseCXXAssumeAttributeArg(Attrs, AttrName, AttrNameLoc, EndLoc, Form);
724 std::optional<ParseScope> PrototypeScope;
726 D &&
D->isFunctionDeclarator()) {
731 for (
unsigned i = 0; i != FTI.
NumParams; ++i) {
737 ParseAttributeArgsCommon(AttrName, AttrNameLoc, Attrs, EndLoc, ScopeName,
741unsigned Parser::ParseClangAttributeArgs(
745 assert(Tok.
is(tok::l_paren) &&
"Attribute arg list not starting with '('");
752 return ParseAttributeArgsCommon(AttrName, AttrNameLoc, Attrs, EndLoc,
753 ScopeName, ScopeLoc, Form);
754 case ParsedAttr::AT_ExternalSourceSymbol:
755 ParseExternalSourceSymbolAttribute(*AttrName, AttrNameLoc, Attrs, EndLoc,
756 ScopeName, ScopeLoc, Form);
758 case ParsedAttr::AT_Availability:
759 ParseAvailabilityAttribute(*AttrName, AttrNameLoc, Attrs, EndLoc, ScopeName,
762 case ParsedAttr::AT_ObjCBridgeRelated:
763 ParseObjCBridgeRelatedAttribute(*AttrName, AttrNameLoc, Attrs, EndLoc,
764 ScopeName, ScopeLoc, Form);
766 case ParsedAttr::AT_SwiftNewType:
767 ParseSwiftNewTypeAttribute(*AttrName, AttrNameLoc, Attrs, EndLoc, ScopeName,
770 case ParsedAttr::AT_TypeTagForDatatype:
771 ParseTypeTagForDatatypeAttribute(*AttrName, AttrNameLoc, Attrs, EndLoc,
772 ScopeName, ScopeLoc, Form);
775 case ParsedAttr::AT_CXXAssume:
776 ParseCXXAssumeAttributeArg(Attrs, AttrName, AttrNameLoc, EndLoc, Form);
779 return !Attrs.
empty() ? Attrs.
begin()->getNumArgs() : 0;
785 unsigned ExistingAttrs = Attrs.
size();
799 if (AttrName->
getName() ==
"property") {
805 T.expectAndConsume(diag::err_expected_lparen_after,
814 bool HasInvalidAccessor =
false;
819 if (!Tok.
is(tok::identifier)) {
821 if (Tok.
is(tok::r_paren) && !HasInvalidAccessor &&
822 AccessorNames[AK_Put] ==
nullptr &&
823 AccessorNames[AK_Get] ==
nullptr) {
824 Diag(AttrNameLoc, diag::err_ms_property_no_getter_or_putter);
835 if (KindStr ==
"get") {
837 }
else if (KindStr ==
"put") {
841 }
else if (KindStr ==
"set") {
842 Diag(KindLoc, diag::err_ms_property_has_set_accessor)
849 Diag(KindLoc, diag::err_ms_property_missing_accessor_kind);
851 HasInvalidAccessor =
true;
852 goto next_property_accessor;
856 Diag(KindLoc, diag::err_ms_property_unknown_accessor);
857 HasInvalidAccessor =
true;
876 if (!Tok.
is(tok::identifier)) {
881 if (Kind == AK_Invalid) {
883 }
else if (AccessorNames[Kind] !=
nullptr) {
885 Diag(KindLoc, diag::err_ms_property_duplicate_accessor) << KindStr;
891 next_property_accessor:
897 if (Tok.
is(tok::r_paren))
900 Diag(Tok.
getLocation(), diag::err_ms_property_expected_comma_or_rparen);
905 if (!HasInvalidAccessor)
907 AccessorNames[AK_Get], AccessorNames[AK_Put],
908 ParsedAttr::Form::Declspec());
910 return !HasInvalidAccessor;
914 ParseAttributeArgsCommon(AttrName, AttrNameLoc, Attrs,
nullptr,
nullptr,
920 Diag(OpenParenLoc, diag::err_attribute_requires_arguments) << AttrName;
933 assert(
getLangOpts().DeclSpecKeyword &&
"__declspec keyword is not enabled");
934 assert(Tok.
is(tok::kw___declspec) &&
"Not a declspec!");
939 while (Tok.
is(tok::kw___declspec)) {
942 if (
T.expectAndConsume(diag::err_expected_lparen_after,
"__declspec",
948 while (Tok.
isNot(tok::r_paren)) {
953 if (Tok.
is(tok::code_completion)) {
962 bool IsString = Tok.
getKind() == tok::string_literal;
963 if (!IsString && Tok.
getKind() != tok::identifier &&
964 Tok.
getKind() != tok::kw_restrict) {
965 Diag(Tok, diag::err_ms_declspec_type);
975 StringRef Str = PP.
getSpelling(Tok, StrBuffer, &Invalid);
981 AttrNameLoc = ConsumeStringToken();
987 bool AttrHandled =
false;
990 if (Tok.
is(tok::l_paren))
991 AttrHandled = ParseMicrosoftDeclSpecArgs(AttrName, AttrNameLoc, Attrs);
992 else if (AttrName->
getName() ==
"property")
998 Attrs.
addNew(AttrName, AttrNameLoc,
nullptr, AttrNameLoc,
nullptr, 0,
999 ParsedAttr::Form::Declspec());
1002 EndLoc =
T.getCloseLocation();
1013 case tok::kw___fastcall:
1014 case tok::kw___stdcall:
1015 case tok::kw___thiscall:
1016 case tok::kw___regcall:
1017 case tok::kw___cdecl:
1018 case tok::kw___vectorcall:
1019 case tok::kw___ptr64:
1021 case tok::kw___ptr32:
1022 case tok::kw___sptr:
1023 case tok::kw___uptr: {
1026 attrs.
addNew(AttrName, AttrNameLoc,
nullptr, AttrNameLoc,
nullptr, 0,
1036void Parser::ParseWebAssemblyFuncrefTypeAttribute(
ParsedAttributes &attrs) {
1037 assert(Tok.
is(tok::kw___funcref));
1041 Diag(StartLoc, diag::err_wasm_funcref_not_wasm);
1047 attrs.
addNew(AttrName, AttrNameLoc,
nullptr,
1052void Parser::DiagnoseAndSkipExtendedMicrosoftTypeAttributes() {
1058 Diag(StartLoc, diag::warn_microsoft_qualifiers_ignored) <<
Range;
1068 case tok::kw_volatile:
1069 case tok::kw___fastcall:
1070 case tok::kw___stdcall:
1071 case tok::kw___thiscall:
1072 case tok::kw___cdecl:
1073 case tok::kw___vectorcall:
1074 case tok::kw___ptr32:
1075 case tok::kw___ptr64:
1077 case tok::kw___unaligned:
1078 case tok::kw___sptr:
1079 case tok::kw___uptr:
1090 while (Tok.
is(tok::kw___pascal)) {
1093 attrs.
addNew(AttrName, AttrNameLoc,
nullptr, AttrNameLoc,
nullptr, 0,
1100 while (Tok.
is(tok::kw___kernel)) {
1103 attrs.
addNew(AttrName, AttrNameLoc,
nullptr, AttrNameLoc,
nullptr, 0,
1109 while (Tok.
is(tok::kw___noinline__)) {
1112 attrs.
addNew(AttrName, AttrNameLoc,
nullptr, AttrNameLoc,
nullptr, 0,
1113 tok::kw___noinline__);
1120 Attrs.
addNew(AttrName, AttrNameLoc,
nullptr, AttrNameLoc,
nullptr, 0,
1124bool Parser::isHLSLQualifier(
const Token &Tok)
const {
1125 return Tok.
is(tok::kw_groupshared);
1132 Attrs.
addNew(AttrName, AttrNameLoc,
nullptr, AttrNameLoc,
nullptr, 0, Kind);
1140 case tok::kw__Nonnull:
1141 case tok::kw__Nullable:
1142 case tok::kw__Nullable_result:
1143 case tok::kw__Null_unspecified: {
1147 Diag(AttrNameLoc, diag::ext_nullability)
1149 attrs.
addNew(AttrName, AttrNameLoc,
nullptr, AttrNameLoc,
nullptr, 0,
1160 return (Separator ==
'.' || Separator ==
'_');
1174 if (!Tok.
is(tok::numeric_constant)) {
1175 Diag(Tok, diag::err_expected_version);
1178 return VersionTuple();
1187 const char *ThisTokBegin = &Buffer[0];
1191 unsigned ActualLength = PP.
getSpelling(Tok, ThisTokBegin, &Invalid);
1193 return VersionTuple();
1196 unsigned AfterMajor = 0;
1198 while (AfterMajor < ActualLength &&
isDigit(ThisTokBegin[AfterMajor])) {
1199 Major = Major * 10 + ThisTokBegin[AfterMajor] -
'0';
1203 if (AfterMajor == 0) {
1204 Diag(Tok, diag::err_expected_version);
1207 return VersionTuple();
1210 if (AfterMajor == ActualLength) {
1215 Diag(Tok, diag::err_zero_version);
1216 return VersionTuple();
1219 return VersionTuple(Major);
1222 const char AfterMajorSeparator = ThisTokBegin[AfterMajor];
1224 || (AfterMajor + 1 == ActualLength)) {
1225 Diag(Tok, diag::err_expected_version);
1228 return VersionTuple();
1232 unsigned AfterMinor = AfterMajor + 1;
1234 while (AfterMinor < ActualLength &&
isDigit(ThisTokBegin[AfterMinor])) {
1235 Minor = Minor * 10 + ThisTokBegin[AfterMinor] -
'0';
1239 if (AfterMinor == ActualLength) {
1243 if (Major == 0 && Minor == 0) {
1244 Diag(Tok, diag::err_zero_version);
1245 return VersionTuple();
1248 return VersionTuple(Major, Minor);
1251 const char AfterMinorSeparator = ThisTokBegin[AfterMinor];
1254 Diag(Tok, diag::err_expected_version);
1257 return VersionTuple();
1261 if (AfterMajorSeparator != AfterMinorSeparator)
1262 Diag(Tok, diag::warn_expected_consistent_version_separator);
1265 unsigned AfterSubminor = AfterMinor + 1;
1266 unsigned Subminor = 0;
1267 while (AfterSubminor < ActualLength &&
isDigit(ThisTokBegin[AfterSubminor])) {
1268 Subminor = Subminor * 10 + ThisTokBegin[AfterSubminor] -
'0';
1272 if (AfterSubminor != ActualLength) {
1273 Diag(Tok, diag::err_expected_version);
1276 return VersionTuple();
1279 return VersionTuple(Major, Minor, Subminor);
1307void Parser::ParseAvailabilityAttribute(
1311 enum { Introduced, Deprecated, Obsoleted,
Unknown };
1318 if (
T.consumeOpen()) {
1319 Diag(Tok, diag::err_expected) << tok::l_paren;
1324 if (Tok.
isNot(tok::identifier)) {
1325 Diag(Tok, diag::err_availability_expected_platform);
1332 if (Ident->getName().contains(
"xrOS") || Ident->getName().contains(
"xros"))
1333 Diag(Platform->
Loc, diag::warn_availability_unknown_platform) << Ident;
1335 else if (Ident->getName() ==
"macosx")
1339 else if (Ident->getName() ==
"macosx_app_extension")
1343 AvailabilityAttr::canonicalizePlatformName(Ident->getName()));
1347 if (ExpectAndConsume(tok::comma)) {
1354 if (!Ident_introduced) {
1369 if (Tok.
isNot(tok::identifier)) {
1370 Diag(Tok, diag::err_availability_expected_change);
1377 if (Keyword == Ident_strict) {
1379 Diag(KeywordLoc, diag::err_availability_redundant)
1382 StrictLoc = KeywordLoc;
1386 if (Keyword == Ident_unavailable) {
1387 if (UnavailableLoc.
isValid()) {
1388 Diag(KeywordLoc, diag::err_availability_redundant)
1391 UnavailableLoc = KeywordLoc;
1395 if (Keyword == Ident_deprecated && Platform->
Ident &&
1398 if (Changes[Deprecated].KeywordLoc.
isValid()) {
1399 Diag(KeywordLoc, diag::err_availability_redundant)
1406 Changes[Deprecated].
Version = VersionTuple(1);
1410 if (Keyword == Ident_environment) {
1411 if (EnvironmentLoc !=
nullptr) {
1412 Diag(KeywordLoc, diag::err_availability_redundant)
1417 if (Tok.
isNot(tok::equal)) {
1418 Diag(Tok, diag::err_expected_after) << Keyword << tok::equal;
1423 if (Keyword == Ident_message || Keyword == Ident_replacement) {
1424 if (!isTokenStringLiteral()) {
1425 Diag(Tok, diag::err_expected_string_literal)
1430 if (Keyword == Ident_message) {
1438 if (Keyword == Ident_environment) {
1439 if (Tok.
isNot(tok::identifier)) {
1440 Diag(Tok, diag::err_availability_expected_environment);
1444 EnvironmentLoc = ParseIdentifierLoc();
1450 if ((Keyword == Ident_introduced || Keyword == Ident_deprecated) &&
1451 Tok.
is(tok::identifier)) {
1455 if (Keyword == Ident_introduced)
1456 UnavailableLoc = KeywordLoc;
1462 VersionTuple Version = ParseVersionTuple(VersionRange);
1464 if (Version.empty()) {
1470 if (Keyword == Ident_introduced)
1472 else if (Keyword == Ident_deprecated)
1474 else if (Keyword == Ident_obsoleted)
1480 if (!Changes[Index].KeywordLoc.
isInvalid()) {
1481 Diag(KeywordLoc, diag::err_availability_redundant)
1484 Changes[Index].VersionRange.
getEnd());
1488 Changes[Index].
Version = Version;
1491 Diag(KeywordLoc, diag::err_availability_unknown_change)
1492 << Keyword << VersionRange;
1498 if (
T.consumeClose())
1502 *endLoc =
T.getCloseLocation();
1506 if (UnavailableLoc.
isValid()) {
1507 bool Complained =
false;
1508 for (
unsigned Index = Introduced; Index !=
Unknown; ++Index) {
1509 if (Changes[Index].KeywordLoc.
isValid()) {
1511 Diag(UnavailableLoc, diag::warn_availability_and_unavailable)
1513 Changes[Index].VersionRange.
getEnd());
1524 attrs.
addNew(&Availability,
1525 SourceRange(AvailabilityLoc,
T.getCloseLocation()), ScopeName,
1526 ScopeLoc, Platform, Changes[Introduced], Changes[Deprecated],
1527 Changes[Obsoleted], UnavailableLoc, MessageExpr.
get(), Form,
1528 StrictLoc, ReplacementExpr.
get(), EnvironmentLoc);
1545void Parser::ParseExternalSourceSymbolAttribute(
1551 if (
T.expectAndConsume())
1555 if (!Ident_language) {
1563 bool HasLanguage =
false;
1565 bool HasDefinedIn =
false;
1568 bool HasUSR =
false;
1572 if (Tok.
isNot(tok::identifier)) {
1573 Diag(Tok, diag::err_external_source_symbol_expected_keyword);
1580 if (Keyword == Ident_generated_declaration) {
1581 if (GeneratedDeclaration) {
1582 Diag(Tok, diag::err_external_source_symbol_duplicate_clause) << Keyword;
1586 GeneratedDeclaration = ParseIdentifierLoc();
1590 if (Keyword != Ident_language && Keyword != Ident_defined_in &&
1591 Keyword != Ident_USR) {
1592 Diag(Tok, diag::err_external_source_symbol_expected_keyword);
1598 if (ExpectAndConsume(tok::equal, diag::err_expected_after,
1604 bool HadLanguage = HasLanguage, HadDefinedIn = HasDefinedIn,
1606 if (Keyword == Ident_language)
1608 else if (Keyword == Ident_USR)
1611 HasDefinedIn =
true;
1613 if (!isTokenStringLiteral()) {
1614 Diag(Tok, diag::err_expected_string_literal)
1617 Keyword == Ident_language
1619 : (Keyword == Ident_defined_in ? 1 : 2));
1623 if (Keyword == Ident_language) {
1625 Diag(KeywordLoc, diag::err_external_source_symbol_duplicate_clause)
1631 }
else if (Keyword == Ident_USR) {
1633 Diag(KeywordLoc, diag::err_external_source_symbol_duplicate_clause)
1640 assert(Keyword == Ident_defined_in &&
"Invalid clause keyword!");
1642 Diag(KeywordLoc, diag::err_external_source_symbol_duplicate_clause)
1652 if (
T.consumeClose())
1655 *EndLoc =
T.getCloseLocation();
1660 ScopeName, ScopeLoc, Args, std::size(Args), Form);
1674void Parser::ParseObjCBridgeRelatedAttribute(
1680 if (
T.consumeOpen()) {
1681 Diag(Tok, diag::err_expected) << tok::l_paren;
1686 if (Tok.
isNot(tok::identifier)) {
1687 Diag(Tok, diag::err_objcbridge_related_expected_related_class);
1692 if (ExpectAndConsume(tok::comma)) {
1701 if (Tok.
is(tok::identifier)) {
1704 Diag(Tok, diag::err_objcbridge_related_selector_name);
1710 if (Tok.
is(tok::colon))
1711 Diag(Tok, diag::err_objcbridge_related_selector_name);
1713 Diag(Tok, diag::err_expected) << tok::comma;
1721 if (Tok.
is(tok::identifier))
1723 else if (Tok.
isNot(tok::r_paren)) {
1724 Diag(Tok, diag::err_expected) << tok::r_paren;
1730 if (
T.consumeClose())
1734 *EndLoc =
T.getCloseLocation();
1737 Attrs.
addNew(&ObjCBridgeRelated,
1738 SourceRange(ObjCBridgeRelatedLoc,
T.getCloseLocation()),
1739 ScopeName, ScopeLoc, RelatedClass, ClassMethod, InstanceMethod,
1743void Parser::ParseSwiftNewTypeAttribute(
1750 if (
T.consumeOpen()) {
1751 Diag(Tok, diag::err_expected) << tok::l_paren;
1755 if (Tok.
is(tok::r_paren)) {
1760 if (Tok.
isNot(tok::kw_struct) && Tok.
isNot(tok::kw_enum)) {
1761 Diag(Tok, diag::warn_attribute_type_not_supported)
1763 if (!isTokenSpecial())
1774 if (
T.consumeClose())
1777 *EndLoc =
T.getCloseLocation();
1781 ScopeName, ScopeLoc, Args, std::size(Args), Form);
1784void Parser::ParseTypeTagForDatatypeAttribute(
1788 assert(Tok.
is(tok::l_paren) &&
"Attribute arg list not starting with '('");
1793 if (Tok.
isNot(tok::identifier)) {
1794 Diag(Tok, diag::err_expected) << tok::identifier;
1800 if (ExpectAndConsume(tok::comma)) {
1812 bool LayoutCompatible =
false;
1813 bool MustBeNull =
false;
1815 if (Tok.
isNot(tok::identifier)) {
1816 Diag(Tok, diag::err_expected) << tok::identifier;
1821 if (Flag->
isStr(
"layout_compatible"))
1822 LayoutCompatible =
true;
1823 else if (Flag->
isStr(
"must_be_null"))
1826 Diag(Tok, diag::err_type_safety_unknown_flag) << Flag;
1833 if (!
T.consumeClose()) {
1835 ArgumentKind, MatchingCType.
get(),
1836 LayoutCompatible, MustBeNull, Form);
1840 *EndLoc =
T.getCloseLocation();
1851bool Parser::DiagnoseProhibitedCXX11Attribute() {
1852 assert(Tok.
is(tok::l_square) &&
NextToken().is(tok::l_square));
1854 switch (isCXX11AttributeSpecifier(
true)) {
1855 case CAK_NotAttributeSpecifier:
1859 case CAK_InvalidAttributeSpecifier:
1863 case CAK_AttributeSpecifier:
1868 assert(Tok.
is(tok::r_square) &&
"isCXX11AttributeSpecifier lied");
1870 Diag(BeginLoc, diag::err_attributes_not_allowed)
1874 llvm_unreachable(
"All cases handled above.");
1883 assert((Tok.
is(tok::l_square) &&
NextToken().is(tok::l_square)) ||
1890 ParseCXX11Attributes(Attrs);
1893 (Keyword ?
Diag(
Loc, diag::err_keyword_not_allowed) << Keyword
1894 :
Diag(
Loc, diag::err_attributes_not_allowed))
1899void Parser::DiagnoseProhibitedAttributes(
1901 auto *FirstAttr = Attrs.
empty() ? nullptr : &Attrs.
front();
1902 if (CorrectLocation.
isValid()) {
1904 (FirstAttr && FirstAttr->isRegularKeywordAttribute()
1905 ?
Diag(CorrectLocation, diag::err_keyword_misplaced) << FirstAttr
1906 :
Diag(CorrectLocation, diag::err_attributes_misplaced))
1911 (FirstAttr && FirstAttr->isRegularKeywordAttribute()
1919 unsigned AttrDiagID,
1920 unsigned KeywordDiagID,
1921 bool DiagnoseEmptyAttrs,
1922 bool WarnOnUnknownAttrs) {
1932 if (FirstLSquare.
is(tok::l_square)) {
1933 std::optional<Token> SecondLSquare =
1936 if (SecondLSquare && SecondLSquare->is(tok::l_square)) {
1947 if (AL.isRegularKeywordAttribute()) {
1948 Diag(AL.getLoc(), KeywordDiagID) << AL;
1952 if (!AL.isStandardAttributeSyntax())
1955 if (WarnOnUnknownAttrs)
1956 Diag(AL.getLoc(), diag::warn_unknown_attribute_ignored)
1957 << AL << AL.getRange();
1959 Diag(AL.getLoc(), AttrDiagID) << AL;
1967 if (PA.isStandardAttributeSyntax() || PA.isRegularKeywordAttribute())
1968 Diag(PA.getLoc(), diag::ext_cxx11_attr_placement)
1969 << PA << PA.isRegularKeywordAttribute() << PA.getRange();
1988 if ((AL.getKind() == ParsedAttr::AT_Aligned &&
1989 AL.isDeclspecAttribute()) ||
1990 AL.isMicrosoftAttribute())
1991 ToBeMoved.push_back(&AL);
2026 Decl *SingleDecl =
nullptr;
2028 case tok::kw_template:
2029 case tok::kw_export:
2030 ProhibitAttributes(DeclAttrs);
2031 ProhibitAttributes(DeclSpecAttrs);
2032 return ParseDeclarationStartingWithTemplate(Context, DeclEnd, DeclAttrs);
2033 case tok::kw_inline:
2036 ProhibitAttributes(DeclAttrs);
2037 ProhibitAttributes(DeclSpecAttrs);
2039 return ParseNamespace(Context, DeclEnd, InlineLoc);
2041 return ParseSimpleDeclaration(Context, DeclEnd, DeclAttrs, DeclSpecAttrs,
2042 true,
nullptr, DeclSpecStart);
2044 case tok::kw_cbuffer:
2045 case tok::kw_tbuffer:
2046 SingleDecl = ParseHLSLBuffer(DeclEnd);
2048 case tok::kw_namespace:
2049 ProhibitAttributes(DeclAttrs);
2050 ProhibitAttributes(DeclSpecAttrs);
2051 return ParseNamespace(Context, DeclEnd);
2052 case tok::kw_using: {
2055 return ParseUsingDirectiveOrDeclaration(Context, ParsedTemplateInfo(),
2058 case tok::kw_static_assert:
2059 case tok::kw__Static_assert:
2060 ProhibitAttributes(DeclAttrs);
2061 ProhibitAttributes(DeclSpecAttrs);
2062 SingleDecl = ParseStaticAssertDeclaration(DeclEnd);
2065 return ParseSimpleDeclaration(Context, DeclEnd, DeclAttrs, DeclSpecAttrs,
2066 true,
nullptr, DeclSpecStart);
2098 bool RequireSemi, ForRangeInit *FRI,
SourceLocation *DeclSpecStart) {
2101 OriginalDeclSpecAttrs.
addAll(DeclSpecAttrs.
begin(), DeclSpecAttrs.
end());
2102 OriginalDeclSpecAttrs.
Range = DeclSpecAttrs.
Range;
2108 ParsedTemplateInfo TemplateInfo;
2109 DeclSpecContext DSContext = getDeclSpecContextFromDeclaratorContext(Context);
2110 ParseDeclarationSpecifiers(DS, TemplateInfo,
AS_none, DSContext);
2115 DiagnoseMissingSemiAfterTagDefinition(DS,
AS_none, DSContext))
2120 if (Tok.
is(tok::semi)) {
2121 ProhibitAttributes(DeclAttrs);
2128 DS.complete(TheDecl);
2130 Decl* decls[] = {AnonRecord, TheDecl};
2142 return ParseDeclGroup(DS, Context, DeclAttrs, TemplateInfo, &DeclEnd, FRI);
2149 case tok::annot_cxxscope:
2150 case tok::annot_template_id:
2152 case tok::code_completion:
2153 case tok::coloncolon:
2155 case tok::kw___attribute:
2156 case tok::kw_operator:
2172 case tok::identifier:
2174 case tok::code_completion:
2175 case tok::coloncolon:
2178 case tok::equalequal:
2179 case tok::kw_alignas:
2181 case tok::kw___attribute:
2199 case tok::identifier:
2222 if (Tok.
isOneOf(tok::comma, tok::l_brace, tok::kw_try)) {
2246 case tok::kw_inline:
2251 (!ParsingInObjCContainer || CurParsedObjCImpl))
2255 case tok::kw_namespace:
2260 (!ParsingInObjCContainer || CurParsedObjCImpl))
2266 if (
NextToken().isObjCAtKeyword(tok::objc_end) &&
2267 ParsingInObjCContainer)
2279 case tok::annot_module_begin:
2280 case tok::annot_module_end:
2281 case tok::annot_module_include:
2282 case tok::annot_repl_input_end:
2299 ParsedTemplateInfo &TemplateInfo,
2301 ForRangeInit *FRI) {
2307 LocalAttrs.takeAllFrom(Attrs);
2309 if (TemplateInfo.TemplateParams)
2310 D.setTemplateParameterLists(*TemplateInfo.TemplateParams);
2312 bool IsTemplateSpecOrInst =
2313 (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation ||
2314 TemplateInfo.Kind == ParsedTemplateInfo::ExplicitSpecialization);
2319 if (IsTemplateSpecOrInst)
2323 if (!
D.hasName() && !
D.mayOmitIdentifier()) {
2329 MaybeParseHLSLAnnotations(
D);
2331 if (Tok.
is(tok::kw_requires))
2332 ParseTrailingRequiresClause(
D);
2337 LateParsedAttrList LateParsedAttrs(
true);
2338 if (
D.isFunctionDeclarator()) {
2339 MaybeParseGNUAttributes(
D, &LateParsedAttrs);
2344 if (Tok.
is(tok::kw__Noreturn)) {
2346 const char *PrevSpec;
2352 MaybeParseGNUAttributes(
D, &LateParsedAttrs);
2353 Fixit &= Tok.
isOneOf(tok::semi, tok::l_brace, tok::kw_try);
2355 Diag(
Loc, diag::err_c11_noreturn_misplaced)
2357 << (Fixit ?
FixItHint::CreateInsertion(
D.getBeginLoc(),
"_Noreturn ")
2362 if (Tok.
is(tok::equal) &&
NextToken().is(tok::code_completion)) {
2373 while (
auto Specifier = isCXX11VirtSpecifier()) {
2374 Diag(Tok, diag::err_virt_specifier_outside_class)
2382 if (!isDeclarationAfterDeclarator()) {
2388 if (isStartOfFunctionDefinition(
D)) {
2398 diag::err_function_declared_typedef)
2402 Decl *TheDecl =
nullptr;
2404 if (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation) {
2408 Diag(Tok, diag::err_template_defn_explicit_instantiation) << 0;
2409 TheDecl = ParseFunctionDefinition(
D, ParsedTemplateInfo(),
2414 Diag(
D.getIdentifierLoc(),
2415 diag::err_explicit_instantiation_with_definition)
2423 std::nullopt, LAngleLoc,
nullptr));
2425 TheDecl = ParseFunctionDefinition(
2427 ParsedTemplateInfo(&FakedParamLists,
2434 ParseFunctionDefinition(
D, TemplateInfo, &LateParsedAttrs);
2441 Tok.
is(tok::kw_namespace)) {
2451 Diag(Tok, diag::err_expected_fn_body);
2456 if (Tok.
is(tok::l_brace)) {
2457 Diag(Tok, diag::err_function_definition_not_allowed);
2465 if (ParseAsmAttributesAfterDeclarator(
D))
2474 if (FRI && (Tok.
is(tok::colon) || isTokIdentifier_in())) {
2475 bool IsForRangeLoop =
false;
2477 IsForRangeLoop =
true;
2487 LastRecord.InLifetimeExtendingContext =
true;
2492 if (Tok.
is(tok::l_brace))
2493 FRI->RangeExpr = ParseBraceInitializer();
2504 FRI->LifetimeExtendTemps = std::move(
2509 if (IsForRangeLoop) {
2513 if (
auto *VD = dyn_cast_or_null<VarDecl>(ThisDecl))
2514 VD->setObjCForDecl(
true);
2517 D.complete(ThisDecl);
2523 ParseDeclarationAfterDeclaratorAndAttributes(
D, TemplateInfo, FRI);
2524 if (LateParsedAttrs.size() > 0)
2525 ParseLexedAttributeList(LateParsedAttrs, FirstDecl,
true,
false);
2526 D.complete(FirstDecl);
2528 DeclsInGroup.push_back(FirstDecl);
2536 if (Tok.
isAtStartOfLine() && ExpectSemi && !MightBeDeclarator(Context)) {
2540 Diag(CommaLoc, diag::err_expected_semi_declaration)
2550 if (TemplateInfo.Kind != ParsedTemplateInfo::NonTemplate &&
2551 D.isFirstDeclarator()) {
2552 Diag(CommaLoc, diag::err_multiple_template_declarators)
2553 << TemplateInfo.Kind;
2558 D.setCommaLoc(CommaLoc);
2567 MaybeParseGNUAttributes(
D);
2571 DiagnoseAndSkipExtendedMicrosoftTypeAttributes();
2576 MaybeParseHLSLAnnotations(
D);
2578 if (!
D.isInvalidType()) {
2583 if (Tok.
is(tok::kw_requires))
2584 ParseTrailingRequiresClause(
D);
2585 Decl *ThisDecl = ParseDeclarationAfterDeclarator(
D, TemplateInfo);
2586 D.complete(ThisDecl);
2588 DeclsInGroup.push_back(ThisDecl);
2595 if (ExpectSemi && ExpectAndConsumeSemi(
2597 ? diag::err_invalid_token_after_toplevel_declarator
2598 : diag::err_expected_semi_declaration)) {
2611bool Parser::ParseAsmAttributesAfterDeclarator(
Declarator &
D) {
2613 if (Tok.
is(tok::kw_asm)) {
2616 if (AsmLabel.isInvalid()) {
2621 D.setAsmLabel(AsmLabel.get());
2625 MaybeParseGNUAttributes(
D);
2651Decl *Parser::ParseDeclarationAfterDeclarator(
2652 Declarator &
D,
const ParsedTemplateInfo &TemplateInfo) {
2653 if (ParseAsmAttributesAfterDeclarator(
D))
2656 return ParseDeclarationAfterDeclaratorAndAttributes(
D, TemplateInfo);
2659Decl *Parser::ParseDeclarationAfterDeclaratorAndAttributes(
2660 Declarator &
D,
const ParsedTemplateInfo &TemplateInfo, ForRangeInit *FRI) {
2662 struct InitializerScopeRAII {
2669 :
P(
P),
D(
D), ThisDecl(ThisDecl), Entered(
false) {
2670 if (ThisDecl &&
P.getLangOpts().CPlusPlus) {
2672 if (
D.getCXXScopeSpec().isSet()) {
2674 S =
P.getCurScope();
2677 P.Actions.ActOnCXXEnterDeclInitializer(S, ThisDecl);
2682 ~InitializerScopeRAII() {
2683 if (ThisDecl &&
P.getLangOpts().CPlusPlus) {
2685 if (
D.getCXXScopeSpec().isSet())
2686 S =
P.getCurScope();
2689 P.Actions.ActOnCXXExitDeclInitializer(S, ThisDecl);
2698 InitKind TheInitKind;
2700 if (isTokenEqualOrEqualTypo())
2701 TheInitKind = InitKind::Equal;
2702 else if (Tok.
is(tok::l_paren))
2703 TheInitKind = InitKind::CXXDirect;
2705 (!CurParsedObjCImpl || !
D.isFunctionDeclarator()))
2706 TheInitKind = InitKind::CXXBraced;
2708 TheInitKind = InitKind::Uninitialized;
2709 if (TheInitKind != InitKind::Uninitialized)
2710 D.setHasInitializer();
2713 Decl *ThisDecl =
nullptr;
2714 Decl *OuterDecl =
nullptr;
2715 switch (TemplateInfo.Kind) {
2716 case ParsedTemplateInfo::NonTemplate:
2720 case ParsedTemplateInfo::Template:
2721 case ParsedTemplateInfo::ExplicitSpecialization: {
2723 *TemplateInfo.TemplateParams,
2725 if (
VarTemplateDecl *VT = dyn_cast_or_null<VarTemplateDecl>(ThisDecl)) {
2728 ThisDecl = VT->getTemplatedDecl();
2733 case ParsedTemplateInfo::ExplicitInstantiation: {
2734 if (Tok.
is(tok::semi)) {
2736 getCurScope(), TemplateInfo.ExternLoc, TemplateInfo.TemplateLoc,
D);
2741 ThisDecl = ThisRes.
get();
2749 Diag(Tok, diag::err_template_defn_explicit_instantiation)
2755 Diag(
D.getIdentifierLoc(),
2756 diag::err_explicit_instantiation_with_definition)
2764 std::nullopt, LAngleLoc,
nullptr));
2776 switch (TheInitKind) {
2778 case InitKind::Equal: {
2781 if (Tok.
is(tok::kw_delete)) {
2782 if (
D.isFunctionDeclarator())
2787 SkipDeletedFunctionBody();
2788 }
else if (Tok.
is(tok::kw_default)) {
2789 if (
D.isFunctionDeclarator())
2796 InitializerScopeRAII
InitScope(*
this,
D, ThisDecl);
2798 if (Tok.
is(tok::code_completion)) {
2811 if (Tok.
is(tok::r_paren) && FRI &&
D.isFirstDeclarator()) {
2812 Diag(EqualLoc, diag::err_single_decl_assign_in_for_range)
2816 FRI->ColonLoc = EqualLoc;
2818 FRI->RangeExpr =
Init;
2821 if (
Init.isInvalid()) {
2823 StopTokens.push_back(tok::comma);
2826 StopTokens.push_back(tok::r_paren);
2835 case InitKind::CXXDirect: {
2842 InitializerScopeRAII
InitScope(*
this,
D, ThisDecl);
2844 auto ThisVarDecl = dyn_cast_or_null<VarDecl>(ThisDecl);
2845 auto RunSignatureHelp = [&]() {
2848 ThisVarDecl->getType()->getCanonicalTypeInternal(),
2851 CalledSignatureHelp =
true;
2852 return PreferredType;
2854 auto SetPreferredType = [&] {
2855 PreferredType.enterFunctionArgument(Tok.
getLocation(), RunSignatureHelp);
2858 llvm::function_ref<void()> ExpressionStarts;
2864 ExpressionStarts = SetPreferredType;
2867 bool SawError = ParseExpressionList(Exprs, ExpressionStarts);
2872 ThisVarDecl->getType()->getCanonicalTypeInternal(),
2875 CalledSignatureHelp =
true;
2884 T.getCloseLocation(),
2891 case InitKind::CXXBraced: {
2893 Diag(Tok, diag::warn_cxx98_compat_generalized_initializer_lists);
2895 InitializerScopeRAII
InitScope(*
this,
D, ThisDecl);
2897 PreferredType.enterVariableInit(Tok.
getLocation(), ThisDecl);
2900 if (
Init.isInvalid()) {
2906 case InitKind::Uninitialized: {
2913 return OuterDecl ? OuterDecl : ThisDecl;
2922void Parser::ParseSpecifierQualifierList(
2925 ParsedTemplateInfo TemplateInfo;
2929 ParseDeclarationSpecifiers(DS, TemplateInfo, AS, DSC,
nullptr,
2930 AllowImplicitTypename);
2935 Diag(Tok, diag::err_expected_type);
2938 Diag(Tok, diag::err_typename_requires_specqual);
2949 diag::err_typename_invalid_storageclass);
2993 return T.isOneOf(tok::l_square, tok::l_paren, tok::r_paren, tok::semi,
2994 tok::comma, tok::equal, tok::kw_asm, tok::l_brace,
3008 ParsedTemplateInfo &TemplateInfo,
3011 assert(Tok.
is(tok::identifier) &&
"should have identifier");
3033 if (!isTypeSpecifier(DSC) &&
getLangOpts().isImplicitIntAllowed() &&
3051 AnnotateScopeToken(*SS,
false);
3062 DSC == DeclSpecContext::DSC_template_type_arg)) {
3063 const char *PrevSpec;
3079 if (SS ==
nullptr) {
3080 const char *TagName =
nullptr, *FixitTagName =
nullptr;
3086 TagName=
"enum" ; FixitTagName =
"enum " ; TagKind=tok::kw_enum ;
break;
3088 TagName=
"union" ; FixitTagName =
"union " ;TagKind=tok::kw_union ;
break;
3090 TagName=
"struct"; FixitTagName =
"struct ";TagKind=tok::kw_struct;
break;
3092 TagName=
"__interface"; FixitTagName =
"__interface ";
3093 TagKind=tok::kw___interface;
break;
3095 TagName=
"class" ; FixitTagName =
"class " ;TagKind=tok::kw_class ;
break;
3103 Diag(
Loc, diag::err_use_of_tag_name_without_tag)
3104 << TokenName << TagName <<
getLangOpts().CPlusPlus
3110 Diag((*I)->getLocation(), diag::note_decl_hiding_tag_type)
3111 << TokenName << TagName;
3115 if (TagKind == tok::kw_enum)
3116 ParseEnumSpecifier(
Loc, DS, TemplateInfo, AS,
3117 DeclSpecContext::DSC_normal);
3119 ParseClassSpecifier(TagKind,
Loc, DS, TemplateInfo, AS,
3121 DeclSpecContext::DSC_normal, Attrs);
3128 if (!isTypeSpecifier(DSC) && (!SS || DSC == DeclSpecContext::DSC_top_level ||
3129 DSC == DeclSpecContext::DSC_class)) {
3133 case tok::l_paren: {
3140 TentativeParsingAction PA(*
this);
3142 TPResult TPR = TryParseDeclarator(
false);
3145 if (TPR != TPResult::False) {
3153 if (DSC == DeclSpecContext::DSC_class ||
3154 (DSC == DeclSpecContext::DSC_top_level && SS)) {
3157 Diag(
Loc, diag::err_constructor_bad_name)
3178 AnnotateScopeToken(*SS,
false);
3200 const char *PrevSpec;
3221 if (IsTemplateName) {
3223 TemplateArgList Args;
3224 ParseTemplateIdAfterTemplateName(
true, LAngle, Args, RAngle);
3238Parser::DeclSpecContext
3242 return DeclSpecContext::DSC_class;
3244 return DeclSpecContext::DSC_top_level;
3246 return DeclSpecContext::DSC_template_param;
3248 return DeclSpecContext::DSC_template_arg;
3250 return DeclSpecContext::DSC_template_type_arg;
3253 return DeclSpecContext::DSC_trailing;
3256 return DeclSpecContext::DSC_alias_declaration;
3258 return DeclSpecContext::DSC_association;
3260 return DeclSpecContext::DSC_type_specifier;
3262 return DeclSpecContext::DSC_condition;
3264 return DeclSpecContext::DSC_conv_operator;
3266 return DeclSpecContext::DSC_new;
3281 return DeclSpecContext::DSC_normal;
3284 llvm_unreachable(
"Missing DeclaratorContext case");
3297 if (isTypeIdInParens()) {
3326 assert(Tok.
isOneOf(tok::kw_alignas, tok::kw__Alignas) &&
3327 "Not an alignment-specifier!");
3334 if (
T.expectAndConsume())
3341 ParseAlignArgument(PP.
getSpelling(KWTok),
T.getOpenLocation(),
3350 *EndLoc =
T.getCloseLocation();
3357 ArgExprs.push_back(ArgExpr.
get());
3358 Attrs.
addNew(KWName, KWLoc,
nullptr, KWLoc, ArgExprs.data(), 1, Kind,
3363void Parser::DistributeCLateParsedAttrs(
Decl *Dcl,
3364 LateParsedAttrList *LateAttrs) {
3369 for (
auto *LateAttr : *LateAttrs) {
3370 if (LateAttr->Decls.empty())
3371 LateAttr->addDecl(Dcl);
3384 assert(Tok.
is(tok::l_paren) &&
"Attribute arg list not starting with '('");
3389 if (Tok.
is(tok::r_paren)) {
3397 using ExpressionKind =
3401 ExpressionKind::EK_AttrArgument);
3411 ArgExprs.push_back(ArgExpr.
get());
3421 ScopeName, ScopeLoc, ArgExprs.data(), ArgExprs.size(), Form);
3424ExprResult Parser::ParseExtIntegerArgument() {
3425 assert(Tok.
isOneOf(tok::kw__ExtInt, tok::kw__BitInt) &&
3426 "Not an extended int type");
3430 if (
T.expectAndConsume())
3439 if(
T.consumeClose())
3453 DeclSpecContext DSContext,
3454 LateParsedAttrList *LateAttrs) {
3457 bool EnteringContext = (DSContext == DeclSpecContext::DSC_class ||
3458 DSContext == DeclSpecContext::DSC_top_level);
3461 Tok.
isOneOf(tok::identifier, tok::coloncolon, tok::kw_decltype,
3462 tok::annot_template_id) &&
3468 bool HasScope = Tok.
is(tok::annot_cxxscope);
3474 bool MightBeDeclarator =
true;
3475 if (Tok.
isOneOf(tok::kw_typename, tok::annot_typename)) {
3477 MightBeDeclarator =
false;
3478 }
else if (AfterScope.
is(tok::annot_template_id)) {
3484 MightBeDeclarator =
false;
3485 }
else if (AfterScope.
is(tok::identifier)) {
3486 const Token &Next = HasScope ? GetLookAheadToken(2) :
NextToken();
3490 if (Next.isOneOf(tok::star, tok::amp, tok::ampamp, tok::identifier,
3491 tok::annot_cxxscope, tok::coloncolon)) {
3493 MightBeDeclarator =
false;
3494 }
else if (HasScope) {
3505 switch (Classification.
getKind()) {
3511 llvm_unreachable(
"typo correction is not possible here");
3518 MightBeDeclarator =
false;
3534 if (MightBeDeclarator)
3539 diag::err_expected_after)
3550 ParsedTemplateInfo NotATemplate;
3551 ParseDeclarationSpecifiers(DS, NotATemplate, AS, DSContext, LateAttrs);
3582void Parser::ParseDeclarationSpecifiers(
3584 DeclSpecContext DSContext, LateParsedAttrList *LateAttrs,
3596 if (DSContext == DeclSpecContext::DSC_conv_operator) {
3599 DSContext = DeclSpecContext::DSC_type_specifier;
3602 bool EnteringContext = (DSContext == DeclSpecContext::DSC_class ||
3603 DSContext == DeclSpecContext::DSC_top_level);
3604 bool AttrsLastTime =
false;
3610 bool isStorageClass =
false;
3611 const char *PrevSpec =
nullptr;
3612 unsigned DiagID = 0;
3633 auto handleOpenCLImageKW = [&] (StringRef Ext,
TypeSpecifierType ImageTypeSpec) {
3647 bool IsTemplateSpecOrInst =
3648 (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation ||
3649 TemplateInfo.Kind == ParsedTemplateInfo::ExplicitSpecialization);
3658 ProhibitAttributes(attrs);
3662 if (!PA.isCXX11Attribute() && !PA.isC23Attribute() &&
3663 !PA.isRegularKeywordAttribute())
3671 if (PA.getKind() == ParsedAttr::AT_VectorSize) {
3672 Diag(PA.getLoc(), diag::warn_attribute_ignored) << PA;
3679 if (PA.isTypeAttr() && PA.getKind() != ParsedAttr::AT_LifetimeBound &&
3680 PA.getKind() != ParsedAttr::AT_AnyX86NoCfCheck)
3682 Diag(PA.getLoc(), diag::err_attribute_not_type_attr)
3683 << PA << PA.isRegularKeywordAttribute();
3692 DS.
Finish(Actions, Policy);
3696 case tok::kw__Alignas:
3697 diagnoseUseOfC11Keyword(Tok);
3699 case tok::kw_alignas:
3705 if (Tok.
getKind() == tok::kw_alignas)
3706 Diag(Tok, diag::warn_c23_compat_keyword) << Tok.
getName();
3712 if (!isAllowedCXX11AttributeSpecifier())
3713 goto DoneWithDeclSpec;
3716 ProhibitAttributes(attrs);
3723 ParseCXX11Attributes(attrs);
3724 AttrsLastTime =
true;
3727 case tok::code_completion: {
3731 bool AllowNonIdentifiers
3737 bool AllowNestedNameSpecifiers
3738 = DSContext == DeclSpecContext::DSC_top_level ||
3743 getCurScope(), DS, AllowNonIdentifiers, AllowNestedNameSpecifiers);
3748 if (TemplateInfo.Kind != ParsedTemplateInfo::NonTemplate)
3749 CCC = DSContext == DeclSpecContext::DSC_class
3752 else if (DSContext == DeclSpecContext::DSC_class)
3756 else if (CurParsedObjCImpl)
3764 case tok::coloncolon:
3770 goto DoneWithDeclSpec;
3772 if (Tok.
is(tok::coloncolon))
3773 goto DoneWithDeclSpec;
3776 case tok::annot_cxxscope: {
3778 goto DoneWithDeclSpec;
3781 if (TemplateInfo.TemplateParams)
3791 ? takeTemplateIdAnnotation(Next)
3797 ConsumeAnnotationToken();
3811 if ((DSContext == DeclSpecContext::DSC_top_level ||
3812 DSContext == DeclSpecContext::DSC_class) &&
3815 isConstructorDeclarator(
false,
3822 goto DoneWithDeclSpec;
3826 ConsumeAnnotationToken();
3827 assert(Tok.
is(tok::annot_template_id) &&
3828 "ParseOptionalCXXScopeSpecifier not working");
3829 AnnotateTemplateIdTokenAsType(SS, AllowImplicitTypename);
3839 ConsumeAnnotationToken();
3843 if (Next.is(tok::annot_typename)) {
3845 ConsumeAnnotationToken();
3849 PrevSpec, DiagID,
T, Policy);
3853 ConsumeAnnotationToken();
3857 Next.is(tok::annot_template_id) &&
3861 ConsumeAnnotationToken();
3862 AnnotateTemplateIdTokenAsType(SS, AllowImplicitTypename);
3866 if (Next.isNot(tok::identifier))
3867 goto DoneWithDeclSpec;
3872 if ((DSContext == DeclSpecContext::DSC_top_level ||
3873 DSContext == DeclSpecContext::DSC_class) &&
3876 isConstructorDeclarator(
false,
3880 goto DoneWithDeclSpec;
3889 *Next.getIdentifierInfo(), Next.getLocation(),
getCurScope(), &SS,
3890 false,
false,
nullptr,
3893 isClassTemplateDeductionContext(DSContext), AllowImplicitTypename);
3895 if (IsTemplateSpecOrInst)
3903 if (TryAnnotateTypeConstraint())
3904 goto DoneWithDeclSpec;
3905 if (Tok.
isNot(tok::annot_cxxscope) ||
3909 ConsumeAnnotationToken();
3911 if (ParseImplicitInt(DS, &SS, TemplateInfo, AS, DSContext, Attrs)) {
3912 if (!Attrs.
empty()) {
3913 AttrsLastTime =
true;
3914 attrs.takeAllFrom(Attrs);
3918 goto DoneWithDeclSpec;
3922 ConsumeAnnotationToken();
3925 DiagID, TypeRep, Policy);
3935 case tok::annot_typename: {
3939 goto DoneWithDeclSpec;
3948 ConsumeAnnotationToken();
3953 case tok::kw___is_signed:
3964 TryKeywordIdentFallback(
true);
3967 goto DoneWithDeclSpec;
3970 case tok::kw___super:
3971 case tok::kw_decltype:
3972 case tok::identifier:
3978 goto DoneWithDeclSpec;
3984 if (!
getLangOpts().DeclSpecKeyword && Tok.
is(tok::identifier) &&
3986 Diag(
Loc, diag::err_ms_attributes_not_enabled);
3996 if (
T.consumeOpen()) {
3997 assert(
false &&
"Not a left paren?");
4016 if (IsTemplateSpecOrInst)
4020 if (IsTemplateSpecOrInst)
4023 goto DoneWithDeclSpec;
4026 if (!Tok.
is(tok::identifier))
4031 if (TryAltiVecToken(DS,
Loc, PrevSpec, DiagID,
isInvalid))
4037 goto DoneWithDeclSpec;
4039 if (DSContext == DeclSpecContext::DSC_objc_method_result &&
4040 isObjCInstancetype()) {
4044 DiagID, TypeRep, Policy);
4057 isConstructorDeclarator(
true,
4060 goto DoneWithDeclSpec;
4064 false,
false,
nullptr,
false,
false,
4065 isClassTemplateDeductionContext(DSContext));
4070 if (TryAnnotateTypeConstraint())
4071 goto DoneWithDeclSpec;
4072 if (Tok.
isNot(tok::identifier))
4075 if (ParseImplicitInt(DS,
nullptr, TemplateInfo, AS, DSContext, Attrs)) {
4076 if (!Attrs.
empty()) {
4077 AttrsLastTime =
true;
4078 attrs.takeAllFrom(Attrs);
4082 goto DoneWithDeclSpec;
4089 (DSContext == DeclSpecContext::DSC_class ||
4090 DSContext == DeclSpecContext::DSC_top_level) &&
4093 isConstructorDeclarator(
true,
4095 goto DoneWithDeclSpec;
4098 DiagID, TypeRep, Policy);
4110 TypeResult NewTypeRep = parseObjCTypeArgsAndProtocolQualifiers(
4125 case tok::annot_template_id: {
4137 TemplateId =
nullptr;
4145 tok::kw_volatile, tok::kw_restrict, tok::amp,
4147 Diag(
Loc, diag::err_placeholder_expected_auto_or_decltype_auto)
4151 TemplateId, Policy);
4155 goto DoneWithDeclSpec;
4158 TemplateId =
nullptr;
4160 ConsumeAnnotationToken();
4164 if (Tracker.consumeOpen()) {
4166 Diag(Tok, diag::err_expected) << tok::l_paren;
4170 Tracker.skipToEnd();
4171 Diag(Tok, diag::err_placeholder_expected_auto_or_decltype_auto)
4176 Tracker.consumeClose();
4184 DiagID, TemplateId, Policy);
4187 TemplateId, Policy);
4196 goto DoneWithDeclSpec;
4204 isConstructorDeclarator(
true,
4207 goto DoneWithDeclSpec;
4212 AnnotateTemplateIdTokenAsType(SS, AllowImplicitTypename);
4217 case tok::kw___attribute:
4218 case tok::kw___declspec:
4219 ParseAttributes(PAKM_GNU | PAKM_Declspec, DS.
getAttributes(), LateAttrs);
4223 case tok::kw___forceinline: {
4228 nullptr, 0, tok::kw___forceinline);
4232 case tok::kw___unaligned:
4237 case tok::kw___sptr:
4238 case tok::kw___uptr:
4239 case tok::kw___ptr64:
4240 case tok::kw___ptr32:
4242 case tok::kw___cdecl:
4243 case tok::kw___stdcall:
4244 case tok::kw___fastcall:
4245 case tok::kw___thiscall:
4246 case tok::kw___regcall:
4247 case tok::kw___vectorcall:
4251 case tok::kw___funcref:
4256 case tok::kw___pascal:
4261 case tok::kw___kernel:
4266 case tok::kw___noinline__:
4271 case tok::kw__Nonnull:
4272 case tok::kw__Nullable:
4273 case tok::kw__Nullable_result:
4274 case tok::kw__Null_unspecified:
4279 case tok::kw___kindof:
4281 nullptr, 0, tok::kw___kindof);
4286 case tok::kw_typedef:
4288 PrevSpec, DiagID, Policy);
4289 isStorageClass =
true;
4291 case tok::kw_extern:
4293 Diag(Tok, diag::ext_thread_before) <<
"extern";
4295 PrevSpec, DiagID, Policy);
4296 isStorageClass =
true;
4298 case tok::kw___private_extern__:
4300 Loc, PrevSpec, DiagID, Policy);
4301 isStorageClass =
true;
4303 case tok::kw_static:
4305 Diag(Tok, diag::ext_thread_before) <<
"static";
4307 PrevSpec, DiagID, Policy);
4308 isStorageClass =
true;
4312 if (isKnownToBeTypeSpecifier(GetLookAheadToken(1))) {
4314 PrevSpec, DiagID, Policy);
4316 Diag(Tok, diag::ext_auto_storage_class)
4323 PrevSpec, DiagID, Policy);
4324 isStorageClass =
true;
4326 case tok::kw___auto_type:
4327 Diag(Tok, diag::ext_auto_type);
4331 case tok::kw_register:
4333 PrevSpec, DiagID, Policy);
4334 isStorageClass =
true;
4336 case tok::kw_mutable:
4338 PrevSpec, DiagID, Policy);
4339 isStorageClass =
true;
4341 case tok::kw___thread:
4344 isStorageClass =
true;
4346 case tok::kw_thread_local:
4348 Diag(Tok, diag::warn_c23_compat_keyword) << Tok.
getName();
4357 Loc, PrevSpec, DiagID);
4358 isStorageClass =
true;
4360 case tok::kw__Thread_local:
4361 diagnoseUseOfC11Keyword(Tok);
4363 Loc, PrevSpec, DiagID);
4364 isStorageClass =
true;
4368 case tok::kw_inline:
4371 case tok::kw_virtual:
4375 !
getActions().getOpenCLOptions().isAvailableOption(
4377 DiagID = diag::err_openclcxx_virtual_function;
4384 case tok::kw_explicit: {
4388 ConsumedEnd = ExplicitLoc;
4390 if (Tok.
is(tok::l_paren)) {
4393 ? diag::warn_cxx17_compat_explicit_bool
4394 : diag::ext_explicit_bool);
4398 Tracker.consumeOpen();
4405 if (ExplicitExpr.isUsable()) {
4407 Tracker.consumeClose();
4411 Tracker.skipToEnd();
4417 ExplicitSpec, CloseParenLoc);
4420 case tok::kw__Noreturn:
4421 diagnoseUseOfC11Keyword(Tok);
4426 case tok::kw_friend:
4427 if (DSContext == DeclSpecContext::DSC_class) {
4434 DiagID = diag::err_friend_invalid_in_context;
4440 case tok::kw___module_private__:
4445 case tok::kw_constexpr:
4447 Diag(Tok, diag::warn_c23_compat_keyword) << Tok.
getName();
4451 case tok::kw_consteval:
4455 case tok::kw_constinit:
4471 PrevSpec, DiagID, Policy);
4473 case tok::kw___int64:
4475 PrevSpec, DiagID, Policy);
4477 case tok::kw_signed:
4481 case tok::kw_unsigned:
4485 case tok::kw__Complex:
4487 Diag(Tok, diag::ext_c99_feature) << Tok.
getName();
4491 case tok::kw__Imaginary:
4493 Diag(Tok, diag::ext_c99_feature) << Tok.
getName();
4509 case tok::kw__ExtInt:
4510 case tok::kw__BitInt: {
4511 DiagnoseBitIntUse(Tok);
4516 ConsumedEnd = PrevTokLocation;
4519 case tok::kw___int128:
4527 case tok::kw___bf16:
4535 case tok::kw_double:
4539 case tok::kw__Float16:
4543 case tok::kw__Accum:
4545 "This keyword is only used when fixed point types are enabled "
4546 "with `-ffixed-point`");
4550 case tok::kw__Fract:
4552 "This keyword is only used when fixed point types are enabled "
4553 "with `-ffixed-point`");
4559 "This keyword is only used when fixed point types are enabled "
4560 "with `-ffixed-point`");
4563 case tok::kw___float128:
4567 case tok::kw___ibm128:
4571 case tok::kw_wchar_t:
4575 case tok::kw_char8_t:
4579 case tok::kw_char16_t:
4583 case tok::kw_char32_t:
4589 Diag(Tok, diag::warn_c23_compat_keyword) << Tok.
getName();
4593 Diag(Tok, diag::ext_c99_feature) << Tok.
getName();
4595 if (Tok.
is(tok::kw_bool) &&
4599 DiagID = diag::err_bool_redeclaration;
4608 case tok::kw__Decimal32:
4612 case tok::kw__Decimal64:
4616 case tok::kw__Decimal128:
4620 case tok::kw___vector:
4623 case tok::kw___pixel:
4626 case tok::kw___bool:
4631 getLangOpts().getOpenCLCompatibleVersion() < 200) {
4636 goto DoneWithDeclSpec;
4638 DiagID = diag::err_opencl_unknown_type_specifier;
4645#define IMAGE_READ_WRITE_TYPE(Type, Id, Ext)
4646#define IMAGE_WRITE_TYPE(Type, Id, Ext)
4647#define IMAGE_READ_TYPE(ImgType, Id, Ext) \
4648 case tok::kw_##ImgType##_t: \
4649 if (!handleOpenCLImageKW(Ext, DeclSpec::TST_##ImgType##_t)) \
4650 goto DoneWithDeclSpec; \
4652#include "clang/Basic/OpenCLImageTypes.def"
4653 case tok::kw___unknown_anytype:
4655 PrevSpec, DiagID, Policy);
4660 case tok::kw_struct:
4661 case tok::kw___interface:
4662 case tok::kw_union: {
4670 ParseClassSpecifier(Kind,
Loc, DS, TemplateInfo, AS,
4671 EnteringContext, DSContext, Attributes);
4675 if (!Attributes.empty()) {
4676 AttrsLastTime =
true;
4677 attrs.takeAllFrom(Attributes);
4685 ParseEnumSpecifier(
Loc, DS, TemplateInfo, AS, DSContext);
4693 case tok::kw_volatile:
4697 case tok::kw_restrict:
4703 case tok::kw_typename:
4706 goto DoneWithDeclSpec;
4708 if (!Tok.
is(tok::kw_typename))
4713 case tok::kw_typeof:
4714 case tok::kw_typeof_unqual:
4715 ParseTypeofSpecifier(DS);
4718 case tok::annot_decltype:
4719 ParseDecltypeSpecifier(DS);
4722 case tok::annot_pack_indexing_type:
4723 ParsePackIndexingType(DS);
4726 case tok::annot_pragma_pack:
4730 case tok::annot_pragma_ms_pragma:
4731 HandlePragmaMSPragma();
4734 case tok::annot_pragma_ms_vtordisp:
4735 HandlePragmaMSVtorDisp();
4738 case tok::annot_pragma_ms_pointers_to_members:
4739 HandlePragmaMSPointersToMembers();
4742#define TRANSFORM_TYPE_TRAIT_DEF(_, Trait) case tok::kw___##Trait:
4743#include "clang/Basic/TransformTypeTraits.def"
4747 if (!MaybeParseTypeTransformTypeSpecifier(DS))
4748 goto ParseIdentifier;
4751 case tok::kw__Atomic:
4756 diagnoseUseOfC11Keyword(Tok);
4758 ParseAtomicSpecifier(DS);
4766 case tok::kw___generic:
4771 if (!Actions.
getLangOpts().OpenCLGenericAddressSpace) {
4772 DiagID = diag::err_opencl_unknown_type_specifier;
4778 case tok::kw_private:
4782 goto DoneWithDeclSpec;
4784 case tok::kw___private:
4785 case tok::kw___global:
4786 case tok::kw___local:
4787 case tok::kw___constant:
4789 case tok::kw___read_only:
4790 case tok::kw___write_only:
4791 case tok::kw___read_write:
4795 case tok::kw_groupshared:
4803#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) \
4804 case tok::kw_##Name: \
4805 isInvalid = DS.SetTypeSpecType(DeclSpec::TST_##Name, Loc, PrevSpec, \
4808#include "clang/Basic/HLSLIntangibleTypes.def"
4815 goto DoneWithDeclSpec;
4820 if (
Type.isUsable()) {
4822 PrevSpec, DiagID,
Type.get(),
4824 Diag(StartLoc, DiagID) << PrevSpec;
4840 assert(PrevSpec &&
"Method did not return previous specifier!");
4843 if (DiagID == diag::ext_duplicate_declspec ||
4844 DiagID == diag::ext_warn_duplicate_declspec ||
4845 DiagID == diag::err_duplicate_declspec)
4849 else if (DiagID == diag::err_opencl_unknown_type_specifier) {
4853 Diag(
Loc, DiagID) << PrevSpec;
4856 if (DiagID != diag::err_bool_redeclaration && ConsumedEnd.
isInvalid())
4860 AttrsLastTime =
false;
4872 if (!RD || !RD->getName().empty() || RD->isAnonymousStructOrUnion())
4875 for (
auto *I : RD->decls()) {
4876 auto *VD = dyn_cast<ValueDecl>(I);
4884 for (
const auto &DD : CAT->dependent_decls()) {
4885 if (!RD->containsDecl(DD.getDecl())) {
4886 P.Diag(VD->getBeginLoc(), diag::err_count_attr_param_not_in_same_struct)
4887 << DD.getDecl() << CAT->getKind() << CAT->isArrayType();
4888 P.Diag(DD.getDecl()->getBeginLoc(),
4889 diag::note_flexible_array_counted_by_attr_field)
4917void Parser::ParseStructDeclaration(
4920 LateParsedAttrList *LateFieldAttrs) {
4922 if (Tok.
is(tok::kw___extension__)) {
4926 return ParseStructDeclaration(DS, FieldsCallback, LateFieldAttrs);
4931 MaybeParseCXX11Attributes(Attrs);
4934 ParseSpecifierQualifierList(DS);
4938 if (Tok.
is(tok::semi)) {
4943 ProhibitAttributes(Attrs);
4947 assert(!AnonRecord &&
"Did not expect anonymous struct or union here");
4953 bool FirstDeclarator =
true;
4957 DeclaratorInfo.D.setCommaLoc(CommaLoc);
4960 if (!FirstDeclarator) {
4963 DiagnoseAndSkipCXX11Attributes();
4964 MaybeParseGNUAttributes(DeclaratorInfo.D);
4965 DiagnoseAndSkipCXX11Attributes();
4970 if (Tok.
isNot(tok::colon)) {
4973 ParseDeclarator(DeclaratorInfo.D);
4975 DeclaratorInfo.D.SetIdentifier(
nullptr, Tok.
getLocation());
4987 DeclaratorInfo.BitfieldSize = Res.
get();
4991 MaybeParseGNUAttributes(DeclaratorInfo.D, LateFieldAttrs);
4994 Decl *
Field = FieldsCallback(DeclaratorInfo);
4996 DistributeCLateParsedAttrs(Field, LateFieldAttrs);
5003 FirstDeclarator =
false;
5009void Parser::ParseLexedCAttributeList(LateParsedAttrList &LAs,
bool EnterScope,
5011 assert(LAs.parseSoon() &&
5012 "Attribute list should be marked for immediate parsing.");
5013 for (
auto *LA : LAs) {
5014 ParseLexedCAttribute(*LA,
EnterScope, OutAttrs);
5025void Parser::ParseLexedCAttribute(LateParsedAttribute &LA,
bool EnterScope,
5034 LA.Toks.push_back(AttrEnd);
5038 LA.Toks.push_back(Tok);
5039 PP.EnterTokenStream(LA.Toks,
true,
5050 assert(LA.Decls.size() <= 1 &&
5051 "late field attribute expects to have at most one declaration.");
5054 ParseGNUAttributeArgs(&LA.AttrName, LA.AttrNameLoc, Attrs,
nullptr,
nullptr,
5057 for (
auto *
D : LA.Decls)
5062 while (Tok.
isNot(tok::eof))
5087 "parsing struct/union body");
5091 if (
T.consumeOpen())
5099 LateParsedAttrList LateFieldAttrs(
true,
5103 while (!tryParseMisplacedModuleImport() && Tok.
isNot(tok::r_brace) &&
5104 Tok.
isNot(tok::eof)) {
5108 if (Tok.
is(tok::semi)) {
5109 ConsumeExtraSemi(InsideStruct,
TagType);
5114 if (Tok.
isOneOf(tok::kw__Static_assert, tok::kw_static_assert)) {
5116 ParseStaticAssertDeclaration(DeclEnd);
5120 if (Tok.
is(tok::annot_pragma_pack)) {
5125 if (Tok.
is(tok::annot_pragma_align)) {
5126 HandlePragmaAlign();
5130 if (Tok.
isOneOf(tok::annot_pragma_openmp, tok::annot_attr_openmp)) {
5134 (void)ParseOpenMPDeclarativeDirectiveWithExtDecl(AS, Attrs);
5138 if (Tok.
is(tok::annot_pragma_openacc)) {
5147 ConsumeAnnotationToken();
5151 if (!Tok.
is(tok::at)) {
5157 FD.D, FD.BitfieldSize);
5164 ParseStructDeclaration(DS, CFieldCallback, &LateFieldAttrs);
5168 Diag(Tok, diag::err_unexpected_at);
5173 ExpectAndConsume(tok::l_paren);
5174 if (!Tok.
is(tok::identifier)) {
5175 Diag(Tok, diag::err_expected) << tok::identifier;
5183 ExpectAndConsume(tok::r_paren);
5189 if (Tok.
is(tok::r_brace)) {
5190 ExpectAndConsume(tok::semi, diag::ext_expected_semi_decl_list);
5194 ExpectAndConsume(tok::semi, diag::err_expected_semi_decl_list);
5205 MaybeParseGNUAttributes(attrs, &LateFieldAttrs);
5208 ParseLexedCAttributeList(LateFieldAttrs,
false);
5213 T.getOpenLocation(),
T.getCloseLocation(), attrs);
5249 const ParsedTemplateInfo &TemplateInfo,
5252 if (Tok.
is(tok::code_completion)) {
5262 MaybeParseAttributes(PAKM_GNU | PAKM_Declspec | PAKM_CXX11, attrs);
5265 bool IsScopedUsingClassTag =
false;
5270 : diag::ext_scoped_enum);
5271 IsScopedUsingClassTag = Tok.
is(tok::kw_class);
5276 ProhibitAttributes(attrs);
5279 MaybeParseAttributes(PAKM_GNU | PAKM_Declspec | PAKM_CXX11, attrs);
5288 bool shouldDelayDiagsInTag =
5289 (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation ||
5290 TemplateInfo.Kind == ParsedTemplateInfo::ExplicitSpecialization);
5294 AllowDefiningTypeSpec AllowEnumSpecifier =
5296 bool CanBeOpaqueEnumDeclaration =
5297 DS.
isEmpty() && isOpaqueEnumDeclarationContext(DSC);
5300 (AllowEnumSpecifier == AllowDefiningTypeSpec::Yes ||
5301 CanBeOpaqueEnumDeclaration);
5309 if (ParseOptionalCXXScopeSpecifier(Spec,
nullptr,
5314 if (Spec.
isSet() && Tok.
isNot(tok::identifier)) {
5315 Diag(Tok, diag::err_expected) << tok::identifier;
5317 if (Tok.
isNot(tok::l_brace)) {