31#include "llvm/ADT/SmallString.h"
32#include "llvm/Support/TimeProfiler.h"
67 assert(Tok.
is(tok::kw_namespace) &&
"Not a namespace!");
71 if (Tok.
is(tok::code_completion)) {
79 InnerNamespaceInfoList ExtraNSs;
84 auto ReadAttributes = [&] {
88 if (Tok.
is(tok::kw___attribute)) {
89 ParseGNUAttributes(attrs);
94 ? diag::warn_cxx14_compat_ns_enum_attribute
95 : diag::ext_ns_enum_attribute)
97 ParseCXX11Attributes(attrs);
100 }
while (MoreToParse);
105 if (Tok.
is(tok::identifier)) {
108 while (Tok.
is(tok::coloncolon) &&
111 GetLookAheadToken(2).is(tok::identifier)))) {
113 InnerNamespaceInfo Info;
116 if (Tok.
is(tok::kw_inline)) {
119 FirstNestedInlineLoc = Info.InlineLoc;
125 ExtraNSs.push_back(Info);
134 if (!ExtraNSs.empty() && attrLoc.
isValid())
135 Diag(attrLoc, diag::err_unexpected_nested_namespace_attribute);
137 if (Tok.
is(tok::equal)) {
139 Diag(Tok, diag::err_expected) << tok::identifier;
144 if (!ExtraNSs.empty()) {
145 Diag(ExtraNSs.front().NamespaceLoc,
146 diag::err_unexpected_qualified_namespace_alias)
148 ExtraNSs.back().IdentLoc);
153 Diag(attrLoc, diag::err_unexpected_namespace_attributes_alias);
155 Diag(InlineLoc, diag::err_inline_namespace_alias)
157 Decl *NSAlias = ParseNamespaceAlias(NamespaceLoc, IdentLoc, Ident, DeclEnd);
162 if (
T.consumeOpen()) {
164 Diag(Tok, diag::err_expected) << tok::l_brace;
166 Diag(Tok, diag::err_expected_either) << tok::identifier << tok::l_brace;
173 Diag(
T.getOpenLocation(), diag::err_namespace_nonnamespace_scope);
178 if (ExtraNSs.empty()) {
180 }
else if (InlineLoc.
isValid()) {
181 Diag(InlineLoc, diag::err_inline_nested_namespace_definition);
183 Diag(ExtraNSs[0].NamespaceLoc,
184 diag::warn_cxx14_compat_nested_namespace_definition);
185 if (FirstNestedInlineLoc.
isValid())
186 Diag(FirstNestedInlineLoc,
187 diag::warn_cxx17_compat_inline_nested_namespace_definition);
189 Diag(ExtraNSs[0].NamespaceLoc,
190 diag::warn_cxx14_compat_nested_namespace_definition);
191 if (FirstNestedInlineLoc.
isValid())
192 Diag(FirstNestedInlineLoc, diag::ext_inline_nested_namespace_definition);
194 TentativeParsingAction TPA(*
this);
196 Token rBraceToken = Tok;
199 if (!rBraceToken.
is(tok::r_brace)) {
200 Diag(ExtraNSs[0].NamespaceLoc, diag::ext_nested_namespace_definition)
202 ExtraNSs.back().IdentLoc);
204 std::string NamespaceFix;
205 for (
const auto &ExtraNS : ExtraNSs) {
206 NamespaceFix +=
" { ";
207 if (ExtraNS.InlineLoc.isValid())
208 NamespaceFix +=
"inline ";
209 NamespaceFix +=
"namespace ";
210 NamespaceFix += ExtraNS.Ident->getName();
214 for (
unsigned i = 0, e = ExtraNSs.size(); i != e; ++i)
217 Diag(ExtraNSs[0].NamespaceLoc, diag::ext_nested_namespace_definition)
220 ExtraNSs.back().IdentLoc),
226 if (FirstNestedInlineLoc.
isValid())
227 Diag(FirstNestedInlineLoc, diag::ext_inline_nested_namespace_definition);
233 ? diag::warn_cxx98_compat_inline_namespace
234 : diag::ext_inline_namespace);
241 getCurScope(), InlineLoc, NamespaceLoc, IdentLoc, Ident,
242 T.getOpenLocation(), attrs, ImplicitUsingDirectiveDecl,
false);
245 NamespaceLoc,
"parsing namespace");
249 ParseInnerNamespace(ExtraNSs, 0, InlineLoc, attrs,
T);
252 NamespaceScope.Exit();
254 DeclEnd =
T.getCloseLocation();
258 ImplicitUsingDirectiveDecl);
262void Parser::ParseInnerNamespace(
const InnerNamespaceInfoList &InnerNSs,
266 if (index == InnerNSs.size()) {
267 while (!tryParseMisplacedModuleImport() && Tok.
isNot(tok::r_brace) &&
268 Tok.
isNot(tok::eof)) {
270 MaybeParseCXX11Attributes(DeclAttrs);
272 ParseExternalDeclaration(DeclAttrs, EmptyDeclSpecAttrs);
288 getCurScope(), InnerNSs[index].InlineLoc, InnerNSs[index].NamespaceLoc,
289 InnerNSs[index].IdentLoc, InnerNSs[index].Ident,
291 assert(!ImplicitUsingDirectiveDecl &&
292 "nested namespace definition cannot define anonymous namespace");
294 ParseInnerNamespace(InnerNSs, ++index, InlineLoc, attrs, Tracker);
296 NamespaceScope.Exit();
307 assert(Tok.
is(tok::equal) &&
"Not equal token");
311 if (Tok.
is(tok::code_completion)) {
319 ParseOptionalCXXScopeSpecifier(SS,
nullptr,
327 if (Tok.
isNot(tok::identifier)) {
328 Diag(Tok, diag::err_expected_namespace_name);
347 if (ExpectAndConsume(tok::semi, diag::err_expected_semi_after_namespace_name))
351 Alias, SS, IdentLoc, Ident);
362 assert(isTokenStringLiteral() &&
"Not a string literal!");
376 while (MaybeParseCXX11Attributes(DeclAttrs) ||
377 MaybeParseGNUAttributes(DeclSpecAttrs))
380 if (Tok.
isNot(tok::l_brace)) {
387 ParseExternalDeclaration(DeclAttrs, DeclSpecAttrs, &DS);
395 ProhibitAttributes(DeclAttrs);
400 unsigned NestedModules = 0;
403 case tok::annot_module_begin:
408 case tok::annot_module_end:
415 case tok::annot_module_include:
429 while (MaybeParseCXX11Attributes(DeclAttrs) ||
430 MaybeParseGNUAttributes(DeclSpecAttrs))
432 ParseExternalDeclaration(DeclAttrs, DeclSpecAttrs);
459Decl *Parser::ParseExportDeclaration() {
460 assert(Tok.
is(tok::kw_export));
463 if (Tok.
is(tok::code_completion)) {
477 if (Tok.
isNot(tok::l_brace)) {
480 MaybeParseCXX11Attributes(DeclAttrs);
482 ParseExternalDeclaration(DeclAttrs, EmptyDeclSpecAttrs);
490 while (!tryParseMisplacedModuleImport() && Tok.
isNot(tok::r_brace) &&
491 Tok.
isNot(tok::eof)) {
493 MaybeParseCXX11Attributes(DeclAttrs);
495 ParseExternalDeclaration(DeclAttrs, EmptyDeclSpecAttrs);
500 T.getCloseLocation());
508 assert(Tok.
is(tok::kw_using) &&
"Not using token");
514 if (Tok.
is(tok::code_completion)) {
521 while (Tok.
is(tok::kw_template)) {
523 Diag(TemplateLoc, diag::err_unexpected_template_after_using)
528 if (Tok.
is(tok::kw_namespace)) {
530 if (TemplateInfo.Kind) {
532 Diag(UsingLoc, diag::err_templated_using_directive_declaration)
536 Decl *UsingDir = ParseUsingDirective(Context, UsingLoc, DeclEnd, Attrs);
541 return ParseUsingDeclaration(Context, TemplateInfo, UsingLoc, DeclEnd, Attrs,
559 assert(Tok.
is(tok::kw_namespace) &&
"Not 'namespace' token");
564 if (Tok.
is(tok::code_completion)) {
572 ParseOptionalCXXScopeSpecifier(SS,
nullptr,
584 if (Tok.
isNot(tok::identifier)) {
585 Diag(Tok, diag::err_expected_namespace_name);
604 bool GNUAttr =
false;
605 if (Tok.
is(tok::kw___attribute)) {
607 ParseGNUAttributes(attrs);
612 if (ExpectAndConsume(tok::semi,
613 GNUAttr ? diag::err_expected_semi_after_attribute_list
614 : diag::err_expected_semi_after_namespace_name))
618 IdentLoc, NamespcName, attrs);
627 UsingDeclarator &
D) {
634 if (Tok.
is(tok::kw___super)) {
641 if (ParseOptionalCXXScopeSpecifier(
D.SS,
nullptr,
651 if (
D.SS.isInvalid())
665 Tok.
is(tok::identifier) &&
671 !
D.SS.getScopeRep()->getAsNamespace() &&
672 !
D.SS.getScopeRep()->getAsNamespaceAlias()) {
676 D.Name.setConstructorName(
Type, IdLoc, IdLoc);
683 !(Tok.
is(tok::identifier) &&
NextToken().is(tok::equal)),
684 false,
nullptr,
D.Name))
690 ? diag::warn_cxx17_compat_using_declaration_pack
691 : diag::ext_using_declaration_pack);
730 ? diag::warn_cxx17_compat_using_enum_declaration
731 : diag::ext_using_enum_declaration);
733 DiagnoseCXX11AttributeExtension(PrefixAttrs);
735 if (TemplateInfo.Kind) {
737 Diag(UsingLoc, diag::err_templated_using_directive_declaration)
743 if (ParseOptionalCXXScopeSpecifier(SS,
nullptr,
755 if (Tok.
is(tok::code_completion)) {
765 if (Tok.
is(tok::identifier)) {
777 }
else if (Tok.
is(tok::annot_template_id)) {
784 assert(Tok.
is(tok::annot_typename) &&
"template-id -> type failed");
787 ConsumeAnnotationToken();
799 << Tok.
is(tok::kw_enum);
810 if (ExpectAndConsume(tok::semi, diag::err_expected_after,
811 "using-enum declaration"))
820 MaybeParseCXX11Attributes(MisplacedAttrs);
822 if (InInitStatement && Tok.
isNot(tok::identifier))
826 bool InvalidDeclarator = ParseUsingDeclarator(Context,
D);
829 MaybeParseAttributes(PAKM_GNU | PAKM_CXX11, Attrs);
833 if (MisplacedAttrs.Range.isValid()) {
835 MisplacedAttrs.empty() ? nullptr : &MisplacedAttrs.front();
836 auto &
Range = MisplacedAttrs.Range;
837 (FirstAttr && FirstAttr->isRegularKeywordAttribute()
847 if (Tok.
is(tok::equal) || InInitStatement) {
848 if (InvalidDeclarator) {
853 ProhibitAttributes(PrefixAttrs);
855 Decl *DeclFromDeclSpec =
nullptr;
861 Decl *AD = ParseAliasDeclarationAfterDeclarator(
862 TemplateInfo, UsingLoc,
D, DeclEnd, AS, Attrs, &DeclFromDeclSpec);
866 DiagnoseCXX11AttributeExtension(PrefixAttrs);
871 if (TemplateInfo.Kind) {
873 Diag(UsingLoc, diag::err_templated_using_directive_declaration)
885 MaybeParseAttributes(PAKM_GNU | PAKM_CXX11, Attrs);
886 DiagnoseCXX11AttributeExtension(Attrs);
889 if (InvalidDeclarator)
894 if (
D.TypenameLoc.isValid() &&
897 diag::err_typename_identifiers_only)
904 D.TypenameLoc,
D.SS,
D.Name,
905 D.EllipsisLoc, Attrs);
907 DeclsInGroup.push_back(UD);
915 InvalidDeclarator = ParseUsingDeclarator(Context,
D);
918 if (DeclsInGroup.size() > 1)
921 ? diag::warn_cxx17_compat_multi_using_declaration
922 : diag::ext_multi_using_declaration);
926 if (ExpectAndConsume(tok::semi, diag::err_expected_after,
927 !Attrs.
empty() ?
"attributes list"
928 : UELoc.
isValid() ?
"using-enum declaration"
929 :
"using declaration"))
935Decl *Parser::ParseAliasDeclarationAfterDeclarator(
939 if (ExpectAndConsume(tok::equal)) {
945 ? diag::warn_cxx98_compat_alias_declaration
946 : diag::ext_alias_declaration);
950 if (TemplateInfo.Kind == ParsedTemplateInfo::Template &&
953 if (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitSpecialization)
955 if (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation)
957 if (SpecKind != -1) {
961 D.Name.TemplateId->RAngleLoc);
963 Range = TemplateInfo.getSourceRange();
965 << SpecKind <<
Range;
972 Diag(
D.Name.StartLocation, diag::err_alias_declaration_not_identifier);
976 }
else if (
D.TypenameLoc.isValid())
977 Diag(
D.TypenameLoc, diag::err_alias_declaration_not_identifier)
981 else if (
D.SS.isNotEmpty())
984 if (
D.EllipsisLoc.isValid())
985 Diag(
D.EllipsisLoc, diag::err_alias_declaration_pack_expansion)
988 Decl *DeclFromDeclSpec =
nullptr;
993 AS, &DeclFromDeclSpec, &Attrs);
995 *OwnedType = DeclFromDeclSpec;
999 if (ExpectAndConsume(tok::semi, diag::err_expected_after,
1000 !Attrs.
empty() ?
"attributes list"
1001 :
"alias declaration"))
1006 TemplateParams ? TemplateParams->data() :
nullptr,
1007 TemplateParams ? TemplateParams->size() : 0);
1009 UsingLoc,
D.Name, Attrs, TypeAlias,
1015 if (
const auto *BO = dyn_cast_or_null<BinaryOperator>(AssertExpr)) {
1016 if (BO->getOpcode() == BO_LAnd &&
1017 isa<StringLiteral>(BO->getRHS()->IgnoreImpCasts()))
1032 assert(Tok.
isOneOf(tok::kw_static_assert, tok::kw__Static_assert) &&
1033 "Not a static_assert declaration");
1036 const char *TokName = Tok.
getName();
1038 if (Tok.
is(tok::kw__Static_assert))
1039 diagnoseUseOfC11Keyword(Tok);
1040 else if (Tok.
is(tok::kw_static_assert)) {
1043 Diag(Tok, diag::warn_c23_compat_keyword) << Tok.
getName();
1048 Diag(Tok, diag::warn_cxx98_compat_static_assert);
1054 if (
T.consumeOpen()) {
1055 Diag(Tok, diag::err_expected) << tok::l_paren;
1063 if (AssertExpr.isInvalid()) {
1069 if (Tok.
is(tok::r_paren)) {
1072 DiagVal = diag::warn_cxx14_compat_static_assert_no_message;
1074 DiagVal = diag::ext_cxx_static_assert_no_message;
1076 DiagVal = diag::warn_c17_compat_static_assert_no_message;
1078 DiagVal = diag::ext_c_static_assert_no_message;
1082 if (ExpectAndConsume(tok::comma)) {
1087 bool ParseAsExpression =
false;
1089 for (
unsigned I = 0;; ++I) {
1090 const Token &
T = GetLookAheadToken(I);
1091 if (
T.is(tok::r_paren))
1094 ParseAsExpression =
true;
1100 if (ParseAsExpression) {
1103 ? diag::warn_cxx20_compat_static_assert_user_generated_message
1104 : diag::ext_cxx_static_assert_user_generated_message);
1109 Diag(Tok, diag::err_expected_string_literal)
1121 if (
T.consumeClose())
1125 ExpectAndConsumeSemi(diag::err_expected_semi_after_static_assert, TokName);
1128 AssertMessage.
get(),
1129 T.getCloseLocation());
1138 assert(Tok.
isOneOf(tok::kw_decltype, tok::annot_decltype) &&
1139 "Not a decltype specifier");
1145 if (Tok.
is(tok::annot_decltype)) {
1146 Result = getExprAnnotation(Tok);
1151 ConsumeAnnotationToken();
1152 if (
Result.isInvalid()) {
1158 Diag(Tok, diag::warn_cxx98_compat_decltype);
1163 if (
T.expectAndConsume(diag::err_expected_lparen_after,
"decltype",
1166 return T.getOpenLocation() == Tok.
getLocation() ? StartLoc
1167 :
T.getOpenLocation();
1171 if (Tok.
is(tok::kw_auto) &&
NextToken().is(tok::r_paren)) {
1176 ? diag::warn_cxx11_compat_decltype_auto_type_specifier
1177 : diag::ext_decltype_auto_type_specifier);
1191 if (
Result.isInvalid()) {
1194 EndLoc = ConsumeParen();
1201 assert(Tok.
is(tok::semi));
1215 if (
T.getCloseLocation().isInvalid()) {
1219 return T.getCloseLocation();
1222 if (
Result.isInvalid()) {
1224 return T.getCloseLocation();
1227 EndLoc =
T.getCloseLocation();
1229 assert(!
Result.isInvalid());
1231 const char *PrevSpec =
nullptr;
1236 PrevSpec, DiagID,
Result.get(), Policy)
1238 PrevSpec, DiagID, Policy)) {
1239 Diag(StartLoc, DiagID) << PrevSpec;
1245void Parser::AnnotateExistingDecltypeSpecifier(
const DeclSpec &DS,
1261 Tok.
setKind(tok::annot_decltype);
1262 setExprAnnotation(Tok,
1272 assert(Tok.
isOneOf(tok::annot_pack_indexing_type, tok::identifier) &&
1273 "Expected an identifier");
1278 const char *PrevSpec;
1282 if (Tok.
is(tok::annot_pack_indexing_type)) {
1290 ConsumeAnnotationToken();
1291 if (
Type.isInvalid()) {
1296 DiagID,
Type, Policy);
1300 !GetLookAheadToken(2).is(tok::l_square)) {
1332 return T.getCloseLocation();
1335void Parser::AnnotateExistingIndexedTypeNamePack(
ParsedType T,
1351 Tok.
setKind(tok::annot_pack_indexing_type);
1352 setTypeAnnotation(Tok,
T);
1360#define TRANSFORM_TYPE_TRAIT_DEF(_, Trait) \
1361 case tok::kw___##Trait: \
1362 return DeclSpec::TST_##Trait;
1363#include "clang/Basic/TransformTypeTraits.def"
1365 llvm_unreachable(
"passed in an unhandled type transformation built-in");
1369bool Parser::MaybeParseTypeTransformTypeSpecifier(
DeclSpec &DS) {
1374 DeclSpec::TST TypeTransformTST = TypeTransformTokToDeclSpec();
1378 if (
T.expectAndConsume(diag::err_expected_lparen_after, Tok.
getName(),
1383 if (
Result.isInvalid()) {
1389 if (
T.getCloseLocation().isInvalid())
1392 const char *PrevSpec =
nullptr;
1397 Diag(StartLoc, DiagID) << PrevSpec;
1423 if (Tok.
is(tok::kw_typename)) {
1424 Diag(Tok, diag::err_expected_class_name_not_template)
1431 if (ParseOptionalCXXScopeSpecifier(SS,
nullptr,
1441 if (Tok.
isOneOf(tok::kw_decltype, tok::annot_decltype)) {
1448 EndLocation = ParseDecltypeSpecifier(DS);
1455 if (Tok.
is(tok::annot_pack_indexing_type)) {
1457 ParsePackIndexingType(DS);
1466 if (Tok.
is(tok::annot_template_id)) {
1472 assert(Tok.
is(tok::annot_typename) &&
"template-id -> type failed");
1475 ConsumeAnnotationToken();
1482 if (Tok.
isNot(tok::identifier)) {
1483 Diag(Tok, diag::err_expected_class_name);
1490 if (Tok.
is(tok::less)) {
1499 Diag(IdLoc, diag::err_unknown_template_name) <<
Id;
1510 if (Tok.
is(tok::annot_template_id) &&
1511 takeTemplateIdAnnotation(Tok)->mightBeType())
1517 if (Tok.
isNot(tok::annot_typename))
1524 ConsumeAnnotationToken();
1537 Diag(IdLoc, diag::err_expected_class_name);
1542 EndLocation = IdLoc;
1550 const char *PrevSpec =
nullptr;
1560void Parser::ParseMicrosoftInheritanceClassAttributes(
ParsedAttributes &attrs) {
1561 while (Tok.
isOneOf(tok::kw___single_inheritance,
1562 tok::kw___multiple_inheritance,
1563 tok::kw___virtual_inheritance)) {
1567 attrs.
addNew(AttrName, AttrNameLoc,
nullptr, AttrNameLoc,
nullptr, 0, Kind);
1572 while (Tok.
is(tok::kw__Nullable)) {
1576 attrs.
addNew(AttrName, AttrNameLoc,
nullptr, AttrNameLoc,
nullptr, 0, Kind);
1583bool Parser::isValidAfterTypeSpecifier(
bool CouldBeBitfield) {
1594 case tok::identifier:
1596 case tok::coloncolon:
1597 case tok::annot_cxxscope:
1598 case tok::annot_typename:
1599 case tok::annot_template_id:
1600 case tok::kw_decltype:
1603 case tok::kw_operator:
1604 case tok::kw___declspec:
1609 case tok::kw___attribute:
1610 case tok::annot_pragma_pack:
1612 case tok::annot_pragma_ms_pragma:
1614 case tok::annot_pragma_ms_vtordisp:
1616 case tok::annot_pragma_ms_pointers_to_members:
1619 return CouldBeBitfield ||
1622 case tok::kw___cdecl:
1623 case tok::kw___fastcall:
1624 case tok::kw___stdcall:
1625 case tok::kw___thiscall:
1626 case tok::kw___vectorcall:
1632 case tok::kw_volatile:
1633 case tok::kw_restrict:
1634 case tok::kw__Atomic:
1635 case tok::kw___unaligned:
1639 case tok::kw_inline:
1640 case tok::kw_virtual:
1641 case tok::kw_friend:
1643 case tok::kw_static:
1644 case tok::kw_extern:
1645 case tok::kw_typedef:
1646 case tok::kw_register:
1648 case tok::kw_mutable:
1649 case tok::kw_thread_local:
1650 case tok::kw_constexpr:
1651 case tok::kw_consteval:
1652 case tok::kw_constinit:
1668 if (!isKnownToBeTypeSpecifier(
NextToken()))
1725 ParsedTemplateInfo &TemplateInfo,
1727 DeclSpecContext DSC,
1730 if (TagTokKind == tok::kw_struct)
1732 else if (TagTokKind == tok::kw___interface)
1734 else if (TagTokKind == tok::kw_class)
1737 assert(TagTokKind == tok::kw_union &&
"Not a class specifier");
1741 if (Tok.
is(tok::code_completion)) {
1755 const bool shouldDelayDiagsInTag =
1756 (TemplateInfo.Kind != ParsedTemplateInfo::NonTemplate);
1762 MaybeParseAttributes(PAKM_CXX11 | PAKM_Declspec | PAKM_GNU, attrs);
1764 if (Tok.
isOneOf(tok::kw___single_inheritance,
1765 tok::kw___multiple_inheritance,
1766 tok::kw___virtual_inheritance)) {
1767 ParseMicrosoftInheritanceClassAttributes(attrs);
1770 if (Tok.
is(tok::kw__Nullable)) {
1771 ParseNullabilityClassAttributes(attrs);
1785#include
"clang/Basic/TransformTypeTraits.def"
1786 tok::kw___is_abstract,
1787 tok::kw___is_aggregate,
1788 tok::kw___is_arithmetic,
1790 tok::kw___is_assignable,
1791 tok::kw___is_base_of,
1792 tok::kw___is_bounded_array,
1794 tok::kw___is_complete_type,
1795 tok::kw___is_compound,
1797 tok::kw___is_constructible,
1798 tok::kw___is_convertible,
1799 tok::kw___is_convertible_to,
1800 tok::kw___is_destructible,
1803 tok::kw___is_floating_point,
1805 tok::kw___is_function,
1806 tok::kw___is_fundamental,
1807 tok::kw___is_integral,
1808 tok::kw___is_interface_class,
1809 tok::kw___is_literal,
1810 tok::kw___is_lvalue_expr,
1811 tok::kw___is_lvalue_reference,
1812 tok::kw___is_member_function_pointer,
1813 tok::kw___is_member_object_pointer,
1814 tok::kw___is_member_pointer,
1815 tok::kw___is_nothrow_assignable,
1816 tok::kw___is_nothrow_constructible,
1817 tok::kw___is_nothrow_convertible,
1818 tok::kw___is_nothrow_destructible,
1819 tok::kw___is_object,
1821 tok::kw___is_pointer,
1822 tok::kw___is_polymorphic,
1823 tok::kw___is_reference,
1824 tok::kw___is_referenceable,
1825 tok::kw___is_rvalue_expr,
1826 tok::kw___is_rvalue_reference,
1828 tok::kw___is_scalar,
1829 tok::kw___is_scoped_enum,
1830 tok::kw___is_sealed,
1831 tok::kw___is_signed,
1832 tok::kw___is_standard_layout,
1833 tok::kw___is_trivial,
1834 tok::kw___is_trivially_equality_comparable,
1835 tok::kw___is_trivially_assignable,
1836 tok::kw___is_trivially_constructible,
1837 tok::kw___is_trivially_copyable,
1838 tok::kw___is_unbounded_array,
1840 tok::kw___is_unsigned,
1842 tok::kw___is_volatile
1849 TryKeywordIdentFallback(
true);
1851 struct PreserveAtomicIdentifierInfoRAII {
1852 PreserveAtomicIdentifierInfoRAII(
Token &Tok,
bool Enabled)
1853 : AtomicII(nullptr) {
1856 assert(Tok.
is(tok::kw__Atomic));
1861 ~PreserveAtomicIdentifierInfoRAII() {
1864 AtomicII->revertIdentifierToTokenID(tok::kw__Atomic);
1874 bool ShouldChangeAtomicToIdentifier =
getLangOpts().MSVCCompat &&
1875 Tok.
is(tok::kw__Atomic) &&
1877 PreserveAtomicIdentifierInfoRAII AtomicTokenGuard(
1878 Tok, ShouldChangeAtomicToIdentifier);
1888 if (TemplateInfo.TemplateParams)
1891 bool HasValidSpec =
true;
1892 if (ParseOptionalCXXScopeSpecifier(Spec,
nullptr,
1896 HasValidSpec =
false;
1899 if (Tok.
isNot(tok::identifier) && Tok.
isNot(tok::annot_template_id)) {
1900 Diag(Tok, diag::err_expected) << tok::identifier;
1901 HasValidSpec =
false;
1909 auto RecoverFromUndeclaredTemplateName = [&](
IdentifierInfo *Name,
1912 bool KnownUndeclared) {
1913 Diag(NameLoc, diag::err_explicit_spec_non_template)
1914 << (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation)
1915 << TagTokKind << Name << TemplateArgRange << KnownUndeclared;
1919 if (TemplateParams && TemplateInfo.LastParameterListWasEmpty) {
1920 if (TemplateParams->size() > 1) {
1921 TemplateParams->pop_back();
1923 TemplateParams =
nullptr;
1924 TemplateInfo.Kind = ParsedTemplateInfo::NonTemplate;
1926 }
else if (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation) {
1928 TemplateParams =
nullptr;
1929 TemplateInfo.Kind = ParsedTemplateInfo::NonTemplate;
1939 if (Tok.
is(tok::identifier)) {
1948 TemplateArgList TemplateArgs;
1950 if (ParseTemplateIdAfterTemplateName(
true, LAngleLoc, TemplateArgs,
1956 RecoverFromUndeclaredTemplateName(
1957 Name, NameLoc,
SourceRange(LAngleLoc, RAngleLoc),
false);
1959 }
else if (Tok.
is(tok::annot_template_id)) {
1960 TemplateId = takeTemplateIdAnnotation(Tok);
1961 NameLoc = ConsumeAnnotationToken();
1968 RecoverFromUndeclaredTemplateName(
1971 TemplateId =
nullptr;
1984 Diag(TemplateId->
LAngleLoc, diag::err_template_spec_syntax_non_template)
1985 << TemplateId->
Name <<
static_cast<int>(TemplateId->
Kind) <<
Range;
2020 MaybeParseCXX11Attributes(Attributes);
2029 Tok.
isOneOf(tok::comma, tok::ellipsis))
2032 AllowDefiningTypeSpec::No ||
2035 else if (Tok.
is(tok::l_brace) ||
2036 (DSC != DeclSpecContext::DSC_association &&
2038 (isClassCompatibleKeyword() &&
2054 }
else if (isClassCompatibleKeyword() &&
2061 TentativeParsingAction PA(*
this);
2064 while (isClassCompatibleKeyword()) {
2070 if (Tok.
is(tok::l_square) &&
NextToken().is(tok::l_square)) {
2074 }
else if (Tok.
is(tok::kw_alignas) &&
NextToken().is(tok::l_paren)) {
2084 if (!
T.consumeOpen())
2092 if (Tok.
isOneOf(tok::l_brace, tok::colon))
2098 }
else if (!isTypeSpecifier(DSC) &&
2099 (Tok.
is(tok::semi) ||
2102 if (Tok.
isNot(tok::semi)) {
2105 ExpectAndConsume(tok::semi, diag::err_expected_after,
2123 auto *FirstAttr = Attributes.
empty() ? nullptr : &Attributes.
front();
2125 (FirstAttr && FirstAttr->isRegularKeywordAttribute()
2126 ?
Diag(
Loc, diag::err_keyword_not_allowed) << FirstAttr
2127 :
Diag(
Loc, diag::err_attributes_not_allowed))
2139 if (!Name && !TemplateId &&
2144 Diag(StartLoc, diag::err_anon_type_definition)
2171 }
else if (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation &&
2174 ProhibitCXX11Attributes(attrs, diag::err_attributes_not_allowed,
2175 diag::err_keyword_not_allowed,
2179 getCurScope(), TemplateInfo.ExternLoc, TemplateInfo.TemplateLoc,
2190 TemplateInfo.Kind == ParsedTemplateInfo::NonTemplate)) {
2191 ProhibitCXX11Attributes(attrs, diag::err_attributes_not_allowed,
2192 diag::err_keyword_not_allowed,
2202 if (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation) {
2215 "Expected a definition here");
2219 TemplateParams =
nullptr;
2224 diag::err_explicit_instantiation_with_definition)
2233 LAngleLoc,
nullptr));
2234 TemplateParams = &FakedParamLists;
2241 SS, *TemplateId, attrs,
2244 TemplateParams ? TemplateParams->size() : 0),
2247 }
else if (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation &&
2254 ProhibitAttributes(attrs);
2257 getCurScope(), TemplateInfo.ExternLoc, TemplateInfo.TemplateLoc,
2258 TagType, StartLoc, SS, Name, NameLoc, attrs);
2260 TemplateInfo.Kind != ParsedTemplateInfo::NonTemplate) {
2261 ProhibitCXX11Attributes(attrs, diag::err_attributes_not_allowed,
2262 diag::err_keyword_not_allowed,
2278 if (Tok.
is(tok::comma)) {
2280 diag::err_friend_template_decl_multiple_specifiers);
2286 NameLoc, EllipsisLoc, attrs,
2288 TemplateParams ? TemplateParams->size() : 0));
2291 ProhibitCXX11Attributes(attrs, diag::err_attributes_not_allowed,
2292 diag::err_keyword_not_allowed,
2296 TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation) {
2299 Diag(Tok, diag::err_template_defn_explicit_instantiation)
2301 TemplateParams =
nullptr;
2304 bool IsDependent =
false;
2314 stripTypeAttributesOffDeclSpec(attrs, DS, TUK);
2317 TagOrTempResult = Actions.
ActOnTag(
2321 DSC == DeclSpecContext::DSC_type_specifier,
2322 DSC == DeclSpecContext::DSC_template_param ||
2323 DSC == DeclSpecContext::DSC_template_type_arg,
2324 OffsetOfState, &SkipBody);
2331 Name, StartLoc, NameLoc);
2338 if (shouldDelayDiagsInTag) {
2339 diagsFromTag.done();
2341 TemplateInfo.Kind == ParsedTemplateInfo::Template)
2342 diagsFromTag.redelay();
2347 assert(Tok.
is(tok::l_brace) ||
2349 isClassCompatibleKeyword());
2351 SkipCXXMemberSpecification(StartLoc, AttrFixitLoc,
TagType,
2352 TagOrTempResult.
get());
2354 ParseCXXMemberSpecification(StartLoc, AttrFixitLoc, attrs,
TagType,
2355 TagOrTempResult.
get());
2360 ParseStructUnionBody(StartLoc,
TagType, cast<RecordDecl>(
D));
2373 const char *PrevSpec =
nullptr;
2378 NameLoc.
isValid() ? NameLoc : StartLoc,
2380 }
else if (!TagOrTempResult.
isInvalid()) {
2382 TagType, StartLoc, NameLoc.
isValid() ? NameLoc : StartLoc, PrevSpec,
2383 DiagID, TagOrTempResult.
get(), Owned, Policy);
2390 Diag(StartLoc, DiagID) << PrevSpec;
2406 (TemplateInfo.Kind || !isValidAfterTypeSpecifier(
false))) {
2407 if (Tok.
isNot(tok::semi)) {
2409 ExpectAndConsume(tok::semi, diag::err_expected_after,
2427void Parser::ParseBaseClause(
Decl *ClassDecl) {
2428 assert(Tok.
is(tok::colon) &&
"Not a base clause");
2437 if (
Result.isInvalid()) {
2443 BaseInfo.push_back(
Result.get());
2468 bool IsVirtual =
false;
2472 MaybeParseCXX11Attributes(Attributes);
2478 CheckMisplacedCXX11Attribute(Attributes, StartLoc);
2488 CheckMisplacedCXX11Attribute(Attributes, StartLoc);
2492 if (Tok.
is(tok::kw_virtual)) {
2496 Diag(VirtualLoc, diag::err_dup_virtual)
2503 CheckMisplacedCXX11Attribute(Attributes, StartLoc);
2517 TypeResult BaseType = ParseBaseTypeSpecifier(BaseLoc, EndLocation);
2533 Access, BaseType.
get(), BaseLoc,
2548 case tok::kw_private:
2550 case tok::kw_protected:
2552 case tok::kw_public:
2561void Parser::HandleMemberFunctionDeclDelays(
Declarator &DeclaratorInfo,
2568 if (!NeedLateParse) {
2572 if (Param->hasUnparsedDefaultArg()) {
2573 NeedLateParse =
true;
2579 if (NeedLateParse) {
2582 auto LateMethod =
new LateParsedMethodDeclaration(
this, ThisDecl);
2583 getCurrentClass().LateParsedDeclarations.push_back(LateMethod);
2588 LateMethod->DefaultArgs.reserve(FTI.
NumParams);
2590 LateMethod->DefaultArgs.push_back(LateParsedDefaultArgument(
2627 if (II == Ident_override)
2630 if (II == Ident_sealed)
2633 if (II == Ident_abstract)
2636 if (II == Ident_final)
2639 if (II == Ident_GNU_final)
2650void Parser::ParseOptionalCXX11VirtSpecifierSeq(
VirtSpecifiers &VS,
2669 const char *PrevSpec =
nullptr;
2687 ? diag::warn_cxx98_compat_override_control_keyword
2688 : diag::ext_override_control_keyword)
2697bool Parser::isCXX11FinalKeyword()
const {
2706bool Parser::isClassCompatibleKeyword()
const {
2716bool Parser::ParseCXXMemberDeclaratorBeforeInitializer(
2718 LateParsedAttrList &LateParsedAttrs) {
2729 if (Tok.
isNot(tok::colon))
2730 ParseDeclarator(DeclaratorInfo);
2735 MaybeParseHLSLAnnotations(DeclaratorInfo,
nullptr,
2740 "don't know where identifier would go yet?");
2744 }
else if (Tok.
is(tok::kw_requires)) {
2745 ParseTrailingRequiresClause(DeclaratorInfo);
2747 ParseOptionalCXX11VirtSpecifierSeq(
2748 VS, getCurrentClass().IsInterface,
2751 MaybeParseAndDiagnoseDeclSpecAfterCXX11VirtSpecifierSeq(DeclaratorInfo,
2756 if (Tok.
is(tok::kw_asm)) {
2759 if (AsmLabel.isInvalid())
2769 DiagnoseAndSkipCXX11Attributes();
2770 MaybeParseGNUAttributes(DeclaratorInfo, &LateParsedAttrs);
2771 DiagnoseAndSkipCXX11Attributes();
2776 ParseOptionalCXX11VirtSpecifierSeq(
2777 VS, getCurrentClass().IsInterface,
2783 if (AL.isKnownToGCC() && !AL.isCXX11Attribute())
2784 Diag(AL.getLoc(), diag::warn_gcc_attribute_location);
2786 MaybeParseAndDiagnoseDeclSpecAfterCXX11VirtSpecifierSeq(DeclaratorInfo,
2803void Parser::MaybeParseAndDiagnoseDeclSpecAfterCXX11VirtSpecifierSeq(
2809 ParseTypeQualifierListOpt(
2810 DS, AR_NoAttributesParsed,
false,
2811 false, llvm::function_ref<
void()>([&]() {
2814 D.ExtendWithDeclSpec(DS);
2816 if (
D.isFunctionDeclarator()) {
2817 auto &
Function =
D.getFunctionTypeInfo();
2819 auto DeclSpecCheck = [&](
DeclSpec::TQ TypeQual, StringRef FixItName,
2822 auto &MQ =
Function.getOrCreateMethodQualifiers();
2823 if (!(MQ.getTypeQualifiers() & TypeQual)) {
2824 std::string Name(FixItName.data());
2827 MQ.SetTypeQual(TypeQual, SpecLoc);
2829 Diag(SpecLoc, diag::err_declspec_after_virtspec)
2838 bool RefQualifierIsLValueRef =
true;
2840 if (ParseRefQualifier(RefQualifierIsLValueRef, RefQualifierLoc)) {
2841 const char *Name = (RefQualifierIsLValueRef ?
"& " :
"&& ");
2844 Function.RefQualifierIsLValueRef = RefQualifierIsLValueRef;
2845 Function.RefQualifierLoc = RefQualifierLoc;
2847 Diag(RefQualifierLoc, diag::err_declspec_after_virtspec)
2848 << (RefQualifierIsLValueRef ?
"&" :
"&&")
2851 D.SetRangeEnd(RefQualifierLoc);
2910 "ParseCXXClassMemberDeclaration should only be called in C++ mode");
2911 if (Tok.
is(tok::at)) {
2913 Diag(Tok, diag::err_at_defs_cxx);
2915 Diag(Tok, diag::err_at_in_class);
2931 bool MalformedTypeSpec =
false;
2932 if (!TemplateInfo.Kind &&
2933 Tok.
isOneOf(tok::identifier, tok::coloncolon, tok::kw___super)) {
2935 MalformedTypeSpec =
true;
2938 if (Tok.
isNot(tok::annot_cxxscope))
2939 isAccessDecl =
false;
2940 else if (
NextToken().is(tok::identifier))
2941 isAccessDecl = GetLookAheadToken(2).
is(tok::semi);
2948 ParseOptionalCXXScopeSpecifier(SS,
nullptr,
2961 false,
false,
true,
true,
2962 false, &TemplateKWLoc, Name)) {
2968 if (ExpectAndConsume(tok::semi, diag::err_expected_after,
2969 "access declaration")) {
2985 if (!TemplateInfo.Kind &&
2986 Tok.
isOneOf(tok::kw_static_assert, tok::kw__Static_assert)) {
2992 if (Tok.
is(tok::kw_template)) {
2993 assert(!TemplateInfo.TemplateParams &&
2994 "Nested template improperly parsed?");
2998 DeclEnd, AccessAttrs, AS);
3002 if (Tok.
is(tok::kw___extension__)) {
3006 return ParseCXXClassMemberDeclaration(AS, AccessAttrs, TemplateInfo,
3012 MaybeParseCXX11Attributes(DeclAttrs);
3017 if (Tok.
is(tok::annot_attr_openmp))
3018 return ParseOpenMPDeclarativeDirectiveWithExtDecl(AS, DeclAttrs);
3020 if (Tok.
is(tok::kw_using)) {
3025 while (Tok.
is(tok::kw_template)) {
3027 Diag(TemplateLoc, diag::err_unexpected_template_after_using)
3031 if (Tok.
is(tok::kw_namespace)) {
3032 Diag(UsingLoc, diag::err_using_namespace_in_class);
3039 UsingLoc, DeclEnd, DeclAttrs, AS);
3043 MaybeParseMicrosoftAttributes(DeclSpecAttrs);
3046 LateParsedAttrList CommonLateParsedAttrs;
3053 if (MalformedTypeSpec)
3061 bool IsTemplateSpecOrInst =
3062 (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation ||
3063 TemplateInfo.Kind == ParsedTemplateInfo::ExplicitSpecialization);
3066 ParseDeclarationSpecifiers(DS, TemplateInfo, AS, DeclSpecContext::DSC_class,
3067 &CommonLateParsedAttrs);
3069 if (IsTemplateSpecOrInst)
3070 diagsFromTag.done();
3078 TemplateInfo.Kind == ParsedTemplateInfo::NonTemplate &&
3079 DiagnoseMissingSemiAfterTagDefinition(DS, AS, DeclSpecContext::DSC_class,
3080 &CommonLateParsedAttrs))
3084 TemplateInfo.TemplateParams ? TemplateInfo.TemplateParams->data()
3086 TemplateInfo.TemplateParams ? TemplateInfo.TemplateParams->size() : 0);
3090 ProhibitAttributes(DeclAttrs);
3094 getCurScope(), AS, DS, DeclAttrs, TemplateParams,
false, AnonRecord);
3096 DS.complete(TheDecl);
3098 Decl *decls[] = {AnonRecord, TheDecl};
3111 ? diag::warn_cxx23_variadic_friends
3112 : diag::ext_variadic_friends);
3125 AnonRecord, VariadicLoc);
3136 if (ParsedFriendDecl(DS))
3141 const char *PrevSpec =
nullptr;
3142 unsigned DiagId = 0;
3144 ParseDeclarationSpecifiers(
DeclSpec, TemplateInfo, AS,
3145 DeclSpecContext::DSC_class,
nullptr);
3150 ExpectAndConsume(tok::semi, diag::err_expected_semi_after_stmt,
3151 "friend declaration");
3159 if (Tok.
is(tok::kw_concept)) {
3163 ? llvm::to_underlying(diag::err_friend_concept)
3164 : llvm::to_underlying(
3166 err_concept_decls_may_only_appear_in_global_namespace_scope));
3173 if (TemplateInfo.TemplateParams)
3178 LateParsedAttrList LateParsedAttrs;
3183 auto TryConsumePureSpecifier = [&](
bool AllowDefinition) {
3184 if (Tok.
isNot(tok::equal))
3189 if (
Zero.isNot(tok::numeric_constant) ||
3193 auto &
After = GetLookAheadToken(2);
3194 if (!
After.isOneOf(tok::semi, tok::comma) &&
3195 !(AllowDefinition &&
3196 After.isOneOf(tok::l_brace, tok::colon, tok::kw_try)))
3207 bool ExpectSemi =
true;
3215 if (ParseCXXMemberDeclaratorBeforeInitializer(
3216 DeclaratorInfo, VS, BitfieldSize, LateParsedAttrs)) {
3221 if (IsTemplateSpecOrInst)
3229 TryConsumePureSpecifier(
true);
3240 if (Tok.
isOneOf(tok::l_brace, tok::colon, tok::kw_try)) {
3242 }
else if (Tok.
is(tok::equal)) {
3244 if (KW.
is(tok::kw_default))
3246 else if (KW.
is(tok::kw_delete))
3248 else if (KW.
is(tok::code_completion)) {
3265 ProhibitAttributes(DeclAttrs);
3282 diag::err_function_declared_typedef);
3288 Decl *FunDecl = ParseCXXInlineMethodDef(AS, AccessAttrs, DeclaratorInfo,
3289 TemplateInfo, VS, PureSpecLoc);
3292 for (
unsigned i = 0, ni = CommonLateParsedAttrs.size(); i < ni; ++i) {
3293 CommonLateParsedAttrs[i]->addDecl(FunDecl);
3295 for (
unsigned i = 0, ni = LateParsedAttrs.size(); i < ni; ++i) {
3296 LateParsedAttrs[i]->addDecl(FunDecl);
3299 LateParsedAttrs.clear();
3302 if (Tok.
is(tok::semi))
3303 ConsumeExtraSemi(AfterMemberFunctionDefinition);
3315 bool HasStaticInitializer =
false;
3320 Diag(Tok, diag::err_anon_bitfield_member_init);
3324 if (!TryConsumePureSpecifier(
false))
3326 HasStaticInitializer =
true;
3332 TemplateInfo.Kind == ParsedTemplateInfo::NonTemplate) {
3334 if (BitfieldSize.
get())
3336 ? diag::warn_cxx17_compat_bitfield_member_init
3337 : diag::ext_bitfield_member_init);
3340 HasStaticInitializer =
true;
3356 if (AL.isCXX11Attribute() || AL.isRegularKeywordAttribute()) {
3357 auto Loc = AL.getRange().getBegin();
3358 (AL.isRegularKeywordAttribute()
3359 ?
Diag(
Loc, diag::err_keyword_not_allowed) << AL
3360 :
Diag(
Loc, diag::err_attributes_not_allowed))
3368 getCurScope(), AS, DeclaratorInfo, TemplateParams, BitfieldSize.
get(),
3369 VS, HasInClassInit);
3372 ThisDecl ? dyn_cast<VarTemplateDecl>(ThisDecl) :
nullptr)
3375 ThisDecl = VT->getTemplatedDecl();
3384 DeclaratorInfo.getDeclSpec().getStorageClassSpec() ==
3387 HasStaticInitializer =
true;
3391 Diag(PureSpecLoc, diag::err_duplicate_virt_specifier) <<
"abstract";
3393 if (ThisDecl && PureSpecLoc.
isValid())
3402 ? diag::warn_cxx98_compat_nonstatic_member_init
3403 : diag::ext_nonstatic_member_init);
3405 if (DeclaratorInfo.isArrayOfUnknownBound()) {
3411 Diag(Tok, diag::err_incomplete_array_member_init);
3418 ParseCXXNonStaticMemberInitializer(ThisDecl);
3419 }
else if (HasStaticInitializer) {
3422 ThisDecl, DeclaratorInfo.isDeclarationOfFunction(), EqualLoc);
3424 if (
Init.isInvalid()) {
3428 }
else if (ThisDecl)
3431 }
else if (ThisDecl && DeclaratorInfo.isStaticMember())
3438 for (
unsigned i = 0, ni = CommonLateParsedAttrs.size(); i < ni; ++i)
3439 CommonLateParsedAttrs[i]->addDecl(ThisDecl);
3441 for (
unsigned i = 0, ni = LateParsedAttrs.size(); i < ni; ++i)
3442 LateParsedAttrs[i]->addDecl(ThisDecl);
3445 DeclsInGroup.push_back(ThisDecl);
3447 if (DeclaratorInfo.isFunctionDeclarator() &&
3448 DeclaratorInfo.getDeclSpec().getStorageClassSpec() !=
3450 HandleMemberFunctionDeclDelays(DeclaratorInfo, ThisDecl);
3452 LateParsedAttrs.clear();
3454 DeclaratorInfo.complete(ThisDecl);
3467 Diag(CommaLoc, diag::err_expected_semi_declaration)
3477 if (TemplateInfo.Kind != ParsedTemplateInfo::NonTemplate &&
3478 DeclaratorInfo.isFirstDeclarator()) {
3479 Diag(CommaLoc, diag::err_multiple_template_declarators)
3480 << TemplateInfo.Kind;
3484 DeclaratorInfo.clear();
3488 DeclaratorInfo.setCommaLoc(CommaLoc);
3493 DiagnoseAndSkipCXX11Attributes();
3494 MaybeParseGNUAttributes(DeclaratorInfo);
3495 DiagnoseAndSkipCXX11Attributes();
3497 if (ParseCXXMemberDeclaratorBeforeInitializer(
3498 DeclaratorInfo, VS, BitfieldSize, LateParsedAttrs))
3503 ExpectAndConsume(tok::semi, diag::err_expected_semi_decl_list)) {
3536 assert(Tok.
isOneOf(tok::equal, tok::l_brace) &&
3537 "Data member initializer not starting with '=' or '{'");
3539 bool IsFieldInitialization = isa_and_present<FieldDecl>(
D);
3543 IsFieldInitialization
3552 IsFieldInitialization;
3555 if (Tok.
is(tok::kw_delete)) {
3562 if (IsFunction || Next.isOneOf(tok::semi, tok::comma, tok::eof)) {
3568 SkipDeletedFunctionBody();
3571 }
else if (Tok.
is(tok::kw_default)) {
3573 Diag(Tok, diag::err_default_delete_in_multiple_declaration)
3581 if (
const auto *PD = dyn_cast_or_null<MSPropertyDecl>(
D)) {
3582 Diag(Tok, diag::err_ms_property_initializer) << PD;
3585 return ParseInitializer();
3593 assert(isCXX11FinalKeyword() &&
"not a class definition");
3599 CheckMisplacedCXX11Attribute(Attrs, AttrFixitLoc);
3604 if (Tok.
isNot(tok::colon) && Tok.
isNot(tok::l_brace))
3611 if (Tok.
is(tok::colon)) {
3614 ParsingClassDefinition ParsingDef(*
this,
TagDecl,
true,
3620 ParseBaseClause(
nullptr);
3624 if (!Tok.
is(tok::l_brace)) {
3626 diag::err_expected_lbrace_after_base_specifiers);
3632 assert(Tok.
is(tok::l_brace));
3638 if (Tok.
is(tok::kw___attribute)) {
3640 MaybeParseGNUAttributes(Attrs);
3650 case tok::kw___if_exists:
3651 case tok::kw___if_not_exists:
3652 ParseMicrosoftIfExistsClassDeclaration(
TagType, AccessAttrs, AS);
3657 ConsumeExtraSemi(InsideStruct,
TagType);
3661 case tok::annot_pragma_vis:
3662 HandlePragmaVisibility();
3664 case tok::annot_pragma_pack:
3667 case tok::annot_pragma_align:
3668 HandlePragmaAlign();
3670 case tok::annot_pragma_ms_pointers_to_members:
3671 HandlePragmaMSPointersToMembers();
3673 case tok::annot_pragma_ms_pragma:
3674 HandlePragmaMSPragma();
3676 case tok::annot_pragma_ms_vtordisp:
3677 HandlePragmaMSVtorDisp();
3679 case tok::annot_pragma_dump:
3683 case tok::kw_namespace:
3685 DiagnoseUnexpectedNamespace(cast<NamedDecl>(
TagDecl));
3688 case tok::kw_private:
3692 ParsedTemplateInfo TemplateInfo;
3693 return ParseCXXClassMemberDeclaration(AS, AccessAttrs, TemplateInfo);
3696 case tok::kw_public:
3697 case tok::kw_protected: {
3707 AccessAttrs.
clear();
3708 MaybeParseGNUAttributes(AccessAttrs);
3713 Diag(EndLoc, diag::err_expected)
3717 Diag(EndLoc, diag::err_expected)
3729 AccessAttrs.
clear();
3735 case tok::annot_attr_openmp:
3736 case tok::annot_pragma_openmp:
3737 return ParseOpenMPDeclarativeDirectiveWithExtDecl(
3739 case tok::annot_pragma_openacc:
3747 ConsumeAnnotationToken();
3750 ParsedTemplateInfo TemplateInfo;
3751 return ParseCXXClassMemberDeclaration(AS, AccessAttrs, TemplateInfo);
3768 "Invalid TagType!");
3770 llvm::TimeTraceScope TimeScope(
"ParseClass", [&]() {
3771 if (
auto *TD = dyn_cast_or_null<NamedDecl>(
TagDecl))
3772 return TD->getQualifiedNameAsString();
3773 return std::string(
"<anonymous>");
3777 "parsing struct/union/class body");
3781 bool NonNestedClass =
true;
3782 if (!ClassStack.empty()) {
3784 if (S->isClassScope()) {
3786 NonNestedClass =
false;
3789 if (getCurrentClass().IsInterface) {
3793 ? cast<NamedDecl>(
TagDecl)->getQualifiedNameAsString()
3799 if (S->isFunctionScope())
3810 ParsingClassDefinition ParsingDef(*
this,
TagDecl, NonNestedClass,
3818 bool IsFinalSpelledSealed =
false;
3819 bool IsAbstract =
false;
3827 if (isCXX11FinalKeyword()) {
3830 Diag(Skipped, diag::err_duplicate_class_virt_specifier)
3835 IsFinalSpelledSealed =
true;
3840 Diag(Skipped, diag::err_duplicate_class_virt_specifier)
3848 Diag(FinalLoc, diag::err_override_control_interface)
3852 ? diag::warn_cxx98_compat_override_control_keyword
3853 : diag::ext_override_control_keyword)
3856 Diag(FinalLoc, diag::ext_ms_sealed_keyword);
3858 Diag(AbstractLoc, diag::ext_ms_abstract_keyword);
3860 Diag(FinalLoc, diag::ext_warn_gnu_final);
3863 "not a class definition");
3869 CheckMisplacedCXX11Attribute(Attrs, AttrFixitLoc);
3878 if (!Tok.
is(tok::colon) && !Tok.
is(tok::l_brace)) {
3885 if (Tok.
is(tok::colon)) {
3886 ParseScope InheritanceScope(
this,
getCurScope()->getFlags() |
3890 if (!Tok.
is(tok::l_brace)) {
3891 bool SuggestFixIt =
false;
3895 case tok::kw_private:
3896 case tok::kw_protected:
3897 case tok::kw_public:
3900 case tok::kw_static_assert:
3904 case tok::kw_template:
3905 SuggestFixIt =
true;
3907 case tok::identifier:
3908 SuggestFixIt = isConstructorDeclarator(
true);
3911 SuggestFixIt = isCXXSimpleDeclaration(
false);
3916 Diag(BraceLoc, diag::err_expected_lbrace_after_base_specifiers);
3930 assert(Tok.
is(tok::l_brace));
3936 IsFinalSpelledSealed, IsAbstract,
3937 T.getOpenLocation());
3952 while (!tryParseMisplacedModuleImport() && Tok.
isNot(tok::r_brace) &&
3953 Tok.
isNot(tok::eof)) {
3955 ParseCXXClassMemberDeclarationWithPragmas(
3957 MaybeDestroyTemplateIds();
3966 MaybeParseGNUAttributes(attrs);
3970 T.getOpenLocation(),
3971 T.getCloseLocation(), attrs);
3978 if (
TagDecl && NonNestedClass) {
3985 ParseLexedPragmas(getCurrentClass());
3986 ParseLexedAttributes(getCurrentClass());
3987 ParseLexedMethodDeclarations(getCurrentClass());
3992 ParseLexedMemberInitializers(getCurrentClass());
3993 ParseLexedMethodDefs(getCurrentClass());
3994 PrevTokLocation = SavedPrevTokLocation;
4009void Parser::DiagnoseUnexpectedNamespace(
NamedDecl *
D) {
4010 assert(Tok.
is(tok::kw_namespace));
4049void Parser::ParseConstructorInitializer(
Decl *ConstructorDecl) {
4050 assert(Tok.
is(tok::colon) &&
4051 "Constructor initializer always starts with ':'");
4059 bool AnyErrors =
false;
4062 if (Tok.
is(tok::code_completion)) {
4065 ConstructorDecl, MemInitializers);
4069 MemInitResult MemInit = ParseMemInitializer(ConstructorDecl);
4071 MemInitializers.push_back(MemInit.
get());
4075 if (Tok.
is(tok::comma))
4077 else if (Tok.
is(tok::l_brace))
4082 Tok.
isOneOf(tok::identifier, tok::coloncolon)) {
4084 Diag(
Loc, diag::err_ctor_init_missing_comma)
4090 << tok::l_brace << tok::comma;
4115 if (ParseOptionalCXXScopeSpecifier(SS,
nullptr,
4128 if (Tok.
is(tok::identifier)) {
4133 }
else if (Tok.
is(tok::annot_decltype)) {
4138 ParseDecltypeSpecifier(DS);
4139 }
else if (Tok.
is(tok::annot_pack_indexing_type)) {
4142 ParsePackIndexingType(DS);
4145 ? takeTemplateIdAnnotation(Tok)
4150 assert(Tok.
is(tok::annot_typename) &&
"template-id -> type failed");
4152 ConsumeAnnotationToken();
4154 Diag(Tok, diag::err_expected_member_or_base_name);
4161 Diag(Tok, diag::warn_cxx98_compat_generalized_initializer_lists);
4164 ExprResult InitList = ParseBraceInitializer();
4174 TemplateTypeTy.
get(), DS, IdLoc,
4175 InitList.
get(), EllipsisLoc);
4176 }
else if (Tok.
is(tok::l_paren)) {
4181 ExprVector ArgExprs;
4182 auto RunSignatureHelp = [&] {
4187 ConstructorDecl, SS, TemplateTypeTy.
get(), ArgExprs, II,
4188 T.getOpenLocation(),
false);
4189 CalledSignatureHelp =
true;
4190 return PreferredType;
4192 if (Tok.
isNot(tok::r_paren) && ParseExpressionList(ArgExprs, [&] {
4193 PreferredType.enterFunctionArgument(Tok.
getLocation(),
4210 ConstructorDecl,
getCurScope(), SS, II, TemplateTypeTy.
get(), DS, IdLoc,
4211 T.getOpenLocation(), ArgExprs,
T.getCloseLocation(), EllipsisLoc);
4218 return Diag(Tok, diag::err_expected_either) << tok::l_paren << tok::l_brace;
4220 return Diag(Tok, diag::err_expected) << tok::l_paren;
4238 ExceptionSpecTokens =
nullptr;
4242 if (Tok.
isNot(tok::kw_throw) && Tok.
isNot(tok::kw_noexcept))
4246 bool IsNoexcept = Tok.
is(tok::kw_noexcept);
4247 Token StartTok = Tok;
4251 if (!Tok.
is(tok::l_paren)) {
4254 Diag(Tok, diag::warn_cxx98_compat_noexcept_decl);
4255 NoexceptExpr =
nullptr;
4259 Diag(Tok, diag::err_expected_lparen_after) <<
"throw";
4265 ExceptionSpecTokens->push_back(StartTok);
4266 ExceptionSpecTokens->push_back(Tok);
4267 SpecificationRange.
setEnd(ConsumeParen());
4269 ConsumeAndStoreUntil(tok::r_paren, *ExceptionSpecTokens,
4272 SpecificationRange.
setEnd(ExceptionSpecTokens->back().getLocation());
4278 if (Tok.
is(tok::kw_throw)) {
4279 Result = ParseDynamicExceptionSpecification(
4280 SpecificationRange, DynamicExceptions, DynamicExceptionRanges);
4281 assert(DynamicExceptions.size() == DynamicExceptionRanges.size() &&
4282 "Produced different number of exception types and ranges.");
4286 if (Tok.
isNot(tok::kw_noexcept))
4289 Diag(Tok, diag::warn_cxx98_compat_noexcept_decl);
4297 if (Tok.
is(tok::l_paren)) {
4310 NoexceptRange =
SourceRange(KeywordLoc,
T.getCloseLocation());
4317 NoexceptRange =
SourceRange(KeywordLoc, KeywordLoc);
4321 SpecificationRange = NoexceptRange;
4326 if (Tok.
is(tok::kw_throw)) {
4327 Diag(Tok.
getLocation(), diag::err_dynamic_and_noexcept_specification);
4328 ParseDynamicExceptionSpecification(NoexceptRange, DynamicExceptions,
4329 DynamicExceptionRanges);
4332 Diag(Tok.
getLocation(), diag::err_dynamic_and_noexcept_specification);
4340 if (
P.getLangOpts().CPlusPlus11) {
4341 const char *Replacement = IsNoexcept ?
"noexcept" :
"noexcept(false)";
4343 ? diag::ext_dynamic_exception_spec
4344 : diag::warn_exception_spec_deprecated)
4365 assert(Tok.
is(tok::kw_throw) &&
"expected throw");
4369 if (
T.consumeOpen()) {
4370 Diag(Tok, diag::err_expected_lparen_after) <<
"throw";
4377 if (Tok.
is(tok::ellipsis)) {
4380 Diag(EllipsisLoc, diag::ext_ellipsis_exception_spec);
4382 SpecificationRange.
setEnd(
T.getCloseLocation());
4389 while (Tok.
isNot(tok::r_paren)) {
4392 if (Tok.
is(tok::ellipsis)) {
4398 if (!Res.isInvalid())
4402 if (!Res.isInvalid()) {
4403 Exceptions.push_back(Res.get());
4404 Ranges.push_back(
Range);
4412 SpecificationRange.
setEnd(
T.getCloseLocation());
4414 Exceptions.empty());
4421 bool MayBeFollowedByDirectInit) {
4422 assert(Tok.
is(tok::arrow) &&
"expected arrow");
4432void Parser::ParseTrailingRequiresClause(
Declarator &
D) {
4433 assert(Tok.
is(tok::kw_requires) &&
"expected requires");
4451 DeclaratorScopeObj DeclScopeObj(*
this, SS);
4453 DeclScopeObj.EnterDeclaratorScope();
4462 std::optional<Sema::CXXThisScopeRAII> ThisScope;
4463 InitCXXThisScopeForDeclaratorIfRelevant(
D,
D.getDeclSpec(), ThisScope);
4465 TrailingRequiresClause =
4468 TrailingRequiresClause =
4471 if (!
D.isDeclarationOfFunction()) {
4473 diag::err_requires_clause_on_declarator_not_declaring_a_function);
4478 SkipUntil({tok::l_brace, tok::arrow, tok::kw_try, tok::comma, tok::colon},
4481 D.setTrailingRequiresClause(TrailingRequiresClause.
get());
4484 if (
D.isFunctionDeclarator() && Tok.
is(tok::arrow) &&
4485 D.getDeclSpec().getTypeSpecType() ==
TST_auto) {
4489 ParseTrailingReturnType(
Range,
false);
4493 diag::err_requires_clause_must_appear_after_trailing_return)
4495 auto &FunctionChunk =
D.getFunctionTypeInfo();
4496 FunctionChunk.HasTrailingReturnType = TrailingReturnType.
isUsable();
4497 FunctionChunk.TrailingReturnType = TrailingReturnType.
get();
4500 SkipUntil({tok::equal, tok::l_brace, tok::arrow, tok::kw_try, tok::comma},
4509 bool NonNestedClass,
4511 assert((NonNestedClass || !ClassStack.empty()) &&
4512 "Nested class without outer class");
4513 ClassStack.push(
new ParsingClass(ClassDecl, NonNestedClass, IsInterface));
4519void Parser::DeallocateParsedClasses(Parser::ParsingClass *
Class) {
4520 for (
unsigned I = 0, N =
Class->LateParsedDeclarations.size(); I != N; ++I)
4521 delete Class->LateParsedDeclarations[I];
4532 assert(!ClassStack.empty() &&
"Mismatched push/pop for class parsing");
4536 ParsingClass *Victim = ClassStack.top();
4538 if (Victim->TopLevelClass) {
4541 DeallocateParsedClasses(Victim);
4544 assert(!ClassStack.empty() &&
"Missing top-level class?");
4546 if (Victim->LateParsedDeclarations.empty()) {
4551 DeallocateParsedClasses(Victim);
4559 "Nested class outside of class scope?");
4560 ClassStack.top()->LateParsedDeclarations.push_back(
4561 new LateParsedClass(
this, Victim));
4587 case tok::code_completion:
4594 case tok::numeric_constant: {
4602 StringRef Spelling = PP.
getSpelling(ExpansionLoc, ExpansionBuf);
4603 if (Spelling ==
"__clang__") {
4607 Diag(Tok, diag::warn_wrong_clang_attr_namespace)
4623 case tok::pipeequal:
4624 case tok::caretequal:
4626 case tok::exclaimequal:
4632 StringRef Spelling = PP.
getSpelling(SpellingLoc, SpellingBuf);
4641void Parser::ParseOpenMPAttributeArgs(
const IdentifierInfo *AttrName,
4646 if (
T.consumeOpen()) {
4647 Diag(Tok, diag::err_expected) << tok::l_paren;
4651 if (AttrName->
isStr(
"directive")) {
4657 OMPBeginTok.
setKind(tok::annot_attr_openmp);
4659 OpenMPTokens.push_back(OMPBeginTok);
4661 ConsumeAndStoreUntil(tok::r_paren, OpenMPTokens,
false,
4665 OMPEndTok.
setKind(tok::annot_pragma_openmp_end);
4667 OpenMPTokens.push_back(OMPEndTok);
4669 assert(AttrName->
isStr(
"sequence") &&
4670 "Expected either 'directive' or 'sequence'");
4679 const IdentifierInfo *Ident = TryParseCXX11AttributeIdentifier(IdentLoc);
4683 if (Ident && Ident->
isStr(
"omp") && !ExpectAndConsume(tok::coloncolon))
4684 Ident = TryParseCXX11AttributeIdentifier(IdentLoc);
4688 if (!Ident || (!Ident->
isStr(
"directive") && !Ident->
isStr(
"sequence"))) {
4695 ParseOpenMPAttributeArgs(Ident, OpenMPTokens);
4709 case ParsedAttr::AT_CarriesDependency:
4710 case ParsedAttr::AT_Deprecated:
4711 case ParsedAttr::AT_FallThrough:
4712 case ParsedAttr::AT_CXX11NoReturn:
4713 case ParsedAttr::AT_NoUniqueAddress:
4714 case ParsedAttr::AT_Likely:
4715 case ParsedAttr::AT_Unlikely:
4717 case ParsedAttr::AT_WarnUnusedResult:
4718 return !ScopeName && AttrName->
getName() ==
"nodiscard";
4719 case ParsedAttr::AT_Unused:
4720 return !ScopeName && AttrName->
getName() ==
"maybe_unused";
4732 assert(Tok.
is(tok::l_paren) &&
"Not a C++11 attribute argument list");
4740 TentativeParsingAction TPA(*
this);
4743 if (Res.isInvalid()) {
4746 if (Tok.
is(tok::r_paren))
4751 if (!Tok.
isOneOf(tok::r_paren, tok::r_square)) {
4756 if (!Res.isInvalid()) {
4757 auto *
E = Res.get();
4796bool Parser::ParseCXX11AttributeArgs(
4800 assert(Tok.
is(tok::l_paren) &&
"Not a C++11 attribute argument list");
4804 LO.CPlusPlus ? ParsedAttr::Form::CXX11() :
ParsedAttr::Form::
C23();
4810 Form = ParsedAttr::Form::Microsoft();
4825 if (ScopeName && (ScopeName->
isStr(
"gnu") || ScopeName->
isStr(
"__gnu__"))) {
4828 ParseGNUAttributeArgs(AttrName, AttrNameLoc, Attrs, EndLoc, ScopeName,
4829 ScopeLoc, Form,
nullptr);
4834 if (ScopeName && ScopeName->
isStr(
"omp") &&
4835 (AttrName->
isStr(
"directive") || AttrName->
isStr(
"sequence"))) {
4837 ? diag::warn_omp51_compat_attributes
4838 : diag::ext_omp_attributes);
4840 ParseOpenMPAttributeArgs(AttrName, OpenMPTokens);
4849 if (ScopeName && (ScopeName->
isStr(
"clang") || ScopeName->
isStr(
"_Clang")))
4850 NumArgs = ParseClangAttributeArgs(AttrName, AttrNameLoc, Attrs, EndLoc,
4851 ScopeName, ScopeLoc, Form);
4853 else if (!ScopeName && AttrName->
isStr(
"assume")) {
4854 if (ParseCXXAssumeAttributeArg(Attrs, AttrName, AttrNameLoc, EndLoc, Form))
4858 NumArgs = ParseAttributeArgsCommon(AttrName, AttrNameLoc, Attrs, EndLoc,
4859 ScopeName, ScopeLoc, Form);
4861 if (!Attrs.
empty() &&
4867 Diag(LParenLoc, diag::warn_unknown_attribute_ignored) << AttrName;
4868 Attr.setInvalid(
true);
4876 if (
Attr.getMaxArgs() && !NumArgs) {
4879 Diag(LParenLoc, diag::err_attribute_requires_arguments) << AttrName;
4880 Attr.setInvalid(
true);
4881 }
else if (!
Attr.getMaxArgs()) {
4885 Diag(LParenLoc, diag::err_cxx11_attribute_forbids_arguments)
4888 Attr.setInvalid(
true);
4921 if (Tok.
is(tok::kw_alignas)) {
4928 ParseAlignmentSpecifier(Attrs, EndLoc);
4939 if (!Tok.
is(tok::l_paren))
4942 ParseAttributeArgsCommon(AttrName,
Loc, Attrs, EndLoc,
4946 Attrs.
addNew(AttrName,
Loc,
nullptr,
Loc,
nullptr, 0, Form);
4950 assert(Tok.
is(tok::l_square) &&
NextToken().is(tok::l_square) &&
4951 "Not a double square bracket attribute list");
4956 : diag::warn_ext_cxx11_attributes);
4959 : diag::warn_ext_c23_attributes);
4963 checkCompoundToken(OpenLoc, tok::l_square, CompoundToken::AttrBegin);
4968 if (Tok.
is(tok::kw_using)) {
4970 ? diag::warn_cxx14_compat_using_attribute_ns
4971 : diag::ext_using_attribute_ns);
4974 CommonScopeName = TryParseCXX11AttributeIdentifier(
4976 if (!CommonScopeName) {
4984 bool AttrParsed =
false;
4985 while (!Tok.
isOneOf(tok::r_square, tok::semi, tok::eof)) {
4989 if (ExpectAndConsume(tok::comma)) {
5003 AttrName = TryParseCXX11AttributeIdentifier(
5012 ScopeName = AttrName;
5015 AttrName = TryParseCXX11AttributeIdentifier(
5025 if (CommonScopeName) {
5027 Diag(ScopeLoc, diag::err_using_attribute_ns_conflict)
5030 ScopeName = CommonScopeName;
5031 ScopeLoc = CommonScopeLoc;
5036 if (Tok.
is(tok::l_paren))
5037 AttrParsed = ParseCXX11AttributeArgs(AttrName, AttrLoc, Attrs, EndLoc,
5038 ScopeName, ScopeLoc, OpenMPTokens);
5044 ScopeName, ScopeLoc,
nullptr, 0,
5046 : ParsedAttr::Form::C23());
5051 Diag(Tok, diag::err_cxx11_attribute_forbids_ellipsis) << AttrName;
5056 if (Tok.
is(tok::semi)) {
5062 if (ExpectAndConsume(tok::r_square))
5064 else if (Tok.
is(tok::r_square))
5065 checkCompoundToken(CloseLoc, tok::r_square, CompoundToken::AttrEnd);
5068 if (ExpectAndConsume(tok::r_square))
5081 ParseCXX11AttributeSpecifier(Attrs, &EndLoc);
5082 }
while (isAllowedCXX11AttributeSpecifier());
5087void Parser::DiagnoseAndSkipCXX11Attributes() {
5096 (Keyword ?
Diag(StartLoc, diag::err_keyword_not_allowed) << Keyword
5097 :
Diag(StartLoc, diag::err_attributes_not_allowed))
5105 if (!isCXX11AttributeSpecifier())
5109 if (Tok.
is(tok::l_square)) {
5113 EndLoc =
T.getCloseLocation();
5120 "not an attribute specifier");
5123 if (!
T.consumeOpen())
5125 EndLoc =
T.getCloseLocation();
5127 }
while (isCXX11AttributeSpecifier());
5134 assert(Tok.
is(tok::identifier) &&
"Not a Microsoft attribute list");
5136 assert(UuidIdent->
getName() ==
"uuid" &&
"Not a Microsoft attribute list");
5143 if (
T.consumeOpen()) {
5144 Diag(Tok, diag::err_expected) << tok::l_paren;
5149 if (isTokenStringLiteral()) {
5154 ArgExprs.push_back(StringResult.
get());
5171 while (Tok.
isNot(tok::r_paren)) {
5173 Diag(Tok, diag::err_attribute_uuid_malformed_guid);
5178 SpellingBuffer.resize(Tok.
getLength() + 1);
5180 StringRef TokSpelling = PP.
getSpelling(Tok, SpellingBuffer, &Invalid);
5185 StrBuffer += TokSpelling;
5191 Diag(Tok, diag::err_attribute_uuid_malformed_guid);
5201 Toks[0].
setKind(tok::string_literal);
5207 ArgExprs.push_back(UuidString);
5210 if (!
T.consumeClose()) {
5213 ParsedAttr::Form::Microsoft());
5226 assert(Tok.
is(tok::l_square) &&
"Not a Microsoft attribute list");
5237 SkipUntil(tok::r_square, tok::identifier,
5239 if (Tok.
is(tok::code_completion)) {
5247 if (Tok.
isNot(tok::identifier))
5250 ParseMicrosoftUuidAttributeArgs(Attrs);
5260 bool AttrParsed =
false;
5261 if (Tok.
is(tok::l_paren)) {
5264 ParseCXX11AttributeArgs(II, NameLoc, Attrs, &EndLoc,
nullptr,
5266 ReplayOpenMPAttributeTokens(OpenMPTokens);
5270 ParsedAttr::Form::Microsoft());