30#include "llvm/ADT/SmallSet.h"
31#include "llvm/ADT/SmallString.h"
32#include "llvm/ADT/StringSwitch.h"
49 DeclSpecContext DSC = getDeclSpecContextFromDeclaratorContext(Context);
50 if (DSC == DeclSpecContext::DSC_normal)
51 DSC = DeclSpecContext::DSC_type_specifier;
57 ParseSpecifierQualifierList(DS, AS, DSC);
65 if (AL.isDeclspecAttribute())
66 ToBeMoved.push_back(&AL);
75 ParseDeclarator(DeclaratorInfo);
87 if (Name.size() >= 4 && Name.startswith(
"__") && Name.endswith(
"__"))
88 return Name.drop_front(2).drop_back(2);
95#define CLANG_ATTR_LATE_PARSED_LIST
97#include "clang/Parse/AttrParserStringSwitches.inc"
99#undef CLANG_ATTR_LATE_PARSED_LIST
109 if (
SM.getFileID(StartLoc) !=
SM.getFileID(EndLoc))
112 bool AttrStartIsInMacro =
114 bool AttrEndIsInMacro =
116 return AttrStartIsInMacro && AttrEndIsInMacro;
119void Parser::ParseAttributes(
unsigned WhichAttrKinds,
ParsedAttributes &Attrs,
120 LateParsedAttrList *LateAttrs) {
126 if (WhichAttrKinds & PAKM_CXX11)
127 MoreToParse |= MaybeParseCXX11Attributes(Attrs);
128 if (WhichAttrKinds & PAKM_GNU)
129 MoreToParse |= MaybeParseGNUAttributes(Attrs, LateAttrs);
130 if (WhichAttrKinds & PAKM_Declspec)
131 MoreToParse |= MaybeParseMicrosoftDeclSpecs(Attrs);
132 }
while (MoreToParse);
177 LateParsedAttrList *LateAttrs,
Declarator *D) {
178 assert(Tok.
is(tok::kw___attribute) &&
"Not a GNU attribute list!");
183 while (Tok.
is(tok::kw___attribute)) {
185 unsigned OldNumAttrs = Attrs.
size();
186 unsigned OldNumLateAttrs = LateAttrs ? LateAttrs->size() : 0;
188 if (ExpectAndConsume(tok::l_paren, diag::err_expected_lparen_after,
193 if (ExpectAndConsume(tok::l_paren, diag::err_expected_lparen_after,
"(")) {
206 if (Tok.
is(tok::code_completion)) {
217 if (Tok.
isNot(tok::l_paren)) {
218 Attrs.
addNew(AttrName, AttrNameLoc,
nullptr, AttrNameLoc,
nullptr, 0,
219 ParsedAttr::Form::GNU());
225 ParseGNUAttributeArgs(AttrName, AttrNameLoc, Attrs, &EndLoc,
nullptr,
231 LateParsedAttribute *LA =
232 new LateParsedAttribute(
this, *AttrName, AttrNameLoc);
233 LateAttrs->push_back(LA);
237 if (!ClassStack.empty() && !LateAttrs->parseSoon())
238 getCurrentClass().LateParsedDeclarations.push_back(LA);
242 LA->Toks.push_back(Tok);
245 ConsumeAndStoreUntil(tok::r_paren, LA->Toks,
true);
250 LA->Toks.push_back(Eof);
251 }
while (Tok.
is(tok::comma));
253 if (ExpectAndConsume(tok::r_paren))
256 if (ExpectAndConsume(tok::r_paren))
263 if (!
SM.isWrittenInBuiltinFile(
SM.getSpellingLoc(AttrTokLoc)) &&
266 StringRef FoundName =
270 for (
unsigned i = OldNumAttrs; i < Attrs.
size(); ++i)
271 Attrs[i].setMacroIdentifier(MacroII, ExpansionRange.
getBegin());
274 for (
unsigned i = OldNumLateAttrs; i < LateAttrs->size(); ++i)
275 (*LateAttrs)[i]->MacroII = MacroII;
285#define CLANG_ATTR_IDENTIFIER_ARG_LIST
287#include "clang/Parse/AttrParserStringSwitches.inc"
289#undef CLANG_ATTR_IDENTIFIER_ARG_LIST
295#define CLANG_ATTR_STRING_LITERAL_ARG_LIST
297#include "clang/Parse/AttrParserStringSwitches.inc"
299#undef CLANG_ATTR_STRING_LITERAL_ARG_LIST
304#define CLANG_ATTR_VARIADIC_IDENTIFIER_ARG_LIST
306#include "clang/Parse/AttrParserStringSwitches.inc"
308#undef CLANG_ATTR_VARIADIC_IDENTIFIER_ARG_LIST
313#define CLANG_ATTR_THIS_ISA_IDENTIFIER_ARG_LIST
315#include "clang/Parse/AttrParserStringSwitches.inc"
317#undef CLANG_ATTR_THIS_ISA_IDENTIFIER_ARG_LIST
322#define CLANG_ATTR_ACCEPTS_EXPR_PACK
324#include "clang/Parse/AttrParserStringSwitches.inc"
326#undef CLANG_ATTR_ACCEPTS_EXPR_PACK
331#define CLANG_ATTR_TYPE_ARG_LIST
333#include "clang/Parse/AttrParserStringSwitches.inc"
335#undef CLANG_ATTR_TYPE_ARG_LIST
341#define CLANG_ATTR_ARG_CONTEXT_LIST
343#include "clang/Parse/AttrParserStringSwitches.inc"
345#undef CLANG_ATTR_ARG_CONTEXT_LIST
349 assert(Tok.
is(tok::identifier) &&
"expected an identifier");
364 Parens.consumeOpen();
367 if (Tok.
isNot(tok::r_paren))
370 if (Parens.consumeClose())
378 SourceRange(AttrNameLoc, Parens.getCloseLocation()),
379 ScopeName, ScopeLoc, T.
get(), Form);
382 ScopeName, ScopeLoc,
nullptr, 0, Form);
386Parser::ParseUnevaluatedStringInAttribute(
const IdentifierInfo &AttrName) {
387 if (Tok.
is(tok::l_paren)) {
390 ExprResult Res = ParseUnevaluatedStringInAttribute(AttrName);
391 Paren.consumeClose();
394 if (!isTokenStringLiteral()) {
402bool Parser::ParseAttributeArgumentList(
405 bool SawError =
false;
410 Expr = ParseUnevaluatedStringInAttribute(AttrName);
412 Diag(Tok, diag::warn_cxx98_compat_generalized_initializer_lists);
413 Expr = ParseBraceInitializer();
419 if (Tok.
is(tok::ellipsis))
421 else if (Tok.
is(tok::code_completion)) {
432 if (
Expr.isInvalid()) {
437 Exprs.push_back(
Expr.get());
439 if (Tok.
isNot(tok::comma))
444 checkPotentialAngleBracketDelimiter(Comma);
451 for (
auto &E : Exprs) {
460unsigned Parser::ParseAttributeArgsCommon(
469 bool AttributeHasVariadicIdentifierArg =
473 if (ChangeKWThisToIdent && Tok.
is(tok::kw_this))
477 if (Tok.
is(tok::identifier)) {
479 bool IsIdentifierArg = AttributeHasVariadicIdentifierArg ||
489 IsIdentifierArg = Next.isOneOf(tok::r_paren, tok::comma);
493 ArgExprs.push_back(ParseIdentifierLoc());
497 if (!ArgExprs.empty() ? Tok.
is(tok::comma) : Tok.
isNot(tok::r_paren)) {
499 if (!ArgExprs.empty())
502 if (AttributeIsTypeArgAttr) {
510 TheParsedType = T.
get();
511 }
else if (AttributeHasVariadicIdentifierArg) {
519 if (ChangeKWThisToIdent && Tok.
is(tok::kw_this))
523 if (Tok.
is(tok::identifier)) {
524 ArgExprs.push_back(ParseIdentifierLoc());
539 ArgExprs.push_back(ArgExpr.
get());
551 ExprVector ParsedExprs;
554 if (ParseAttributeArgumentList(*AttrName, ParsedExprs, ArgProperties)) {
560 for (
size_t I = 0; I < ParsedExprs.size(); ++I) {
561 if (!isa<PackExpansionExpr>(ParsedExprs[I]))
566 diag::err_attribute_argument_parm_pack_not_supported)
573 ArgExprs.insert(ArgExprs.end(), ParsedExprs.begin(), ParsedExprs.end());
578 if (!ExpectAndConsume(tok::r_paren)) {
581 if (AttributeIsTypeArgAttr && !TheParsedType.
get().
isNull()) {
583 ScopeName, ScopeLoc, TheParsedType, Form);
586 ArgExprs.data(), ArgExprs.size(), Form);
593 return static_cast<unsigned>(ArgExprs.size() + !TheParsedType.
get().
isNull());
598void Parser::ParseGNUAttributeArgs(
603 assert(Tok.
is(tok::l_paren) &&
"Attribute arg list not starting with '('");
608 if (AttrKind == ParsedAttr::AT_Availability) {
609 ParseAvailabilityAttribute(*AttrName, AttrNameLoc, Attrs, EndLoc, ScopeName,
612 }
else if (AttrKind == ParsedAttr::AT_ExternalSourceSymbol) {
613 ParseExternalSourceSymbolAttribute(*AttrName, AttrNameLoc, Attrs, EndLoc,
614 ScopeName, ScopeLoc, Form);
616 }
else if (AttrKind == ParsedAttr::AT_ObjCBridgeRelated) {
617 ParseObjCBridgeRelatedAttribute(*AttrName, AttrNameLoc, Attrs, EndLoc,
618 ScopeName, ScopeLoc, Form);
620 }
else if (AttrKind == ParsedAttr::AT_SwiftNewType) {
621 ParseSwiftNewTypeAttribute(*AttrName, AttrNameLoc, Attrs, EndLoc, ScopeName,
624 }
else if (AttrKind == ParsedAttr::AT_TypeTagForDatatype) {
625 ParseTypeTagForDatatypeAttribute(*AttrName, AttrNameLoc, Attrs, EndLoc,
626 ScopeName, ScopeLoc, Form);
629 ParseAttributeWithTypeArg(*AttrName, AttrNameLoc, Attrs, ScopeName,
636 std::optional<ParseScope> PrototypeScope;
643 for (
unsigned i = 0; i != FTI.
NumParams; ++i) {
649 ParseAttributeArgsCommon(AttrName, AttrNameLoc, Attrs, EndLoc, ScopeName,
653unsigned Parser::ParseClangAttributeArgs(
657 assert(Tok.
is(tok::l_paren) &&
"Attribute arg list not starting with '('");
664 return ParseAttributeArgsCommon(AttrName, AttrNameLoc, Attrs, EndLoc,
665 ScopeName, ScopeLoc, Form);
666 case ParsedAttr::AT_ExternalSourceSymbol:
667 ParseExternalSourceSymbolAttribute(*AttrName, AttrNameLoc, Attrs, EndLoc,
668 ScopeName, ScopeLoc, Form);
670 case ParsedAttr::AT_Availability:
671 ParseAvailabilityAttribute(*AttrName, AttrNameLoc, Attrs, EndLoc, ScopeName,
674 case ParsedAttr::AT_ObjCBridgeRelated:
675 ParseObjCBridgeRelatedAttribute(*AttrName, AttrNameLoc, Attrs, EndLoc,
676 ScopeName, ScopeLoc, Form);
678 case ParsedAttr::AT_SwiftNewType:
679 ParseSwiftNewTypeAttribute(*AttrName, AttrNameLoc, Attrs, EndLoc, ScopeName,
682 case ParsedAttr::AT_TypeTagForDatatype:
683 ParseTypeTagForDatatypeAttribute(*AttrName, AttrNameLoc, Attrs, EndLoc,
684 ScopeName, ScopeLoc, Form);
687 return !Attrs.
empty() ? Attrs.
begin()->getNumArgs() : 0;
693 unsigned ExistingAttrs = Attrs.
size();
707 if (AttrName->
getName() ==
"property") {
713 T.expectAndConsume(diag::err_expected_lparen_after,
722 bool HasInvalidAccessor =
false;
727 if (!Tok.
is(tok::identifier)) {
729 if (Tok.
is(tok::r_paren) && !HasInvalidAccessor &&
730 AccessorNames[AK_Put] ==
nullptr &&
731 AccessorNames[AK_Get] ==
nullptr) {
732 Diag(AttrNameLoc, diag::err_ms_property_no_getter_or_putter);
743 if (KindStr ==
"get") {
745 }
else if (KindStr ==
"put") {
749 }
else if (KindStr ==
"set") {
750 Diag(KindLoc, diag::err_ms_property_has_set_accessor)
757 Diag(KindLoc, diag::err_ms_property_missing_accessor_kind);
759 HasInvalidAccessor =
true;
760 goto next_property_accessor;
764 Diag(KindLoc, diag::err_ms_property_unknown_accessor);
765 HasInvalidAccessor =
true;
784 if (!Tok.
is(tok::identifier)) {
789 if (Kind == AK_Invalid) {
791 }
else if (AccessorNames[Kind] !=
nullptr) {
793 Diag(KindLoc, diag::err_ms_property_duplicate_accessor) << KindStr;
799 next_property_accessor:
805 if (Tok.
is(tok::r_paren))
808 Diag(Tok.
getLocation(), diag::err_ms_property_expected_comma_or_rparen);
813 if (!HasInvalidAccessor)
815 AccessorNames[AK_Get], AccessorNames[AK_Put],
816 ParsedAttr::Form::Declspec());
818 return !HasInvalidAccessor;
822 ParseAttributeArgsCommon(AttrName, AttrNameLoc, Attrs,
nullptr,
nullptr,
828 Diag(OpenParenLoc, diag::err_attribute_requires_arguments) << AttrName;
841 assert(
getLangOpts().DeclSpecKeyword &&
"__declspec keyword is not enabled");
842 assert(Tok.
is(tok::kw___declspec) &&
"Not a declspec!");
847 while (Tok.
is(tok::kw___declspec)) {
850 if (T.expectAndConsume(diag::err_expected_lparen_after,
"__declspec",
856 while (Tok.
isNot(tok::r_paren)) {
861 if (Tok.
is(tok::code_completion)) {
869 bool IsString = Tok.
getKind() == tok::string_literal;
870 if (!IsString && Tok.
getKind() != tok::identifier &&
871 Tok.
getKind() != tok::kw_restrict) {
872 Diag(Tok, diag::err_ms_declspec_type);
882 StringRef Str = PP.
getSpelling(Tok, StrBuffer, &Invalid);
888 AttrNameLoc = ConsumeStringToken();
894 bool AttrHandled =
false;
897 if (Tok.
is(tok::l_paren))
898 AttrHandled = ParseMicrosoftDeclSpecArgs(AttrName, AttrNameLoc, Attrs);
899 else if (AttrName->
getName() ==
"property")
905 Attrs.
addNew(AttrName, AttrNameLoc,
nullptr, AttrNameLoc,
nullptr, 0,
906 ParsedAttr::Form::Declspec());
909 EndLoc = T.getCloseLocation();
920 case tok::kw___fastcall:
921 case tok::kw___stdcall:
922 case tok::kw___thiscall:
923 case tok::kw___regcall:
924 case tok::kw___cdecl:
925 case tok::kw___vectorcall:
926 case tok::kw___ptr64:
928 case tok::kw___ptr32:
930 case tok::kw___uptr: {
933 attrs.
addNew(AttrName, AttrNameLoc,
nullptr, AttrNameLoc,
nullptr, 0,
944 assert(Tok.
is(tok::kw___funcref));
948 Diag(StartLoc, diag::err_wasm_funcref_not_wasm);
954 attrs.
addNew(AttrName, AttrNameLoc,
nullptr,
959void Parser::DiagnoseAndSkipExtendedMicrosoftTypeAttributes() {
965 Diag(StartLoc, diag::warn_microsoft_qualifiers_ignored) <<
Range;
975 case tok::kw_volatile:
976 case tok::kw___fastcall:
977 case tok::kw___stdcall:
978 case tok::kw___thiscall:
979 case tok::kw___cdecl:
980 case tok::kw___vectorcall:
981 case tok::kw___ptr32:
982 case tok::kw___ptr64:
984 case tok::kw___unaligned:
997 while (Tok.
is(tok::kw___pascal)) {
1000 attrs.
addNew(AttrName, AttrNameLoc,
nullptr, AttrNameLoc,
nullptr, 0,
1007 while (Tok.
is(tok::kw___kernel)) {
1010 attrs.
addNew(AttrName, AttrNameLoc,
nullptr, AttrNameLoc,
nullptr, 0,
1016 while (Tok.
is(tok::kw___noinline__)) {
1019 attrs.
addNew(AttrName, AttrNameLoc,
nullptr, AttrNameLoc,
nullptr, 0,
1020 tok::kw___noinline__);
1027 Attrs.
addNew(AttrName, AttrNameLoc,
nullptr, AttrNameLoc,
nullptr, 0,
1031bool Parser::isHLSLQualifier(
const Token &Tok)
const {
1032 return Tok.
is(tok::kw_groupshared);
1039 Attrs.
addNew(AttrName, AttrNameLoc,
nullptr, AttrNameLoc,
nullptr, 0, Kind);
1047 case tok::kw__Nonnull:
1048 case tok::kw__Nullable:
1049 case tok::kw__Nullable_result:
1050 case tok::kw__Null_unspecified: {
1054 Diag(AttrNameLoc, diag::ext_nullability)
1056 attrs.
addNew(AttrName, AttrNameLoc,
nullptr, AttrNameLoc,
nullptr, 0,
1067 return (Separator ==
'.' || Separator ==
'_');
1078VersionTuple Parser::ParseVersionTuple(
SourceRange &Range) {
1081 if (!Tok.
is(tok::numeric_constant)) {
1082 Diag(Tok, diag::err_expected_version);
1085 return VersionTuple();
1094 const char *ThisTokBegin = &Buffer[0];
1098 unsigned ActualLength = PP.
getSpelling(Tok, ThisTokBegin, &Invalid);
1100 return VersionTuple();
1103 unsigned AfterMajor = 0;
1105 while (AfterMajor < ActualLength &&
isDigit(ThisTokBegin[AfterMajor])) {
1106 Major = Major * 10 + ThisTokBegin[AfterMajor] -
'0';
1110 if (AfterMajor == 0) {
1111 Diag(Tok, diag::err_expected_version);
1114 return VersionTuple();
1117 if (AfterMajor == ActualLength) {
1122 Diag(Tok, diag::err_zero_version);
1123 return VersionTuple();
1126 return VersionTuple(Major);
1129 const char AfterMajorSeparator = ThisTokBegin[AfterMajor];
1131 || (AfterMajor + 1 == ActualLength)) {
1132 Diag(Tok, diag::err_expected_version);
1135 return VersionTuple();
1139 unsigned AfterMinor = AfterMajor + 1;
1141 while (AfterMinor < ActualLength &&
isDigit(ThisTokBegin[AfterMinor])) {
1142 Minor = Minor * 10 + ThisTokBegin[AfterMinor] -
'0';
1146 if (AfterMinor == ActualLength) {
1150 if (Major == 0 && Minor == 0) {
1151 Diag(Tok, diag::err_zero_version);
1152 return VersionTuple();
1155 return VersionTuple(Major, Minor);
1158 const char AfterMinorSeparator = ThisTokBegin[AfterMinor];
1161 Diag(Tok, diag::err_expected_version);
1164 return VersionTuple();
1168 if (AfterMajorSeparator != AfterMinorSeparator)
1169 Diag(Tok, diag::warn_expected_consistent_version_separator);
1172 unsigned AfterSubminor = AfterMinor + 1;
1173 unsigned Subminor = 0;
1174 while (AfterSubminor < ActualLength &&
isDigit(ThisTokBegin[AfterSubminor])) {
1175 Subminor = Subminor * 10 + ThisTokBegin[AfterSubminor] -
'0';
1179 if (AfterSubminor != ActualLength) {
1180 Diag(Tok, diag::err_expected_version);
1183 return VersionTuple();
1186 return VersionTuple(Major, Minor, Subminor);
1214void Parser::ParseAvailabilityAttribute(
1218 enum { Introduced, Deprecated, Obsoleted,
Unknown };
1224 if (T.consumeOpen()) {
1225 Diag(Tok, diag::err_expected) << tok::l_paren;
1230 if (Tok.
isNot(tok::identifier)) {
1231 Diag(Tok, diag::err_availability_expected_platform);
1238 if (Ident->getName() ==
"macosx")
1242 else if (Ident->getName() ==
"macosx_app_extension")
1246 AvailabilityAttr::canonicalizePlatformName(Ident->getName()));
1250 if (ExpectAndConsume(tok::comma)) {
1257 if (!Ident_introduced) {
1271 if (Tok.
isNot(tok::identifier)) {
1272 Diag(Tok, diag::err_availability_expected_change);
1279 if (Keyword == Ident_strict) {
1281 Diag(KeywordLoc, diag::err_availability_redundant)
1284 StrictLoc = KeywordLoc;
1288 if (Keyword == Ident_unavailable) {
1289 if (UnavailableLoc.
isValid()) {
1290 Diag(KeywordLoc, diag::err_availability_redundant)
1293 UnavailableLoc = KeywordLoc;
1297 if (Keyword == Ident_deprecated && Platform->
Ident &&
1300 if (Changes[Deprecated].KeywordLoc.
isValid()) {
1301 Diag(KeywordLoc, diag::err_availability_redundant)
1308 Changes[Deprecated].
Version = VersionTuple(1);
1312 if (Tok.
isNot(tok::equal)) {
1313 Diag(Tok, diag::err_expected_after) << Keyword << tok::equal;
1318 if (Keyword == Ident_message || Keyword == Ident_replacement) {
1319 if (!isTokenStringLiteral()) {
1320 Diag(Tok, diag::err_expected_string_literal)
1325 if (Keyword == Ident_message) {
1336 if ((Keyword == Ident_introduced || Keyword == Ident_deprecated) &&
1337 Tok.
is(tok::identifier)) {
1341 if (Keyword == Ident_introduced)
1342 UnavailableLoc = KeywordLoc;
1348 VersionTuple Version = ParseVersionTuple(VersionRange);
1350 if (Version.empty()) {
1356 if (Keyword == Ident_introduced)
1358 else if (Keyword == Ident_deprecated)
1360 else if (Keyword == Ident_obsoleted)
1366 if (!Changes[Index].KeywordLoc.
isInvalid()) {
1367 Diag(KeywordLoc, diag::err_availability_redundant)
1370 Changes[Index].VersionRange.
getEnd());
1374 Changes[Index].
Version = Version;
1377 Diag(KeywordLoc, diag::err_availability_unknown_change)
1378 << Keyword << VersionRange;
1384 if (T.consumeClose())
1388 *endLoc = T.getCloseLocation();
1392 if (UnavailableLoc.
isValid()) {
1393 bool Complained =
false;
1394 for (
unsigned Index = Introduced; Index !=
Unknown; ++Index) {
1395 if (Changes[Index].KeywordLoc.
isValid()) {
1397 Diag(UnavailableLoc, diag::warn_availability_and_unavailable)
1399 Changes[Index].VersionRange.
getEnd());
1410 attrs.
addNew(&Availability,
1411 SourceRange(AvailabilityLoc, T.getCloseLocation()), ScopeName,
1412 ScopeLoc, Platform, Changes[Introduced], Changes[Deprecated],
1413 Changes[Obsoleted], UnavailableLoc, MessageExpr.
get(), Form,
1414 StrictLoc, ReplacementExpr.
get());
1431void Parser::ParseExternalSourceSymbolAttribute(
1437 if (T.expectAndConsume())
1441 if (!Ident_language) {
1449 bool HasLanguage =
false;
1451 bool HasDefinedIn =
false;
1454 bool HasUSR =
false;
1458 if (Tok.
isNot(tok::identifier)) {
1459 Diag(Tok, diag::err_external_source_symbol_expected_keyword);
1466 if (Keyword == Ident_generated_declaration) {
1467 if (GeneratedDeclaration) {
1468 Diag(Tok, diag::err_external_source_symbol_duplicate_clause) << Keyword;
1472 GeneratedDeclaration = ParseIdentifierLoc();
1476 if (Keyword != Ident_language && Keyword != Ident_defined_in &&
1477 Keyword != Ident_USR) {
1478 Diag(Tok, diag::err_external_source_symbol_expected_keyword);
1484 if (ExpectAndConsume(tok::equal, diag::err_expected_after,
1490 bool HadLanguage = HasLanguage, HadDefinedIn = HasDefinedIn,
1492 if (Keyword == Ident_language)
1494 else if (Keyword == Ident_USR)
1497 HasDefinedIn =
true;
1499 if (!isTokenStringLiteral()) {
1500 Diag(Tok, diag::err_expected_string_literal)
1503 Keyword == Ident_language
1505 : (Keyword == Ident_defined_in ? 1 : 2));
1509 if (Keyword == Ident_language) {
1511 Diag(KeywordLoc, diag::err_external_source_symbol_duplicate_clause)
1517 }
else if (Keyword == Ident_USR) {
1519 Diag(KeywordLoc, diag::err_external_source_symbol_duplicate_clause)
1526 assert(Keyword == Ident_defined_in &&
"Invalid clause keyword!");
1528 Diag(KeywordLoc, diag::err_external_source_symbol_duplicate_clause)
1538 if (T.consumeClose())
1541 *EndLoc = T.getCloseLocation();
1546 ScopeName, ScopeLoc, Args, std::size(Args), Form);
1560void Parser::ParseObjCBridgeRelatedAttribute(
1566 if (T.consumeOpen()) {
1567 Diag(Tok, diag::err_expected) << tok::l_paren;
1572 if (Tok.
isNot(tok::identifier)) {
1573 Diag(Tok, diag::err_objcbridge_related_expected_related_class);
1578 if (ExpectAndConsume(tok::comma)) {
1587 if (Tok.
is(tok::identifier)) {
1590 Diag(Tok, diag::err_objcbridge_related_selector_name);
1596 if (Tok.
is(tok::colon))
1597 Diag(Tok, diag::err_objcbridge_related_selector_name);
1599 Diag(Tok, diag::err_expected) << tok::comma;
1607 if (Tok.
is(tok::identifier))
1609 else if (Tok.
isNot(tok::r_paren)) {
1610 Diag(Tok, diag::err_expected) << tok::r_paren;
1616 if (T.consumeClose())
1620 *EndLoc = T.getCloseLocation();
1623 Attrs.
addNew(&ObjCBridgeRelated,
1624 SourceRange(ObjCBridgeRelatedLoc, T.getCloseLocation()),
1625 ScopeName, ScopeLoc, RelatedClass, ClassMethod, InstanceMethod,
1629void Parser::ParseSwiftNewTypeAttribute(
1636 if (T.consumeOpen()) {
1637 Diag(Tok, diag::err_expected) << tok::l_paren;
1641 if (Tok.
is(tok::r_paren)) {
1646 if (Tok.
isNot(tok::kw_struct) && Tok.
isNot(tok::kw_enum)) {
1647 Diag(Tok, diag::warn_attribute_type_not_supported)
1649 if (!isTokenSpecial())
1660 if (T.consumeClose())
1663 *EndLoc = T.getCloseLocation();
1667 ScopeName, ScopeLoc, Args, std::size(Args), Form);
1670void Parser::ParseTypeTagForDatatypeAttribute(
1674 assert(Tok.
is(tok::l_paren) &&
"Attribute arg list not starting with '('");
1679 if (Tok.
isNot(tok::identifier)) {
1680 Diag(Tok, diag::err_expected) << tok::identifier;
1686 if (ExpectAndConsume(tok::comma)) {
1698 bool LayoutCompatible =
false;
1699 bool MustBeNull =
false;
1701 if (Tok.
isNot(tok::identifier)) {
1702 Diag(Tok, diag::err_expected) << tok::identifier;
1707 if (Flag->
isStr(
"layout_compatible"))
1708 LayoutCompatible =
true;
1709 else if (Flag->
isStr(
"must_be_null"))
1712 Diag(Tok, diag::err_type_safety_unknown_flag) << Flag;
1719 if (!T.consumeClose()) {
1721 ArgumentKind, MatchingCType.
get(),
1722 LayoutCompatible, MustBeNull, Form);
1726 *EndLoc = T.getCloseLocation();
1737bool Parser::DiagnoseProhibitedCXX11Attribute() {
1738 assert(Tok.
is(tok::l_square) &&
NextToken().is(tok::l_square));
1740 switch (isCXX11AttributeSpecifier(
true)) {
1741 case CAK_NotAttributeSpecifier:
1745 case CAK_InvalidAttributeSpecifier:
1749 case CAK_AttributeSpecifier:
1754 assert(Tok.
is(tok::r_square) &&
"isCXX11AttributeSpecifier lied");
1756 Diag(BeginLoc, diag::err_attributes_not_allowed)
1760 llvm_unreachable(
"All cases handled above.");
1769 assert((Tok.
is(tok::l_square) &&
NextToken().is(tok::l_square)) ||
1776 ParseCXX11Attributes(Attrs);
1779 (Keyword ?
Diag(Loc, diag::err_keyword_not_allowed) << Keyword
1780 :
Diag(Loc, diag::err_attributes_not_allowed))
1785void Parser::DiagnoseProhibitedAttributes(
1787 auto *FirstAttr = Attrs.
empty() ? nullptr : &Attrs.
front();
1788 if (CorrectLocation.
isValid()) {
1790 (FirstAttr && FirstAttr->isRegularKeywordAttribute()
1791 ?
Diag(CorrectLocation, diag::err_keyword_misplaced) << FirstAttr
1792 :
Diag(CorrectLocation, diag::err_attributes_misplaced))
1797 (FirstAttr && FirstAttr->isRegularKeywordAttribute()
1798 ?
Diag(
Range.getBegin(), diag::err_keyword_not_allowed) << FirstAttr
1799 :
Diag(
Range.getBegin(), diag::err_attributes_not_allowed))
1805 unsigned AttrDiagID,
1806 unsigned KeywordDiagID,
1807 bool DiagnoseEmptyAttrs,
1808 bool WarnOnUnknownAttrs) {
1818 if (FirstLSquare.
is(tok::l_square)) {
1819 std::optional<Token> SecondLSquare =
1822 if (SecondLSquare && SecondLSquare->is(tok::l_square)) {
1833 if (AL.isRegularKeywordAttribute()) {
1834 Diag(AL.getLoc(), KeywordDiagID) << AL;
1838 if (!AL.isStandardAttributeSyntax())
1841 if (WarnOnUnknownAttrs)
1842 Diag(AL.getLoc(), diag::warn_unknown_attribute_ignored)
1843 << AL << AL.getRange();
1845 Diag(AL.getLoc(), AttrDiagID) << AL;
1853 if (PA.isStandardAttributeSyntax() || PA.isRegularKeywordAttribute())
1854 Diag(PA.getLoc(), diag::ext_cxx11_attr_placement)
1855 << PA << PA.isRegularKeywordAttribute() << PA.getRange();
1875 if ((AL.getKind() == ParsedAttr::AT_Aligned &&
1876 AL.isDeclspecAttribute()) ||
1877 AL.isMicrosoftAttribute())
1878 ToBeMoved.push_back(&AL);
1913 Decl *SingleDecl =
nullptr;
1915 case tok::kw_template:
1916 case tok::kw_export:
1917 ProhibitAttributes(DeclAttrs);
1918 ProhibitAttributes(DeclSpecAttrs);
1920 ParseDeclarationStartingWithTemplate(Context, DeclEnd, DeclAttrs);
1922 case tok::kw_inline:
1925 ProhibitAttributes(DeclAttrs);
1926 ProhibitAttributes(DeclSpecAttrs);
1928 return ParseNamespace(Context, DeclEnd, InlineLoc);
1930 return ParseSimpleDeclaration(Context, DeclEnd, DeclAttrs, DeclSpecAttrs,
1931 true,
nullptr, DeclSpecStart);
1933 case tok::kw_cbuffer:
1934 case tok::kw_tbuffer:
1935 SingleDecl = ParseHLSLBuffer(DeclEnd);
1937 case tok::kw_namespace:
1938 ProhibitAttributes(DeclAttrs);
1939 ProhibitAttributes(DeclSpecAttrs);
1940 return ParseNamespace(Context, DeclEnd);
1941 case tok::kw_using: {
1944 return ParseUsingDirectiveOrDeclaration(Context, ParsedTemplateInfo(),
1947 case tok::kw_static_assert:
1948 case tok::kw__Static_assert:
1949 ProhibitAttributes(DeclAttrs);
1950 ProhibitAttributes(DeclSpecAttrs);
1951 SingleDecl = ParseStaticAssertDeclaration(DeclEnd);
1954 return ParseSimpleDeclaration(Context, DeclEnd, DeclAttrs, DeclSpecAttrs,
1955 true,
nullptr, DeclSpecStart);
1987 bool RequireSemi, ForRangeInit *FRI,
SourceLocation *DeclSpecStart) {
1990 OriginalDeclSpecAttrs.
addAll(DeclSpecAttrs.
begin(), DeclSpecAttrs.
end());
1991 OriginalDeclSpecAttrs.
Range = DeclSpecAttrs.
Range;
1997 DeclSpecContext DSContext = getDeclSpecContextFromDeclaratorContext(Context);
1998 ParseDeclarationSpecifiers(DS, ParsedTemplateInfo(),
AS_none, DSContext);
2003 DiagnoseMissingSemiAfterTagDefinition(DS,
AS_none, DSContext))
2008 if (Tok.
is(tok::semi)) {
2009 ProhibitAttributes(DeclAttrs);
2016 DS.complete(TheDecl);
2018 Decl* decls[] = {AnonRecord, TheDecl};
2030 return ParseDeclGroup(DS, Context, DeclAttrs, &DeclEnd, FRI);
2037 case tok::annot_cxxscope:
2038 case tok::annot_template_id:
2040 case tok::code_completion:
2041 case tok::coloncolon:
2043 case tok::kw___attribute:
2044 case tok::kw_operator:
2060 case tok::identifier:
2062 case tok::code_completion:
2063 case tok::coloncolon:
2066 case tok::equalequal:
2067 case tok::kw_alignas:
2069 case tok::kw___attribute:
2087 case tok::identifier:
2110 if (Tok.
isOneOf(tok::comma, tok::l_brace, tok::kw_try)) {
2134 case tok::kw_inline:
2139 (!ParsingInObjCContainer || CurParsedObjCImpl))
2143 case tok::kw_namespace:
2148 (!ParsingInObjCContainer || CurParsedObjCImpl))
2154 if (
NextToken().isObjCAtKeyword(tok::objc_end) &&
2155 ParsingInObjCContainer)
2167 case tok::annot_module_begin:
2168 case tok::annot_module_end:
2169 case tok::annot_module_include:
2170 case tok::annot_repl_input_end:
2188 ForRangeInit *FRI) {
2194 LocalAttrs.takeAllFrom(Attrs);
2205 MaybeParseHLSLSemantics(D);
2207 if (Tok.
is(tok::kw_requires))
2208 ParseTrailingRequiresClause(D);
2213 LateParsedAttrList LateParsedAttrs(
true);
2215 MaybeParseGNUAttributes(D, &LateParsedAttrs);
2220 if (Tok.
is(tok::kw__Noreturn)) {
2222 const char *PrevSpec;
2228 MaybeParseGNUAttributes(D, &LateParsedAttrs);
2229 Fixit &= Tok.
isOneOf(tok::semi, tok::l_brace, tok::kw_try);
2231 Diag(Loc, diag::err_c11_noreturn_misplaced)
2233 << (Fixit ?
FixItHint::CreateInsertion(D.getBeginLoc(),
"_Noreturn ")
2238 if (Tok.
is(tok::equal) &&
NextToken().is(tok::code_completion)) {
2249 while (
auto Specifier = isCXX11VirtSpecifier()) {
2250 Diag(Tok, diag::err_virt_specifier_outside_class)
2258 if (!isDeclarationAfterDeclarator()) {
2264 if (isStartOfFunctionDefinition(D)) {
2266 Diag(Tok, diag::err_function_declared_typedef);
2272 Decl *TheDecl = ParseFunctionDefinition(D, ParsedTemplateInfo(),
2278 Tok.
is(tok::kw_namespace)) {
2288 Diag(Tok, diag::err_expected_fn_body);
2293 if (Tok.
is(tok::l_brace)) {
2294 Diag(Tok, diag::err_function_definition_not_allowed);
2302 if (ParseAsmAttributesAfterDeclarator(D))
2311 if (FRI && (Tok.
is(tok::colon) || isTokIdentifier_in())) {
2312 bool IsForRangeLoop =
false;
2314 IsForRangeLoop =
true;
2317 if (Tok.
is(tok::l_brace))
2318 FRI->RangeExpr = ParseBraceInitializer();
2324 if (IsForRangeLoop) {
2328 if (
auto *VD = dyn_cast_or_null<VarDecl>(ThisDecl))
2329 VD->setObjCForDecl(
true);
2332 D.complete(ThisDecl);
2337 Decl *FirstDecl = ParseDeclarationAfterDeclaratorAndAttributes(
2338 D, ParsedTemplateInfo(), FRI);
2339 if (LateParsedAttrs.size() > 0)
2340 ParseLexedAttributeList(LateParsedAttrs, FirstDecl,
true,
false);
2341 D.complete(FirstDecl);
2343 DeclsInGroup.push_back(FirstDecl);
2351 if (Tok.
isAtStartOfLine() && ExpectSemi && !MightBeDeclarator(Context)) {
2355 Diag(CommaLoc, diag::err_expected_semi_declaration)
2372 MaybeParseGNUAttributes(D);
2376 DiagnoseAndSkipExtendedMicrosoftTypeAttributes();
2381 MaybeParseHLSLSemantics(D);
2388 if (Tok.
is(tok::kw_requires))
2389 ParseTrailingRequiresClause(D);
2390 Decl *ThisDecl = ParseDeclarationAfterDeclarator(D);
2391 D.complete(ThisDecl);
2393 DeclsInGroup.push_back(ThisDecl);
2400 if (ExpectSemi && ExpectAndConsumeSemi(
2402 ? diag::err_invalid_token_after_toplevel_declarator
2403 : diag::err_expected_semi_declaration)) {
2416bool Parser::ParseAsmAttributesAfterDeclarator(
Declarator &D) {
2418 if (Tok.
is(tok::kw_asm)) {
2420 ExprResult AsmLabel(ParseSimpleAsm(
true, &Loc));
2421 if (AsmLabel.isInvalid()) {
2430 MaybeParseGNUAttributes(D);
2456Decl *Parser::ParseDeclarationAfterDeclarator(
2457 Declarator &D,
const ParsedTemplateInfo &TemplateInfo) {
2458 if (ParseAsmAttributesAfterDeclarator(D))
2461 return ParseDeclarationAfterDeclaratorAndAttributes(D, TemplateInfo);
2464Decl *Parser::ParseDeclarationAfterDeclaratorAndAttributes(
2465 Declarator &D,
const ParsedTemplateInfo &TemplateInfo, ForRangeInit *FRI) {
2467 struct InitializerScopeRAII {
2473 :
P(
P), D(D), ThisDecl(ThisDecl) {
2474 if (ThisDecl &&
P.getLangOpts().CPlusPlus) {
2478 S =
P.getCurScope();
2480 P.Actions.ActOnCXXEnterDeclInitializer(S, ThisDecl);
2483 ~InitializerScopeRAII() { pop(); }
2485 if (ThisDecl &&
P.getLangOpts().CPlusPlus) {
2488 S =
P.getCurScope();
2489 P.Actions.ActOnCXXExitDeclInitializer(S, ThisDecl);
2498 InitKind TheInitKind;
2500 if (isTokenEqualOrEqualTypo())
2501 TheInitKind = InitKind::Equal;
2502 else if (Tok.
is(tok::l_paren))
2503 TheInitKind = InitKind::CXXDirect;
2506 TheInitKind = InitKind::CXXBraced;
2508 TheInitKind = InitKind::Uninitialized;
2509 if (TheInitKind != InitKind::Uninitialized)
2513 Decl *ThisDecl =
nullptr;
2514 Decl *OuterDecl =
nullptr;
2515 switch (TemplateInfo.Kind) {
2516 case ParsedTemplateInfo::NonTemplate:
2520 case ParsedTemplateInfo::Template:
2521 case ParsedTemplateInfo::ExplicitSpecialization: {
2523 *TemplateInfo.TemplateParams,
2525 if (
VarTemplateDecl *VT = dyn_cast_or_null<VarTemplateDecl>(ThisDecl)) {
2528 ThisDecl = VT->getTemplatedDecl();
2533 case ParsedTemplateInfo::ExplicitInstantiation: {
2534 if (Tok.
is(tok::semi)) {
2536 getCurScope(), TemplateInfo.ExternLoc, TemplateInfo.TemplateLoc, D);
2541 ThisDecl = ThisRes.
get();
2549 Diag(Tok, diag::err_template_defn_explicit_instantiation)
2556 diag::err_explicit_instantiation_with_definition)
2564 std::nullopt, LAngleLoc,
nullptr));
2575 switch (TheInitKind) {
2577 case InitKind::Equal: {
2580 if (Tok.
is(tok::kw_delete)) {
2586 }
else if (Tok.
is(tok::kw_default)) {
2594 InitializerScopeRAII InitScope(*
this, D, ThisDecl);
2596 if (Tok.
is(tok::code_completion)) {
2609 Diag(EqualLoc, diag::err_single_decl_assign_in_for_range)
2613 FRI->ColonLoc = EqualLoc;
2615 FRI->RangeExpr = Init;
2620 if (Init.isInvalid()) {
2622 StopTokens.push_back(tok::comma);
2625 StopTokens.push_back(tok::r_paren);
2634 case InitKind::CXXDirect: {
2641 InitializerScopeRAII InitScope(*
this, D, ThisDecl);
2643 auto ThisVarDecl = dyn_cast_or_null<VarDecl>(ThisDecl);
2644 auto RunSignatureHelp = [&]() {
2646 ThisVarDecl->getType()->getCanonicalTypeInternal(),
2647 ThisDecl->
getLocation(), Exprs, T.getOpenLocation(),
2649 CalledSignatureHelp =
true;
2650 return PreferredType;
2652 auto SetPreferredType = [&] {
2653 PreferredType.enterFunctionArgument(Tok.
getLocation(), RunSignatureHelp);
2656 llvm::function_ref<void()> ExpressionStarts;
2662 ExpressionStarts = SetPreferredType;
2664 if (ParseExpressionList(Exprs, ExpressionStarts)) {
2667 ThisVarDecl->getType()->getCanonicalTypeInternal(),
2668 ThisDecl->
getLocation(), Exprs, T.getOpenLocation(),
2670 CalledSignatureHelp =
true;
2680 T.getCloseLocation(),
2687 case InitKind::CXXBraced: {
2689 Diag(Tok, diag::warn_cxx98_compat_generalized_initializer_lists);
2691 InitializerScopeRAII InitScope(*
this, D, ThisDecl);
2693 PreferredType.enterVariableInit(Tok.
getLocation(), ThisDecl);
2698 if (Init.isInvalid()) {
2704 case InitKind::Uninitialized: {
2711 return OuterDecl ? OuterDecl : ThisDecl;
2720void Parser::ParseSpecifierQualifierList(
2726 ParseDeclarationSpecifiers(DS, ParsedTemplateInfo(), AS, DSC,
nullptr,
2727 AllowImplicitTypename);
2732 Diag(Tok, diag::err_expected_type);
2735 Diag(Tok, diag::err_typename_requires_specqual);
2746 diag::err_typename_invalid_storageclass);
2790 return T.
isOneOf(tok::l_square, tok::l_paren, tok::r_paren, tok::semi,
2791 tok::comma, tok::equal, tok::kw_asm, tok::l_brace,
2805 const ParsedTemplateInfo &TemplateInfo,
2808 assert(Tok.
is(tok::identifier) &&
"should have identifier");
2830 if (!isTypeSpecifier(DSC) &&
getLangOpts().isImplicitIntAllowed() &&
2848 AnnotateScopeToken(*SS,
false);
2859 DSC == DeclSpecContext::DSC_template_type_arg)) {
2860 const char *PrevSpec;
2876 if (SS ==
nullptr) {
2877 const char *TagName =
nullptr, *FixitTagName =
nullptr;
2883 TagName=
"enum" ; FixitTagName =
"enum " ; TagKind=tok::kw_enum ;
break;
2885 TagName=
"union" ; FixitTagName =
"union " ;TagKind=tok::kw_union ;
break;
2887 TagName=
"struct"; FixitTagName =
"struct ";TagKind=tok::kw_struct;
break;
2889 TagName=
"__interface"; FixitTagName =
"__interface ";
2890 TagKind=tok::kw___interface;
break;
2892 TagName=
"class" ; FixitTagName =
"class " ;TagKind=tok::kw_class ;
break;
2900 Diag(Loc, diag::err_use_of_tag_name_without_tag)
2901 << TokenName << TagName <<
getLangOpts().CPlusPlus
2907 Diag((*I)->getLocation(), diag::note_decl_hiding_tag_type)
2908 << TokenName << TagName;
2912 if (TagKind == tok::kw_enum)
2913 ParseEnumSpecifier(Loc, DS, TemplateInfo, AS,
2914 DeclSpecContext::DSC_normal);
2916 ParseClassSpecifier(TagKind, Loc, DS, TemplateInfo, AS,
2918 DeclSpecContext::DSC_normal, Attrs);
2925 if (!isTypeSpecifier(DSC) && (!SS || DSC == DeclSpecContext::DSC_top_level ||
2926 DSC == DeclSpecContext::DSC_class)) {
2930 case tok::l_paren: {
2937 TentativeParsingAction PA(*
this);
2939 TPResult TPR = TryParseDeclarator(
false);
2942 if (TPR != TPResult::False) {
2950 if (DSC == DeclSpecContext::DSC_class ||
2951 (DSC == DeclSpecContext::DSC_top_level && SS)) {
2954 Diag(Loc, diag::err_constructor_bad_name)
2975 AnnotateScopeToken(*SS,
false);
2997 const char *PrevSpec;
3018 if (IsTemplateName) {
3020 TemplateArgList Args;
3021 ParseTemplateIdAfterTemplateName(
true, LAngle, Args, RAngle);
3035Parser::DeclSpecContext
3039 return DeclSpecContext::DSC_class;
3041 return DeclSpecContext::DSC_top_level;
3043 return DeclSpecContext::DSC_template_param;
3045 return DeclSpecContext::DSC_template_arg;
3047 return DeclSpecContext::DSC_template_type_arg;
3050 return DeclSpecContext::DSC_trailing;
3053 return DeclSpecContext::DSC_alias_declaration;
3055 return DeclSpecContext::DSC_association;
3057 return DeclSpecContext::DSC_type_specifier;
3059 return DeclSpecContext::DSC_condition;
3061 return DeclSpecContext::DSC_conv_operator;
3063 return DeclSpecContext::DSC_new;
3078 return DeclSpecContext::DSC_normal;
3081 llvm_unreachable(
"Missing DeclaratorContext case");
3094 if (isTypeIdInParens()) {
3123 assert(Tok.
isOneOf(tok::kw_alignas, tok::kw__Alignas) &&
3124 "Not an alignment-specifier!");
3131 if (T.expectAndConsume())
3138 ParseAlignArgument(PP.
getSpelling(KWTok), T.getOpenLocation(),
3147 *EndLoc = T.getCloseLocation();
3154 ArgExprs.push_back(ArgExpr.
get());
3155 Attrs.
addNew(KWName, KWLoc,
nullptr, KWLoc, ArgExprs.data(), 1, Kind,
3160ExprResult Parser::ParseExtIntegerArgument() {
3161 assert(Tok.
isOneOf(tok::kw__ExtInt, tok::kw__BitInt) &&
3162 "Not an extended int type");
3166 if (T.expectAndConsume())
3175 if(T.consumeClose())
3189 DeclSpecContext DSContext,
3190 LateParsedAttrList *LateAttrs) {
3193 bool EnteringContext = (DSContext == DeclSpecContext::DSC_class ||
3194 DSContext == DeclSpecContext::DSC_top_level);
3197 Tok.
isOneOf(tok::identifier, tok::coloncolon, tok::kw_decltype,
3198 tok::annot_template_id) &&
3204 bool HasScope = Tok.
is(tok::annot_cxxscope);
3210 bool MightBeDeclarator =
true;
3211 if (Tok.
isOneOf(tok::kw_typename, tok::annot_typename)) {
3213 MightBeDeclarator =
false;
3214 }
else if (AfterScope.
is(tok::annot_template_id)) {
3220 MightBeDeclarator =
false;
3221 }
else if (AfterScope.
is(tok::identifier)) {
3222 const Token &Next = HasScope ? GetLookAheadToken(2) :
NextToken();
3226 if (Next.isOneOf(tok::star, tok::amp, tok::ampamp, tok::identifier,
3227 tok::annot_cxxscope, tok::coloncolon)) {
3229 MightBeDeclarator =
false;
3230 }
else if (HasScope) {
3241 switch (Classification.
getKind()) {
3247 llvm_unreachable(
"typo correction is not possible here");
3254 MightBeDeclarator =
false;
3270 if (MightBeDeclarator)
3275 diag::err_expected_after)
3286 ParsedTemplateInfo NotATemplate;
3287 ParseDeclarationSpecifiers(DS, NotATemplate, AS, DSContext, LateAttrs);
3294 const char *&PrevSpec,
unsigned &DiagID,
3296 assert(!LangOpts.FixedPoint);
3297 DiagID = diag::err_fixed_point_not_enabled;
3329void Parser::ParseDeclarationSpecifiers(
3331 DeclSpecContext DSContext, LateParsedAttrList *LateAttrs,
3343 if (DSContext == DeclSpecContext::DSC_conv_operator) {
3346 DSContext = DeclSpecContext::DSC_type_specifier;
3349 bool EnteringContext = (DSContext == DeclSpecContext::DSC_class ||
3350 DSContext == DeclSpecContext::DSC_top_level);
3351 bool AttrsLastTime =
false;
3357 bool isStorageClass =
false;
3358 const char *PrevSpec =
nullptr;
3359 unsigned DiagID = 0;
3380 auto handleOpenCLImageKW = [&] (StringRef Ext,
TypeSpecifierType ImageTypeSpec) {
3394 bool IsTemplateSpecOrInst =
3395 (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation ||
3396 TemplateInfo.Kind == ParsedTemplateInfo::ExplicitSpecialization);
3405 ProhibitAttributes(attrs);
3409 if (!PA.isCXX11Attribute() && !PA.isC23Attribute() &&
3410 !PA.isRegularKeywordAttribute())
3418 if (PA.getKind() == ParsedAttr::AT_VectorSize) {
3419 Diag(PA.getLoc(), diag::warn_attribute_ignored) << PA;
3426 if (PA.isTypeAttr() && PA.getKind() != ParsedAttr::AT_LifetimeBound &&
3427 PA.getKind() != ParsedAttr::AT_AnyX86NoCfCheck)
3429 Diag(PA.getLoc(), diag::err_attribute_not_type_attr)
3430 << PA << PA.isRegularKeywordAttribute();
3439 DS.
Finish(Actions, Policy);
3443 case tok::kw_alignas:
3444 if (!isAllowedCXX11AttributeSpecifier())
3445 goto DoneWithDeclSpec;
3448 ProhibitAttributes(attrs);
3455 ParseCXX11Attributes(attrs);
3456 AttrsLastTime =
true;
3459 case tok::code_completion: {
3462 bool AllowNonIdentifiers
3468 bool AllowNestedNameSpecifiers
3469 = DSContext == DeclSpecContext::DSC_top_level ||
3474 AllowNonIdentifiers,
3475 AllowNestedNameSpecifiers);
3480 if (TemplateInfo.Kind != ParsedTemplateInfo::NonTemplate)
3483 else if (DSContext == DeclSpecContext::DSC_class)
3487 else if (CurParsedObjCImpl)
3495 case tok::coloncolon:
3500 goto DoneWithDeclSpec;
3502 if (Tok.
is(tok::coloncolon))
3503 goto DoneWithDeclSpec;
3506 case tok::annot_cxxscope: {
3508 goto DoneWithDeclSpec;
3511 if (TemplateInfo.TemplateParams)
3521 ? takeTemplateIdAnnotation(Next)
3527 ConsumeAnnotationToken();
3541 if ((DSContext == DeclSpecContext::DSC_top_level ||
3542 DSContext == DeclSpecContext::DSC_class) &&
3545 isConstructorDeclarator(
false,
3552 goto DoneWithDeclSpec;
3556 ConsumeAnnotationToken();
3557 assert(Tok.
is(tok::annot_template_id) &&
3558 "ParseOptionalCXXScopeSpecifier not working");
3559 AnnotateTemplateIdTokenAsType(SS, AllowImplicitTypename);
3569 ConsumeAnnotationToken();
3573 if (Next.is(tok::annot_typename)) {
3575 ConsumeAnnotationToken();
3579 PrevSpec, DiagID, T, Policy);
3583 ConsumeAnnotationToken();
3587 Next.is(tok::annot_template_id) &&
3591 ConsumeAnnotationToken();
3592 AnnotateTemplateIdTokenAsType(SS, AllowImplicitTypename);
3596 if (Next.isNot(tok::identifier))
3597 goto DoneWithDeclSpec;
3602 if ((DSContext == DeclSpecContext::DSC_top_level ||
3603 DSContext == DeclSpecContext::DSC_class) &&
3606 isConstructorDeclarator(
false,
3610 goto DoneWithDeclSpec;
3619 *Next.getIdentifierInfo(), Next.getLocation(),
getCurScope(), &SS,
3620 false,
false,
nullptr,
3623 isClassTemplateDeductionContext(DSContext), AllowImplicitTypename);
3625 if (IsTemplateSpecOrInst)
3633 if (TryAnnotateTypeConstraint())
3634 goto DoneWithDeclSpec;
3635 if (Tok.
isNot(tok::annot_cxxscope) ||
3639 ConsumeAnnotationToken();
3641 if (ParseImplicitInt(DS, &SS, TemplateInfo, AS, DSContext, Attrs)) {
3642 if (!Attrs.
empty()) {
3643 AttrsLastTime =
true;
3644 attrs.takeAllFrom(Attrs);
3648 goto DoneWithDeclSpec;
3652 ConsumeAnnotationToken();
3655 DiagID, TypeRep, Policy);
3665 case tok::annot_typename: {
3669 goto DoneWithDeclSpec;
3678 ConsumeAnnotationToken();
3683 case tok::kw___is_signed:
3694 TryKeywordIdentFallback(
true);
3697 goto DoneWithDeclSpec;
3700 case tok::kw___super:
3701 case tok::kw_decltype:
3702 case tok::identifier:
3708 goto DoneWithDeclSpec;
3714 if (!
getLangOpts().DeclSpecKeyword && Tok.
is(tok::identifier) &&
3716 Diag(Loc, diag::err_ms_attributes_not_enabled);
3726 if (T.consumeOpen()) {
3727 assert(
false &&
"Not a left paren?");
3746 if (IsTemplateSpecOrInst)
3750 if (IsTemplateSpecOrInst)
3753 goto DoneWithDeclSpec;
3756 if (!Tok.
is(tok::identifier))
3761 if (TryAltiVecToken(DS, Loc, PrevSpec, DiagID,
isInvalid))
3767 goto DoneWithDeclSpec;
3769 if (DSContext == DeclSpecContext::DSC_objc_method_result &&
3770 isObjCInstancetype()) {
3774 DiagID, TypeRep, Policy);
3787 isConstructorDeclarator(
true,
3790 goto DoneWithDeclSpec;
3794 false,
false,
nullptr,
false,
false,
3795 isClassTemplateDeductionContext(DSContext));
3800 if (TryAnnotateTypeConstraint())
3801 goto DoneWithDeclSpec;
3802 if (Tok.
isNot(tok::identifier))
3805 if (ParseImplicitInt(DS,
nullptr, TemplateInfo, AS, DSContext, Attrs)) {
3806 if (!Attrs.
empty()) {
3807 AttrsLastTime =
true;
3808 attrs.takeAllFrom(Attrs);
3812 goto DoneWithDeclSpec;
3819 (DSContext == DeclSpecContext::DSC_class ||
3820 DSContext == DeclSpecContext::DSC_top_level) &&
3823 isConstructorDeclarator(
true,
3825 goto DoneWithDeclSpec;
3828 DiagID, TypeRep, Policy);
3840 TypeResult NewTypeRep = parseObjCTypeArgsAndProtocolQualifiers(
3855 case tok::annot_template_id: {
3867 TemplateId =
nullptr;
3875 tok::kw_volatile, tok::kw_restrict, tok::amp,
3877 Diag(Loc, diag::err_placeholder_expected_auto_or_decltype_auto)
3881 TemplateId, Policy);
3885 goto DoneWithDeclSpec;
3888 TemplateId =
nullptr;
3890 ConsumeAnnotationToken();
3894 if (Tracker.consumeOpen()) {
3896 Diag(Tok, diag::err_expected) << tok::l_paren;
3900 Tracker.skipToEnd();
3901 Diag(Tok, diag::err_placeholder_expected_auto_or_decltype_auto)
3906 Tracker.consumeClose();
3914 DiagID, TemplateId, Policy);
3917 TemplateId, Policy);
3926 goto DoneWithDeclSpec;
3934 isConstructorDeclarator(
true,
3937 goto DoneWithDeclSpec;
3942 AnnotateTemplateIdTokenAsType(SS, AllowImplicitTypename);
3947 case tok::kw___attribute:
3948 case tok::kw___declspec:
3949 ParseAttributes(PAKM_GNU | PAKM_Declspec, DS.
getAttributes(), LateAttrs);
3953 case tok::kw___forceinline: {
3958 nullptr, 0, tok::kw___forceinline);
3962 case tok::kw___unaligned:
3967 case tok::kw___sptr:
3968 case tok::kw___uptr:
3969 case tok::kw___ptr64:
3970 case tok::kw___ptr32:
3972 case tok::kw___cdecl:
3973 case tok::kw___stdcall:
3974 case tok::kw___fastcall:
3975 case tok::kw___thiscall:
3976 case tok::kw___regcall:
3977 case tok::kw___vectorcall:
3981 case tok::kw___funcref:
3986 case tok::kw___pascal:
3991 case tok::kw___kernel:
3996 case tok::kw___noinline__:
4001 case tok::kw__Nonnull:
4002 case tok::kw__Nullable:
4003 case tok::kw__Nullable_result:
4004 case tok::kw__Null_unspecified:
4009 case tok::kw___kindof:
4011 nullptr, 0, tok::kw___kindof);
4016 case tok::kw_typedef:
4018 PrevSpec, DiagID, Policy);
4019 isStorageClass =
true;
4021 case tok::kw_extern:
4023 Diag(Tok, diag::ext_thread_before) <<
"extern";
4025 PrevSpec, DiagID, Policy);
4026 isStorageClass =
true;
4028 case tok::kw___private_extern__:
4030 Loc, PrevSpec, DiagID, Policy);
4031 isStorageClass =
true;
4033 case tok::kw_static:
4035 Diag(Tok, diag::ext_thread_before) <<
"static";
4037 PrevSpec, DiagID, Policy);
4038 isStorageClass =
true;
4042 if (isKnownToBeTypeSpecifier(GetLookAheadToken(1))) {
4044 PrevSpec, DiagID, Policy);
4046 Diag(Tok, diag::ext_auto_storage_class)
4053 PrevSpec, DiagID, Policy);
4054 isStorageClass =
true;
4056 case tok::kw___auto_type:
4057 Diag(Tok, diag::ext_auto_type);
4061 case tok::kw_register:
4063 PrevSpec, DiagID, Policy);
4064 isStorageClass =
true;
4066 case tok::kw_mutable:
4068 PrevSpec, DiagID, Policy);
4069 isStorageClass =
true;
4071 case tok::kw___thread:
4074 isStorageClass =
true;
4076 case tok::kw_thread_local:
4078 Diag(Tok, diag::warn_c23_compat_keyword) << Tok.
getName();
4081 isStorageClass =
true;
4083 case tok::kw__Thread_local:
4085 Diag(Tok, diag::ext_c11_feature) << Tok.
getName();
4087 Loc, PrevSpec, DiagID);
4088 isStorageClass =
true;
4092 case tok::kw_inline:
4095 case tok::kw_virtual:
4099 !
getActions().getOpenCLOptions().isAvailableOption(
4101 DiagID = diag::err_openclcxx_virtual_function;
4108 case tok::kw_explicit: {
4112 ConsumedEnd = ExplicitLoc;
4114 if (Tok.
is(tok::l_paren)) {
4117 ? diag::warn_cxx17_compat_explicit_bool
4118 : diag::ext_explicit_bool);
4122 Tracker.consumeOpen();
4129 if (ExplicitExpr.isUsable()) {
4131 Tracker.consumeClose();
4135 Tracker.skipToEnd();
4141 ExplicitSpec, CloseParenLoc);
4144 case tok::kw__Noreturn:
4146 Diag(Tok, diag::ext_c11_feature) << Tok.
getName();
4151 case tok::kw__Alignas:
4153 Diag(Tok, diag::ext_c11_feature) << Tok.
getName();
4158 case tok::kw_friend:
4159 if (DSContext == DeclSpecContext::DSC_class)
4163 DiagID = diag::err_friend_invalid_in_context;
4169 case tok::kw___module_private__:
4174 case tok::kw_constexpr:
4178 case tok::kw_consteval:
4182 case tok::kw_constinit:
4198 PrevSpec, DiagID, Policy);
4200 case tok::kw___int64:
4202 PrevSpec, DiagID, Policy);
4204 case tok::kw_signed:
4208 case tok::kw_unsigned:
4212 case tok::kw__Complex:
4214 Diag(Tok, diag::ext_c99_feature) << Tok.
getName();
4218 case tok::kw__Imaginary:
4220 Diag(Tok, diag::ext_c99_feature) << Tok.
getName();
4236 case tok::kw__ExtInt:
4237 case tok::kw__BitInt: {
4238 DiagnoseBitIntUse(Tok);
4243 ConsumedEnd = PrevTokLocation;
4246 case tok::kw___int128:
4254 case tok::kw___bf16:
4262 case tok::kw_double:
4266 case tok::kw__Float16:
4270 case tok::kw__Accum:
4278 case tok::kw__Fract:
4293 case tok::kw___float128:
4297 case tok::kw___ibm128:
4301 case tok::kw_wchar_t:
4305 case tok::kw_char8_t:
4309 case tok::kw_char16_t:
4313 case tok::kw_char32_t:
4319 Diag(Tok, diag::warn_c23_compat_keyword) << Tok.
getName();
4323 Diag(Tok, diag::ext_c99_feature) << Tok.
getName();
4325 if (Tok.
is(tok::kw_bool) &&
4329 DiagID = diag::err_bool_redeclaration;
4338 case tok::kw__Decimal32:
4342 case tok::kw__Decimal64:
4346 case tok::kw__Decimal128:
4350 case tok::kw___vector:
4353 case tok::kw___pixel:
4356 case tok::kw___bool:
4361 getLangOpts().getOpenCLCompatibleVersion() < 200) {
4366 goto DoneWithDeclSpec;
4368 DiagID = diag::err_opencl_unknown_type_specifier;
4375#define IMAGE_READ_WRITE_TYPE(Type, Id, Ext)
4376#define IMAGE_WRITE_TYPE(Type, Id, Ext)
4377#define IMAGE_READ_TYPE(ImgType, Id, Ext) \
4378 case tok::kw_##ImgType##_t: \
4379 if (!handleOpenCLImageKW(Ext, DeclSpec::TST_##ImgType##_t)) \
4380 goto DoneWithDeclSpec; \
4382#include "clang/Basic/OpenCLImageTypes.def"
4383 case tok::kw___unknown_anytype:
4385 PrevSpec, DiagID, Policy);
4390 case tok::kw_struct:
4391 case tok::kw___interface:
4392 case tok::kw_union: {
4400 ParseClassSpecifier(Kind, Loc, DS, TemplateInfo, AS,
4401 EnteringContext, DSContext, Attributes);
4405 if (!Attributes.empty()) {
4406 AttrsLastTime =
true;
4407 attrs.takeAllFrom(Attributes);
4415 ParseEnumSpecifier(Loc, DS, TemplateInfo, AS, DSContext);
4423 case tok::kw_volatile:
4427 case tok::kw_restrict:
4433 case tok::kw_typename:
4436 goto DoneWithDeclSpec;
4438 if (!Tok.
is(tok::kw_typename))
4443 case tok::kw_typeof:
4444 case tok::kw_typeof_unqual:
4445 ParseTypeofSpecifier(DS);
4448 case tok::annot_decltype:
4449 ParseDecltypeSpecifier(DS);
4452 case tok::annot_pragma_pack:
4456 case tok::annot_pragma_ms_pragma:
4457 HandlePragmaMSPragma();
4460 case tok::annot_pragma_ms_vtordisp:
4461 HandlePragmaMSVtorDisp();
4464 case tok::annot_pragma_ms_pointers_to_members:
4465 HandlePragmaMSPointersToMembers();
4468#define TRANSFORM_TYPE_TRAIT_DEF(_, Trait) case tok::kw___##Trait:
4469#include "clang/Basic/TransformTypeTraits.def"
4473 if (!MaybeParseTypeTransformTypeSpecifier(DS))
4474 goto ParseIdentifier;
4477 case tok::kw__Atomic:
4483 Diag(Tok, diag::ext_c11_feature) << Tok.
getName();
4486 ParseAtomicSpecifier(DS);
4494 case tok::kw___generic:
4499 if (!Actions.
getLangOpts().OpenCLGenericAddressSpace) {
4500 DiagID = diag::err_opencl_unknown_type_specifier;
4506 case tok::kw_private:
4510 goto DoneWithDeclSpec;
4512 case tok::kw___private:
4513 case tok::kw___global:
4514 case tok::kw___local:
4515 case tok::kw___constant:
4517 case tok::kw___read_only:
4518 case tok::kw___write_only:
4519 case tok::kw___read_write:
4523 case tok::kw_groupshared:
4533 goto DoneWithDeclSpec;
4538 if (
Type.isUsable()) {
4540 PrevSpec, DiagID,
Type.get(),
4542 Diag(StartLoc, DiagID) << PrevSpec;
4558 assert(PrevSpec &&
"Method did not return previous specifier!");
4561 if (DiagID == diag::ext_duplicate_declspec ||
4562 DiagID == diag::ext_warn_duplicate_declspec ||
4563 DiagID == diag::err_duplicate_declspec)
4564 Diag(Loc, DiagID) << PrevSpec
4567 else if (DiagID == diag::err_opencl_unknown_type_specifier) {
4571 Diag(Loc, DiagID) << PrevSpec;
4574 if (DiagID != diag::err_bool_redeclaration && ConsumedEnd.
isInvalid())
4578 AttrsLastTime =
false;
4603void Parser::ParseStructDeclaration(
4607 if (Tok.
is(tok::kw___extension__)) {
4611 return ParseStructDeclaration(DS, FieldsCallback);
4616 MaybeParseCXX11Attributes(Attrs);
4619 ParseSpecifierQualifierList(DS);
4623 if (Tok.
is(tok::semi)) {
4628 ProhibitAttributes(Attrs);
4632 assert(!AnonRecord &&
"Did not expect anonymous struct or union here");
4638 bool FirstDeclarator =
true;
4642 DeclaratorInfo.D.setCommaLoc(CommaLoc);
4645 if (!FirstDeclarator) {
4648 DiagnoseAndSkipCXX11Attributes();
4649 MaybeParseGNUAttributes(DeclaratorInfo.D);
4650 DiagnoseAndSkipCXX11Attributes();
4655 if (Tok.
isNot(tok::colon)) {
4658 ParseDeclarator(DeclaratorInfo.D);
4660 DeclaratorInfo.D.SetIdentifier(
nullptr, Tok.
getLocation());
4667 DeclaratorInfo.BitfieldSize = Res.
get();
4671 MaybeParseGNUAttributes(DeclaratorInfo.D);
4674 FieldsCallback(DeclaratorInfo);
4681 FirstDeclarator =
false;
4698 "parsing struct/union body");
4702 if (T.consumeOpen())
4709 while (!tryParseMisplacedModuleImport() && Tok.
isNot(tok::r_brace) &&
4710 Tok.
isNot(tok::eof)) {
4714 if (Tok.
is(tok::semi)) {
4715 ConsumeExtraSemi(InsideStruct,
TagType);
4720 if (Tok.
isOneOf(tok::kw__Static_assert, tok::kw_static_assert)) {
4722 ParseStaticAssertDeclaration(DeclEnd);
4726 if (Tok.
is(tok::annot_pragma_pack)) {
4731 if (Tok.
is(tok::annot_pragma_align)) {
4732 HandlePragmaAlign();
4736 if (Tok.
isOneOf(tok::annot_pragma_openmp, tok::annot_attr_openmp)) {
4740 (void)ParseOpenMPDeclarativeDirectiveWithExtDecl(AS, Attrs);
4748 ConsumeAnnotationToken();
4752 if (!Tok.
is(tok::at)) {
4758 FD.D, FD.BitfieldSize);
4764 ParseStructDeclaration(DS, CFieldCallback);
4768 Diag(Tok, diag::err_unexpected_at);
4773 ExpectAndConsume(tok::l_paren);
4774 if (!Tok.
is(tok::identifier)) {
4775 Diag(Tok, diag::err_expected) << tok::identifier;
4783 ExpectAndConsume(tok::r_paren);
4789 if (Tok.
is(tok::r_brace)) {
4790 ExpectAndConsume(tok::semi, diag::ext_expected_semi_decl_list);
4794 ExpectAndConsume(tok::semi, diag::err_expected_semi_decl_list);
4805 MaybeParseGNUAttributes(attrs);
4810 T.getOpenLocation(), T.getCloseLocation(), attrs);
4846 const ParsedTemplateInfo &TemplateInfo,
4849 if (Tok.
is(tok::code_completion)) {
4859 MaybeParseAttributes(PAKM_GNU | PAKM_Declspec | PAKM_CXX11, attrs);
4862 bool IsScopedUsingClassTag =
false;
4867 : diag::ext_scoped_enum);
4868 IsScopedUsingClassTag = Tok.
is(tok::kw_class);
4873 ProhibitAttributes(attrs);
4876 MaybeParseAttributes(PAKM_GNU | PAKM_Declspec | PAKM_CXX11, attrs);
4885 bool shouldDelayDiagsInTag =
4886 (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation ||
4887 TemplateInfo.Kind == ParsedTemplateInfo::ExplicitSpecialization);
4891 AllowDefiningTypeSpec AllowEnumSpecifier =
4893 bool CanBeOpaqueEnumDeclaration =
4894 DS.
isEmpty() && isOpaqueEnumDeclarationContext(DSC);
4897 (AllowEnumSpecifier == AllowDefiningTypeSpec::Yes ||
4898 CanBeOpaqueEnumDeclaration);
4906 if (ParseOptionalCXXScopeSpecifier(Spec,
nullptr,
4911 if (Spec.
isSet() && Tok.
isNot(tok::identifier)) {
4912 Diag(Tok, diag::err_expected) << tok::identifier;
4914 if (Tok.
isNot(tok::l_brace)) {
4926 if (Tok.
isNot(tok::identifier) && Tok.
isNot(tok::l_brace) &&
4927 Tok.
isNot(tok::colon)) {
4928 Diag(Tok, diag::err_expected_either) << tok::identifier << tok::l_brace;
4939 if (Tok.
is(tok::identifier)) {
4944 if (!Name && ScopedEnumKWLoc.
isValid()) {
4947 Diag(Tok, diag::err_scoped_enum_missing_identifier);
4949 IsScopedUsingClassTag =
false;
4954 if (shouldDelayDiagsInTag)
4955 diagsFromTag.done();
4960 bool CanBeBitfield =
4964 if (Tok.
is(tok::colon)) {
4989 if (CanBeBitfield && !isEnumBase(CanBeOpaqueEnumDeclaration)) {
4994 }
else if (CanHaveEnumBase || !ColonIsSacred) {
5005 DeclSpecContext::DSC_type_specifier);
5010 BaseRange =
SourceRange(ColonLoc, DeclaratorInfo.getSourceRange().getEnd());
5014 Diag(ColonLoc, diag::warn_cxx98_compat_enum_fixed_underlying_type)
5017 Diag(ColonLoc, diag::ext_cxx11_enum_fixed_underlying_type)
5020 Diag(ColonLoc, diag::ext_ms_c_enum_fixed_underlying_type)
5023 Diag(ColonLoc, diag::ext_clang_c_enum_fixed_underlying_type)
5040 if (AllowEnumSpecifier == AllowDefiningTypeSpec::No)
5042 else if (Tok.
is(tok::l_brace)) {
5051 IsScopedUsingClassTag =
false;
5057 }
else if (!isTypeSpecifier(DSC) &&
5058 (Tok.
is(tok::semi) ||
5060 !isValidAfterTypeSpecifier(CanBeBitfield)))) {
5065 if (Tok.
isNot(tok::semi)) {
5067 ExpectAndConsume(tok::semi, diag::err_expected_after,
"enum");
5075 bool IsElaboratedTypeSpecifier =
5081 diagsFromTag.redelay();
5085 if (TemplateInfo.Kind != ParsedTemplateInfo::NonTemplate &&
5089 Diag(Tok, diag::err_enum_template);
5094 if (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation) {
5097 Diag(StartLoc, diag::err_explicit_instantiation_enum);
5101 assert(TemplateInfo.TemplateParams &&
"no template parameters");
5103 TemplateInfo.TemplateParams->size());
5108 Diag(Tok, diag::err_enumerator_unnamed_no_def);
5124 if (IsElaboratedTypeSpecifier && !
getLangOpts().MicrosoftExt &&
5126 ProhibitCXX11Attributes(attrs, diag::err_attributes_not_allowed,
5127 diag::err_keyword_not_allowed,
5130 Diag(BaseRange.
getBegin(), diag::ext_enum_base_in_type_specifier)
5131 << (AllowEnumSpecifier == AllowDefiningTypeSpec::Yes) << BaseRange;
5132 else if (ScopedEnumKWLoc.
isValid())
5133 Diag(ScopedEnumKWLoc, diag::ext_elaborated_enum_class)
5137 stripTypeAttributesOffDeclSpec(attrs, DS, TUK);
5147 bool IsDependent =
false;
5148 const char *PrevSpec =
nullptr;
5153 TParams, Owned, IsDependent, ScopedEnumKWLoc,
5154 IsScopedUsingClassTag,
5155 BaseType, DSC == DeclSpecContext::DSC_type_specifier,
5156 DSC == DeclSpecContext::DSC_template_param ||
5157 DSC == DeclSpecContext::DSC_template_type_arg,
5158 OffsetOfState, &SkipBody).
get();
5168 NameLoc.
isValid() ? NameLoc : StartLoc,
5169 PrevSpec, DiagID,
TagDecl, Owned,
5171 Diag(StartLoc, DiagID) << PrevSpec;
5180 Diag(Tok, diag::err_expected_type_name_after_typename);
5186 if (
Type.isInvalid()) {
5192 NameLoc.
isValid() ? NameLoc : StartLoc,
5193 PrevSpec, DiagID,
Type.get(),
5195 Diag(StartLoc, DiagID) << PrevSpec;
5214 ParseEnumBody(StartLoc, D);
5223 NameLoc.
isValid() ? NameLoc : StartLoc,
5224 PrevSpec, DiagID,
TagDecl, Owned,
5226 Diag(StartLoc, DiagID) << PrevSpec;
5249 Diag(Tok, diag::err_empty_enum);
5254 Decl *LastEnumConstDecl =
nullptr;
5257 while (Tok.
isNot(tok::r_brace)) {
5260 if (Tok.
isNot(tok::identifier)) {
5272 MaybeParseGNUAttributes(attrs);
5273 if (isAllowedCXX11AttributeSpecifier()) {
5276 ? diag::warn_cxx14_compat_ns_enum_attribute
5277 : diag::ext_ns_enum_attribute)
5279 ParseCXX11Attributes(attrs);
5284 EnumAvailabilityDiags.emplace_back(*
this);
5297 EqualLoc, AssignedVal.
get());
5298 EnumAvailabilityDiags.back().done();
5300 EnumConstantDecls.push_back(EnumConstDecl);
5301 LastEnumConstDecl = EnumConstDecl;
5303 if (Tok.
is(tok::identifier)) {
5306 Diag(Loc, diag::err_enumerator_list_missing_comma)
5329 if (Tok.
is(tok::r_brace) && CommaLoc.
isValid()) {
5332 diag::ext_enumerator_list_comma_cxx :
5333 diag::ext_enumerator_list_comma_c)
5336 Diag(CommaLoc, diag::warn_cxx98_compat_enumerator_list_comma)
5347 MaybeParseGNUAttributes(attrs);
5353 assert(EnumConstantDecls.size() == EnumAvailabilityDiags.size());
5354 for (
size_t i = 0, e = EnumConstantDecls.size(); i != e; ++i) {
5356 EnumAvailabilityDiags[i].redelay();
5357 PD.complete(EnumConstantDecls[i]);
5366 if (!isValidAfterTypeSpecifier(CanBeBitfield)) {
5367 ExpectAndConsume(tok::semi, diag::err_expected_after,
"enum");
5379bool Parser::isKnownToBeTypeSpecifier(
const Token &Tok)
const {
5381 default:
return false;
5385 case tok::kw___int64:
5386 case tok::kw___int128:
5387 case tok::kw_signed:
5388 case tok::kw_unsigned:
5389 case tok::kw__Complex:
5390 case tok::kw__Imaginary:
5393 case tok::kw_wchar_t:
5394 case tok::kw_char8_t:
5395 case tok::kw_char16_t:
5396 case tok::kw_char32_t:
5398 case tok::kw__ExtInt:
5399 case tok::kw__BitInt:
5400 case tok::kw___bf16:
5403 case tok::kw_double:
5404 case tok::kw__Accum:
5405 case tok::kw__Fract:
5406 case tok::kw__Float16:
5407 case tok::kw___float128:
5408 case tok::kw___ibm128:
5411 case tok::kw__Decimal32:
5412 case tok::kw__Decimal64:
5413 case tok::kw__Decimal128:
5414 case tok::kw___vector:
5415#define GENERIC_IMAGE_TYPE(ImgType, Id) case tok::kw_##ImgType##_t:
5416#include "clang/Basic/OpenCLImageTypes.def"
5420 case tok::kw_struct:
5421 case tok::kw___interface:
5427 case tok::annot_typename:
5434bool Parser::isTypeSpecifierQualifier() {
5436 default:
return false;
5438 case tok::identifier:
5439 if (TryAltiVecVectorToken())
5442 case tok::kw_typename:
5447 if (Tok.
is(tok::identifier))
5449 return isTypeSpecifierQualifier();
5451 case tok::coloncolon: