32#include "llvm/Support/TimeProfiler.h"
40 assert(Tok.is(tok::kw_namespace) &&
"Not a namespace!");
42 ObjCDeclContextSwitch ObjCDC(*
this);
44 if (Tok.is(tok::code_completion)) {
46 Actions.CodeCompletion().CodeCompleteNamespaceDecl(
getCurScope());
50 SourceLocation IdentLoc;
51 IdentifierInfo *Ident =
nullptr;
52 InnerNamespaceInfoList ExtraNSs;
53 SourceLocation FirstNestedInlineLoc;
55 ParsedAttributes attrs(AttrFactory);
57 while (MaybeParseGNUAttributes(attrs) || isAllowedCXX11AttributeSpecifier()) {
58 if (isAllowedCXX11AttributeSpecifier()) {
61 ? diag::warn_cxx14_compat_ns_enum_attribute
62 : diag::ext_ns_enum_attribute)
64 ParseCXX11Attributes(attrs);
68 if (Tok.is(tok::identifier)) {
69 Ident = Tok.getIdentifierInfo();
71 while (Tok.is(tok::coloncolon) &&
76 InnerNamespaceInfo Info;
79 if (Tok.is(tok::kw_inline)) {
82 FirstNestedInlineLoc = Info.InlineLoc;
85 Info.Ident = Tok.getIdentifierInfo();
88 ExtraNSs.push_back(Info);
92 DiagnoseAndSkipCXX11Attributes();
93 MaybeParseGNUAttributes(attrs);
94 DiagnoseAndSkipCXX11Attributes();
96 SourceLocation attrLoc = attrs.Range.getBegin();
99 if (!ExtraNSs.empty() && attrLoc.
isValid())
100 Diag(attrLoc, diag::err_unexpected_nested_namespace_attribute);
102 if (Tok.is(tok::equal)) {
104 Diag(Tok, diag::err_expected) << tok::identifier;
109 if (!ExtraNSs.empty()) {
110 Diag(ExtraNSs.front().NamespaceLoc,
111 diag::err_unexpected_qualified_namespace_alias)
112 << SourceRange(ExtraNSs.front().NamespaceLoc,
113 ExtraNSs.back().IdentLoc);
118 Diag(attrLoc, diag::err_unexpected_namespace_attributes_alias);
120 Diag(InlineLoc, diag::err_inline_namespace_alias)
122 Decl *NSAlias = ParseNamespaceAlias(NamespaceLoc, IdentLoc, Ident, DeclEnd);
123 return Actions.ConvertDeclToDeclGroup(NSAlias);
127 if (
T.consumeOpen()) {
129 Diag(Tok, diag::err_expected) << tok::l_brace;
131 Diag(Tok, diag::err_expected_either) << tok::identifier << tok::l_brace;
138 Diag(
T.getOpenLocation(), diag::err_namespace_nonnamespace_scope);
143 if (ExtraNSs.empty()) {
145 }
else if (InlineLoc.
isValid()) {
146 Diag(InlineLoc, diag::err_inline_nested_namespace_definition);
148 Diag(ExtraNSs[0].NamespaceLoc,
149 diag::warn_cxx14_compat_nested_namespace_definition);
150 if (FirstNestedInlineLoc.
isValid())
151 Diag(FirstNestedInlineLoc,
152 diag::warn_cxx17_compat_inline_nested_namespace_definition);
154 Diag(ExtraNSs[0].NamespaceLoc,
155 diag::warn_cxx14_compat_nested_namespace_definition);
156 if (FirstNestedInlineLoc.
isValid())
157 Diag(FirstNestedInlineLoc, diag::ext_inline_nested_namespace_definition);
159 TentativeParsingAction TPA(*
this);
161 Token rBraceToken = Tok;
164 if (!rBraceToken.
is(tok::r_brace)) {
165 Diag(ExtraNSs[0].NamespaceLoc, diag::ext_nested_namespace_definition)
166 << SourceRange(ExtraNSs.front().NamespaceLoc,
167 ExtraNSs.back().IdentLoc);
169 std::string NamespaceFix;
170 for (
const auto &ExtraNS : ExtraNSs) {
171 NamespaceFix +=
" { ";
172 if (ExtraNS.InlineLoc.isValid())
173 NamespaceFix +=
"inline ";
174 NamespaceFix +=
"namespace ";
175 NamespaceFix += ExtraNS.Ident->getName();
179 for (
unsigned i = 0, e = ExtraNSs.size(); i != e; ++i)
182 Diag(ExtraNSs[0].NamespaceLoc, diag::ext_nested_namespace_definition)
184 SourceRange(ExtraNSs.front().NamespaceLoc,
185 ExtraNSs.back().IdentLoc),
191 if (FirstNestedInlineLoc.
isValid())
192 Diag(FirstNestedInlineLoc, diag::ext_inline_nested_namespace_definition);
198 ? diag::warn_cxx98_compat_inline_namespace
199 : diag::ext_inline_namespace);
204 UsingDirectiveDecl *ImplicitUsingDirectiveDecl =
nullptr;
205 Decl *NamespcDecl = Actions.ActOnStartNamespaceDef(
206 getCurScope(), InlineLoc, NamespaceLoc, IdentLoc, Ident,
207 T.getOpenLocation(), attrs, ImplicitUsingDirectiveDecl,
false);
209 PrettyDeclStackTraceEntry CrashInfo(Actions.Context, NamespcDecl,
210 NamespaceLoc,
"parsing namespace");
214 ParseInnerNamespace(ExtraNSs, 0, InlineLoc, attrs,
T);
217 NamespaceScope.Exit();
219 DeclEnd =
T.getCloseLocation();
220 Actions.ActOnFinishNamespaceDef(NamespcDecl, DeclEnd);
222 return Actions.ConvertDeclToDeclGroup(NamespcDecl,
223 ImplicitUsingDirectiveDecl);
226void Parser::ParseInnerNamespace(
const InnerNamespaceInfoList &InnerNSs,
230 if (index == InnerNSs.size()) {
231 while (!tryParseMisplacedModuleImport() && Tok.isNot(tok::r_brace) &&
232 Tok.isNot(tok::eof)) {
233 ParsedAttributes DeclAttrs(AttrFactory);
234 MaybeParseCXX11Attributes(DeclAttrs);
235 ParsedAttributes EmptyDeclSpecAttrs(AttrFactory);
236 ParseExternalDeclaration(DeclAttrs, EmptyDeclSpecAttrs);
250 UsingDirectiveDecl *ImplicitUsingDirectiveDecl =
nullptr;
251 Decl *NamespcDecl = Actions.ActOnStartNamespaceDef(
252 getCurScope(), InnerNSs[index].InlineLoc, InnerNSs[index].NamespaceLoc,
253 InnerNSs[index].IdentLoc, InnerNSs[index].Ident,
255 assert(!ImplicitUsingDirectiveDecl &&
256 "nested namespace definition cannot define anonymous namespace");
258 ParseInnerNamespace(InnerNSs, ++index, InlineLoc, attrs, Tracker);
260 NamespaceScope.Exit();
268 assert(Tok.is(tok::equal) &&
"Not equal token");
272 if (Tok.is(tok::code_completion)) {
274 Actions.CodeCompletion().CodeCompleteNamespaceAliasDecl(
getCurScope());
280 ParseOptionalCXXScopeSpecifier(SS,
nullptr,
288 if (Tok.isNot(tok::identifier)) {
289 Diag(Tok, diag::err_expected_namespace_name);
303 IdentifierInfo *Ident = Tok.getIdentifierInfo();
307 DeclEnd = Tok.getLocation();
308 if (ExpectAndConsume(tok::semi, diag::err_expected_semi_after_namespace_name))
311 return Actions.ActOnNamespaceAliasDef(
getCurScope(), NamespaceLoc, AliasLoc,
312 Alias, SS, IdentLoc, Ident);
316 assert(isTokenStringLiteral() &&
"Not a string literal!");
323 : Actions.ActOnStartLinkageSpecification(
325 Tok.is(tok::l_brace) ? Tok.getLocation() : SourceLocation());
327 ParsedAttributes DeclAttrs(AttrFactory);
328 ParsedAttributes DeclSpecAttrs(AttrFactory);
330 while (MaybeParseCXX11Attributes(DeclAttrs) ||
331 MaybeParseGNUAttributes(DeclSpecAttrs))
334 if (Tok.isNot(tok::l_brace)) {
341 ParseExternalDeclaration(DeclAttrs, DeclSpecAttrs, &DS);
342 return LinkageSpec ? Actions.ActOnFinishLinkageSpecification(
349 ProhibitAttributes(DeclAttrs);
354 unsigned NestedModules = 0;
356 switch (Tok.getKind()) {
357 case tok::annot_module_begin:
362 case tok::annot_module_end:
369 case tok::annot_module_include:
381 ParsedAttributes DeclAttrs(AttrFactory);
382 ParsedAttributes DeclSpecAttrs(AttrFactory);
383 while (MaybeParseCXX11Attributes(DeclAttrs) ||
384 MaybeParseGNUAttributes(DeclSpecAttrs))
386 ParseExternalDeclaration(DeclAttrs, DeclSpecAttrs);
394 return LinkageSpec ? Actions.ActOnFinishLinkageSpecification(
399Decl *Parser::ParseExportDeclaration() {
400 assert(Tok.is(tok::kw_export));
403 if (Tok.is(tok::code_completion)) {
405 Actions.CodeCompletion().CodeCompleteOrdinaryName(
413 Decl *ExportDecl = Actions.ActOnStartExportDecl(
415 Tok.is(tok::l_brace) ? Tok.getLocation() : SourceLocation());
417 if (Tok.isNot(tok::l_brace)) {
419 ParsedAttributes DeclAttrs(AttrFactory);
420 MaybeParseCXX11Attributes(DeclAttrs);
421 ParsedAttributes EmptyDeclSpecAttrs(AttrFactory);
422 ParseExternalDeclaration(DeclAttrs, EmptyDeclSpecAttrs);
423 return Actions.ActOnFinishExportDecl(
getCurScope(), ExportDecl,
430 while (!tryParseMisplacedModuleImport() && Tok.isNot(tok::r_brace) &&
431 Tok.isNot(tok::eof)) {
432 ParsedAttributes DeclAttrs(AttrFactory);
433 MaybeParseCXX11Attributes(DeclAttrs);
434 ParsedAttributes EmptyDeclSpecAttrs(AttrFactory);
435 ParseExternalDeclaration(DeclAttrs, EmptyDeclSpecAttrs);
439 return Actions.ActOnFinishExportDecl(
getCurScope(), ExportDecl,
440 T.getCloseLocation());
446 assert(Tok.is(tok::kw_using) &&
"Not using token");
447 ObjCDeclContextSwitch ObjCDC(*
this);
452 if (Tok.is(tok::code_completion)) {
454 Actions.CodeCompletion().CodeCompleteUsing(
getCurScope());
459 while (Tok.is(tok::kw_template)) {
461 Diag(TemplateLoc, diag::err_unexpected_template_after_using)
466 if (Tok.is(tok::kw_namespace)) {
469 SourceRange R = TemplateInfo.getSourceRange();
470 Diag(UsingLoc, diag::err_templated_using_directive_declaration)
474 Decl *UsingDir = ParseUsingDirective(Context, UsingLoc, DeclEnd, Attrs);
475 return Actions.ConvertDeclToDeclGroup(UsingDir);
479 return ParseUsingDeclaration(Context, TemplateInfo, UsingLoc, DeclEnd, Attrs,
487 assert(Tok.is(tok::kw_namespace) &&
"Not 'namespace' token");
492 if (Tok.is(tok::code_completion)) {
494 Actions.CodeCompletion().CodeCompleteUsingDirective(
getCurScope());
500 ParseOptionalCXXScopeSpecifier(SS,
nullptr,
508 IdentifierInfo *NamespcName =
nullptr;
509 SourceLocation IdentLoc = SourceLocation();
512 if (Tok.isNot(tok::identifier)) {
513 Diag(Tok, diag::err_expected_namespace_name);
528 NamespcName = Tok.getIdentifierInfo();
532 bool GNUAttr =
false;
533 if (Tok.is(tok::kw___attribute)) {
535 ParseGNUAttributes(attrs);
539 DeclEnd = Tok.getLocation();
540 if (ExpectAndConsume(tok::semi,
541 GNUAttr ? diag::err_expected_semi_after_attribute_list
542 : diag::err_expected_semi_after_namespace_name))
545 return Actions.ActOnUsingDirective(
getCurScope(), UsingLoc, NamespcLoc, SS,
546 IdentLoc, NamespcName, attrs);
550 UsingDeclarator &D) {
557 if (Tok.is(tok::kw___super)) {
558 Diag(Tok.getLocation(), diag::err_super_in_using_declaration);
563 const IdentifierInfo *LastII =
nullptr;
564 if (ParseOptionalCXXScopeSpecifier(D.SS,
nullptr,
574 if (D.SS.isInvalid())
588 Tok.is(tok::identifier) &&
593 D.SS.isNotEmpty() && LastII == Tok.getIdentifierInfo() &&
597 Actions.getInheritingConstructorName(D.SS, IdLoc, *LastII);
598 D.Name.setConstructorName(
Type, IdLoc, IdLoc);
605 !(Tok.is(tok::identifier) &&
NextToken().
is(tok::equal)),
606 false,
nullptr, D.Name))
612 ? diag::warn_cxx17_compat_using_declaration_pack
613 : diag::ext_using_declaration_pack);
622 SourceLocation UELoc;
629 ? diag::warn_cxx17_compat_using_enum_declaration
630 : diag::ext_using_enum_declaration);
632 DiagnoseCXX11AttributeExtension(PrefixAttrs);
635 SourceRange R = TemplateInfo.getSourceRange();
636 Diag(UsingLoc, diag::err_templated_using_directive_declaration)
642 if (ParseOptionalCXXScopeSpecifier(SS,
nullptr,
654 if (Tok.is(tok::code_completion)) {
656 Actions.CodeCompletion().CodeCompleteUsing(
getCurScope());
664 if (Tok.is(tok::identifier)) {
665 IdentifierInfo *IdentInfo = Tok.getIdentifierInfo();
674 UED = Actions.ActOnUsingEnumDeclaration(
676 }
else if (Tok.is(tok::annot_template_id)) {
677 TemplateIdAnnotation *TemplateId = takeTemplateIdAnnotation(Tok);
683 assert(Tok.is(tok::annot_typename) &&
"template-id -> type failed");
685 SourceRange Loc = Tok.getAnnotationRange();
686 ConsumeAnnotationToken();
688 UED = Actions.ActOnUsingEnumDeclaration(
getCurScope(), AS, UsingLoc,
689 UELoc, Loc, *TemplateId->
Name,
692 Diag(Tok.getLocation(), diag::err_using_enum_not_enum)
697 Diag(Tok.getLocation(), diag::err_using_enum_expect_identifier)
698 << Tok.is(tok::kw_enum);
708 DeclEnd = Tok.getLocation();
709 if (ExpectAndConsume(tok::semi, diag::err_expected_after,
710 "using-enum declaration"))
713 return Actions.ConvertDeclToDeclGroup(UED);
718 ParsedAttributes MisplacedAttrs(AttrFactory);
719 MaybeParseCXX11Attributes(MisplacedAttrs);
721 if (InInitStatement && Tok.isNot(tok::identifier))
725 bool InvalidDeclarator = ParseUsingDeclarator(Context, D);
727 ParsedAttributes Attrs(AttrFactory);
728 MaybeParseAttributes(PAKM_GNU | PAKM_CXX11, Attrs);
732 if (MisplacedAttrs.Range.isValid()) {
734 MisplacedAttrs.empty() ?
nullptr : &MisplacedAttrs.front();
735 auto &
Range = MisplacedAttrs.Range;
736 (FirstAttr && FirstAttr->isRegularKeywordAttribute()
737 ?
Diag(
Range.getBegin(), diag::err_keyword_not_allowed) << FirstAttr
738 :
Diag(
Range.getBegin(), diag::err_attributes_not_allowed))
746 if (Tok.is(tok::equal) || InInitStatement) {
747 if (InvalidDeclarator) {
752 ProhibitAttributes(PrefixAttrs);
754 Decl *DeclFromDeclSpec =
nullptr;
760 Decl *AD = ParseAliasDeclarationAfterDeclarator(
761 TemplateInfo, UsingLoc, D, DeclEnd, AS, Attrs, &DeclFromDeclSpec);
766 return Actions.ConvertDeclToDeclGroup(AD, DeclFromDeclSpec);
769 DiagnoseCXX11AttributeExtension(PrefixAttrs);
775 SourceRange R = TemplateInfo.getSourceRange();
776 Diag(UsingLoc, diag::err_templated_using_directive_declaration)
785 SmallVector<Decl *, 8> DeclsInGroup;
788 MaybeParseAttributes(PAKM_GNU | PAKM_CXX11, Attrs);
789 DiagnoseCXX11AttributeExtension(Attrs);
792 if (InvalidDeclarator)
797 if (D.TypenameLoc.isValid() &&
799 Diag(D.Name.getSourceRange().getBegin(),
800 diag::err_typename_identifiers_only)
803 D.TypenameLoc = SourceLocation();
807 D.TypenameLoc, D.SS, D.Name,
808 D.EllipsisLoc, Attrs);
810 DeclsInGroup.push_back(UD);
818 InvalidDeclarator = ParseUsingDeclarator(Context, D);
821 if (DeclsInGroup.size() > 1)
822 Diag(Tok.getLocation(),
824 ? diag::warn_cxx17_compat_multi_using_declaration
825 : diag::ext_multi_using_declaration);
828 DeclEnd = Tok.getLocation();
829 if (ExpectAndConsume(tok::semi, diag::err_expected_after,
830 !Attrs.
empty() ?
"attributes list"
831 : UELoc.
isValid() ?
"using-enum declaration"
832 :
"using declaration"))
835 return Actions.BuildDeclaratorGroup(DeclsInGroup);
838Decl *Parser::ParseAliasDeclarationAfterDeclarator(
842 if (ExpectAndConsume(tok::equal)) {
848 ? diag::warn_cxx98_compat_alias_declaration
849 : diag::ext_alias_declaration);
860 if (SpecKind != -1) {
863 Range = SourceRange(D.Name.TemplateId->LAngleLoc,
864 D.Name.TemplateId->RAngleLoc);
866 Range = TemplateInfo.getSourceRange();
867 Diag(
Range.getBegin(), diag::err_alias_declaration_specialization)
868 << SpecKind <<
Range;
875 Diag(D.Name.StartLocation, diag::err_alias_declaration_not_identifier);
879 }
else if (D.TypenameLoc.isValid())
880 Diag(D.TypenameLoc, diag::err_alias_declaration_not_identifier)
882 SourceRange(D.TypenameLoc, D.SS.isNotEmpty() ? D.SS.getEndLoc()
884 else if (D.SS.isNotEmpty())
885 Diag(D.SS.getBeginLoc(), diag::err_alias_declaration_not_identifier)
887 if (D.EllipsisLoc.isValid())
888 Diag(D.EllipsisLoc, diag::err_alias_declaration_pack_expansion)
891 Decl *DeclFromDeclSpec =
nullptr;
896 AS, &DeclFromDeclSpec, &Attrs);
898 *OwnedType = DeclFromDeclSpec;
901 DeclEnd = Tok.getLocation();
902 if (ExpectAndConsume(tok::semi, diag::err_expected_after,
903 !Attrs.
empty() ?
"attributes list"
904 :
"alias declaration"))
909 TemplateParams ? TemplateParams->data() :
nullptr,
910 TemplateParams ? TemplateParams->size() : 0);
911 return Actions.ActOnAliasDeclaration(
getCurScope(), AS, TemplateParamsArg,
918 if (
const auto *BO = dyn_cast_or_null<BinaryOperator>(AssertExpr)) {
919 if (BO->getOpcode() == BO_LAnd &&
927 assert(Tok.isOneOf(tok::kw_static_assert, tok::kw__Static_assert) &&
928 "Not a static_assert declaration");
931 const char *TokName = Tok.getName();
933 if (Tok.is(tok::kw__Static_assert))
934 diagnoseUseOfC11Keyword(Tok);
935 else if (Tok.is(tok::kw_static_assert)) {
938 Diag(Tok, diag::warn_c23_compat_keyword) << Tok.getName();
940 Diag(Tok, diag::warn_cxx98_compat_static_assert);
946 if (
T.consumeOpen()) {
947 Diag(Tok, diag::err_expected) << tok::l_paren;
952 EnterExpressionEvaluationContext ConstantEvaluated(
955 if (AssertExpr.isInvalid()) {
961 if (Tok.is(tok::r_paren)) {
964 DiagVal = diag::warn_cxx14_compat_static_assert_no_message;
966 DiagVal = diag::ext_cxx_static_assert_no_message;
968 DiagVal = diag::warn_c17_compat_static_assert_no_message;
970 DiagVal = diag::ext_c_static_assert_no_message;
974 if (ExpectAndConsume(tok::comma)) {
979 bool ParseAsExpression =
false;
981 for (
unsigned I = 0;; ++I) {
983 if (
T.is(tok::r_paren))
986 ParseAsExpression =
true;
992 if (ParseAsExpression) {
995 ? diag::warn_cxx20_compat_static_assert_user_generated_message
996 : diag::ext_cxx_static_assert_user_generated_message);
1001 Diag(Tok, diag::err_expected_string_literal)
1013 if (
T.consumeClose())
1016 DeclEnd = Tok.getLocation();
1017 ExpectAndConsumeSemi(diag::err_expected_semi_after_static_assert, TokName);
1019 return Actions.ActOnStaticAssertDeclaration(StaticAssertLoc, AssertExpr.get(),
1020 AssertMessage.
get(),
1021 T.getCloseLocation());
1025 assert(Tok.isOneOf(tok::kw_decltype, tok::annot_decltype) &&
1026 "Not a decltype specifier");
1029 SourceLocation StartLoc = Tok.getLocation();
1030 SourceLocation EndLoc;
1032 if (Tok.is(tok::annot_decltype)) {
1033 Result = getExprAnnotation(Tok);
1034 EndLoc = Tok.getAnnotationEndLoc();
1038 ConsumeAnnotationToken();
1039 if (
Result.isInvalid()) {
1044 if (Tok.getIdentifierInfo()->isStr(
"decltype"))
1045 Diag(Tok, diag::warn_cxx98_compat_decltype);
1050 if (
T.expectAndConsume(diag::err_expected_lparen_after,
"decltype",
1053 return T.getOpenLocation() == Tok.getLocation() ? StartLoc
1054 :
T.getOpenLocation();
1058 if (Tok.is(tok::kw_auto) &&
NextToken().
is(tok::r_paren)) {
1061 Diag(Tok.getLocation(),
1063 ? diag::warn_cxx11_compat_decltype_auto_type_specifier
1064 : diag::ext_decltype_auto_type_specifier);
1075 if (
Result.isInvalid()) {
1078 EndLoc = ConsumeParen();
1080 if (PP.isBacktrackEnabled() && Tok.is(tok::semi)) {
1082 PP.RevertCachedTokens(2);
1085 assert(Tok.is(tok::semi));
1087 EndLoc = Tok.getLocation();
1093 Result = Actions.ActOnDecltypeExpression(
Result.get());
1099 if (
T.getCloseLocation().isInvalid()) {
1103 return T.getCloseLocation();
1106 if (
Result.isInvalid()) {
1108 return T.getCloseLocation();
1111 EndLoc =
T.getCloseLocation();
1113 assert(!
Result.isInvalid());
1115 const char *PrevSpec =
nullptr;
1117 const PrintingPolicy &Policy = Actions.getASTContext().getPrintingPolicy();
1120 PrevSpec, DiagID,
Result.get(), Policy)
1122 PrevSpec, DiagID, Policy)) {
1123 Diag(StartLoc, DiagID) << PrevSpec;
1130void Parser::AnnotateExistingDecltypeSpecifier(
const DeclSpec &DS,
1134 if (PP.isBacktrackEnabled()) {
1135 PP.RevertCachedTokens(1);
1137 PP.EnterToken(Tok,
true);
1139 Tok.setKind(tok::annot_decltype);
1140 setExprAnnotation(Tok,
1144 Tok.setAnnotationEndLoc(EndLoc);
1145 Tok.setLocation(StartLoc);
1146 PP.AnnotateCachedTokens(Tok);
1150 assert(Tok.isOneOf(tok::annot_pack_indexing_type, tok::identifier) &&
1151 "Expected an identifier");
1154 SourceLocation StartLoc;
1155 SourceLocation EllipsisLoc;
1156 const char *PrevSpec;
1158 const PrintingPolicy &Policy = Actions.getASTContext().getPrintingPolicy();
1160 if (Tok.is(tok::annot_pack_indexing_type)) {
1161 StartLoc = Tok.getLocation();
1162 SourceLocation EndLoc;
1164 EndLoc = Tok.getAnnotationEndLoc();
1168 ConsumeAnnotationToken();
1169 if (
Type.isInvalid()) {
1174 DiagID,
Type, Policy);
1180 return Tok.getEndLoc();
1183 ParsedType Ty = Actions.getTypeName(*Tok.getIdentifierInfo(),
1187 return Tok.getEndLoc();
1202 ASTContext &
C = Actions.getASTContext();
1204 C.getSizeType(), SourceLocation());
1210 return T.getCloseLocation();
1213void Parser::AnnotateExistingIndexedTypeNamePack(
ParsedType T,
1217 if (PP.isBacktrackEnabled()) {
1218 PP.RevertCachedTokens(1);
1224 EndLoc = PP.getLastCachedTokenLocation();
1227 PP.EnterToken(Tok,
true);
1229 Tok.setKind(tok::annot_pack_indexing_type);
1230 setTypeAnnotation(Tok,
T);
1231 Tok.setAnnotationEndLoc(EndLoc);
1232 Tok.setLocation(StartLoc);
1233 PP.AnnotateCachedTokens(Tok);
1237 switch (Tok.getKind()) {
1238#define TRANSFORM_TYPE_TRAIT_DEF(_, Trait) \
1239 case tok::kw___##Trait: \
1240 return DeclSpec::TST_##Trait;
1241#include "clang/Basic/TransformTypeTraits.def"
1243 llvm_unreachable(
"passed in an unhandled type transformation built-in");
1247bool Parser::MaybeParseTypeTransformTypeSpecifier(
DeclSpec &DS) {
1249 Tok.setKind(tok::identifier);
1252 DeclSpec::TST TypeTransformTST = TypeTransformTokToDeclSpec();
1256 if (
T.expectAndConsume(diag::err_expected_lparen_after, Tok.getName(),
1261 if (
Result.isInvalid()) {
1267 if (
T.getCloseLocation().isInvalid())
1270 const char *PrevSpec =
nullptr;
1274 Actions.getASTContext().getPrintingPolicy()))
1275 Diag(StartLoc, DiagID) << PrevSpec;
1283 if (Tok.is(tok::kw_typename)) {
1284 Diag(Tok, diag::err_expected_class_name_not_template)
1291 if (ParseOptionalCXXScopeSpecifier(SS,
nullptr,
1296 BaseLoc = Tok.getLocation();
1301 if (Tok.isOneOf(tok::kw_decltype, tok::annot_decltype)) {
1306 DeclSpec DS(AttrFactory);
1308 EndLocation = ParseDecltypeSpecifier(DS);
1312 return Actions.ActOnTypeName(DeclaratorInfo);
1315 if (Tok.is(tok::annot_pack_indexing_type)) {
1316 DeclSpec DS(AttrFactory);
1317 ParsePackIndexingType(DS);
1320 return Actions.ActOnTypeName(DeclaratorInfo);
1326 if (Tok.is(tok::annot_template_id)) {
1327 TemplateIdAnnotation *TemplateId = takeTemplateIdAnnotation(Tok);
1332 assert(Tok.is(tok::annot_typename) &&
"template-id -> type failed");
1334 EndLocation = Tok.getAnnotationEndLoc();
1335 ConsumeAnnotationToken();
1342 if (Tok.isNot(tok::identifier)) {
1343 Diag(Tok, diag::err_expected_class_name);
1347 IdentifierInfo *Id = Tok.getIdentifierInfo();
1350 if (Tok.is(tok::less)) {
1357 if (!Actions.DiagnoseUnknownTemplateName(*Id, IdLoc,
getCurScope(), &SS,
1359 Diag(IdLoc, diag::err_unknown_template_name) << Id;
1367 if (AnnotateTemplateIdToken(
Template, TNK, SS, SourceLocation(),
1370 if (Tok.is(tok::annot_template_id) &&
1371 takeTemplateIdAnnotation(Tok)->mightBeType())
1377 if (Tok.isNot(tok::annot_typename))
1382 EndLocation = Tok.getAnnotationEndLoc();
1384 ConsumeAnnotationToken();
1389 IdentifierInfo *CorrectedII =
nullptr;
1391 *Id, IdLoc,
getCurScope(), &SS,
true,
false,
nullptr,
1397 Diag(IdLoc, diag::err_expected_class_name);
1402 EndLocation = IdLoc;
1405 DeclSpec DS(AttrFactory);
1410 const char *PrevSpec =
nullptr;
1413 Actions.getASTContext().getPrintingPolicy());
1417 return Actions.ActOnTypeName(DeclaratorInfo);
1420void Parser::ParseMicrosoftInheritanceClassAttributes(
ParsedAttributes &attrs) {
1421 while (Tok.isOneOf(tok::kw___single_inheritance,
1422 tok::kw___multiple_inheritance,
1423 tok::kw___virtual_inheritance)) {
1424 IdentifierInfo *
AttrName = Tok.getIdentifierInfo();
1425 auto Kind = Tok.getKind();
1427 attrs.
addNew(AttrName, AttrNameLoc, AttributeScopeInfo(),
nullptr, 0, Kind);
1432 while (Tok.is(tok::kw__Nullable)) {
1433 IdentifierInfo *
AttrName = Tok.getIdentifierInfo();
1434 auto Kind = Tok.getKind();
1436 attrs.
addNew(AttrName, AttrNameLoc, AttributeScopeInfo(),
nullptr, 0, Kind);
1440bool Parser::isValidAfterTypeSpecifier(
bool CouldBeBitfield) {
1442 switch (Tok.getKind()) {
1444 if (Tok.isRegularKeywordAttribute())
1451 case tok::identifier:
1453 case tok::coloncolon:
1454 case tok::annot_cxxscope:
1455 case tok::annot_typename:
1456 case tok::annot_template_id:
1457 case tok::kw_decltype:
1460 case tok::kw_operator:
1461 case tok::kw___declspec:
1466 case tok::kw___attribute:
1467 case tok::annot_pragma_pack:
1469 case tok::annot_pragma_ms_pragma:
1471 case tok::annot_pragma_ms_vtordisp:
1473 case tok::annot_pragma_ms_pointers_to_members:
1475 case tok::annot_pragma_export:
1478 return CouldBeBitfield ||
1481 case tok::kw___cdecl:
1482 case tok::kw___fastcall:
1483 case tok::kw___stdcall:
1484 case tok::kw___thiscall:
1485 case tok::kw___vectorcall:
1491 case tok::kw_volatile:
1492 case tok::kw_restrict:
1493 case tok::kw__Atomic:
1494 case tok::kw___unaligned:
1498 case tok::kw_inline:
1499 case tok::kw_virtual:
1500 case tok::kw_friend:
1502 case tok::kw_static:
1503 case tok::kw_extern:
1504 case tok::kw_typedef:
1505 case tok::kw_register:
1507 case tok::kw_mutable:
1508 case tok::kw_thread_local:
1509 case tok::kw_constexpr:
1510 case tok::kw_consteval:
1511 case tok::kw_constinit:
1527 if (!isKnownToBeTypeSpecifier(
NextToken()))
1544 ParsedTemplateInfo &TemplateInfo,
1546 DeclSpecContext DSC,
1549 if (TagTokKind == tok::kw_struct)
1551 else if (TagTokKind == tok::kw___interface)
1553 else if (TagTokKind == tok::kw_class)
1556 assert(TagTokKind == tok::kw_union &&
"Not a class specifier");
1560 if (Tok.is(tok::code_completion)) {
1563 Actions.CodeCompletion().CodeCompleteTag(
getCurScope(), TagType);
1574 const bool shouldDelayDiagsInTag =
1576 SuppressAccessChecks diagsFromTag(*
this, shouldDelayDiagsInTag);
1578 ParsedAttributes attrs(AttrFactory);
1581 MaybeParseAttributes(PAKM_CXX11 | PAKM_Declspec | PAKM_GNU, attrs);
1583 if (Tok.isOneOf(tok::kw___single_inheritance,
1584 tok::kw___multiple_inheritance,
1585 tok::kw___virtual_inheritance)) {
1586 ParseMicrosoftInheritanceClassAttributes(attrs);
1589 if (Tok.is(tok::kw__Nullable)) {
1590 ParseNullabilityClassAttributes(attrs);
1598 SourceLocation AttrFixitLoc = Tok.getLocation();
1601 !Tok.isAnnotation() && Tok.getIdentifierInfo() &&
1604#include
"clang/Basic/TransformTypeTraits.def"
1605 tok::kw___is_abstract,
1606 tok::kw___is_aggregate,
1607 tok::kw___is_arithmetic,
1609 tok::kw___is_assignable,
1610 tok::kw___is_base_of,
1611 tok::kw___is_bounded_array,
1613 tok::kw___is_complete_type,
1614 tok::kw___is_compound,
1616 tok::kw___is_constructible,
1617 tok::kw___is_convertible,
1618 tok::kw___is_convertible_to,
1619 tok::kw___is_destructible,
1622 tok::kw___is_floating_point,
1624 tok::kw___is_function,
1625 tok::kw___is_fundamental,
1626 tok::kw___is_integral,
1627 tok::kw___is_interface_class,
1628 tok::kw___is_literal,
1629 tok::kw___is_lvalue_expr,
1630 tok::kw___is_lvalue_reference,
1631 tok::kw___is_member_function_pointer,
1632 tok::kw___is_member_object_pointer,
1633 tok::kw___is_member_pointer,
1634 tok::kw___is_nothrow_assignable,
1635 tok::kw___is_nothrow_constructible,
1636 tok::kw___is_nothrow_convertible,
1637 tok::kw___is_nothrow_destructible,
1638 tok::kw___is_object,
1640 tok::kw___is_pointer,
1641 tok::kw___is_polymorphic,
1642 tok::kw___is_reference,
1643 tok::kw___is_rvalue_expr,
1644 tok::kw___is_rvalue_reference,
1646 tok::kw___is_scalar,
1647 tok::kw___is_scoped_enum,
1648 tok::kw___is_sealed,
1649 tok::kw___is_signed,
1650 tok::kw___is_standard_layout,
1651 tok::kw___is_trivial,
1652 tok::kw___is_trivially_equality_comparable,
1653 tok::kw___is_trivially_assignable,
1654 tok::kw___is_trivially_constructible,
1655 tok::kw___is_trivially_copyable,
1656 tok::kw___is_unbounded_array,
1658 tok::kw___is_unsigned,
1660 tok::kw___is_volatile
1667 TryKeywordIdentFallback(
true);
1669 struct PreserveAtomicIdentifierInfoRAII {
1670 PreserveAtomicIdentifierInfoRAII(Token &
Tok,
bool Enabled)
1674 assert(
Tok.
is(tok::kw__Atomic));
1679 ~PreserveAtomicIdentifierInfoRAII() {
1682 AtomicII->revertIdentifierToTokenID(tok::kw__Atomic);
1684 IdentifierInfo *AtomicII;
1692 bool ShouldChangeAtomicToIdentifier =
getLangOpts().MSVCCompat &&
1693 Tok.is(tok::kw__Atomic) &&
1695 PreserveAtomicIdentifierInfoRAII AtomicTokenGuard(
1696 Tok, ShouldChangeAtomicToIdentifier);
1706 if (TemplateInfo.TemplateParams)
1709 bool HasValidSpec =
true;
1710 if (ParseOptionalCXXScopeSpecifier(Spec,
nullptr,
1714 HasValidSpec =
false;
1717 if (Tok.isNot(tok::identifier) && Tok.isNot(tok::annot_template_id)) {
1718 Diag(Tok, diag::err_expected) << tok::identifier;
1719 HasValidSpec =
false;
1727 auto RecoverFromUndeclaredTemplateName = [&](IdentifierInfo *Name,
1728 SourceLocation NameLoc,
1729 SourceRange TemplateArgRange,
1730 bool KnownUndeclared) {
1731 Diag(NameLoc, diag::err_explicit_spec_non_template)
1733 << TagTokKind << Name << TemplateArgRange << KnownUndeclared;
1737 if (TemplateParams && TemplateInfo.LastParameterListWasEmpty) {
1738 if (TemplateParams->size() > 1) {
1739 TemplateParams->pop_back();
1741 TemplateParams =
nullptr;
1746 TemplateParams =
nullptr;
1748 TemplateInfo.TemplateLoc = SourceLocation();
1749 TemplateInfo.ExternLoc = SourceLocation();
1754 IdentifierInfo *Name =
nullptr;
1755 SourceLocation NameLoc;
1756 TemplateIdAnnotation *TemplateId =
nullptr;
1757 if (Tok.is(tok::identifier)) {
1758 Name = Tok.getIdentifierInfo();
1766 TemplateArgList TemplateArgs;
1767 SourceLocation LAngleLoc, RAngleLoc;
1768 if (ParseTemplateIdAfterTemplateName(
true, LAngleLoc, TemplateArgs,
1772 LAngleLoc = RAngleLoc = SourceLocation();
1774 RecoverFromUndeclaredTemplateName(
1775 Name, NameLoc, SourceRange(LAngleLoc, RAngleLoc),
false);
1777 }
else if (Tok.is(tok::annot_template_id)) {
1778 TemplateId = takeTemplateIdAnnotation(Tok);
1779 NameLoc = ConsumeAnnotationToken();
1783 Actions.ActOnUndeclaredTypeTemplateName(
1786 RecoverFromUndeclaredTemplateName(
1789 TemplateId =
nullptr;
1797 SourceRange
Range(NameLoc);
1802 Diag(TemplateId->
LAngleLoc, diag::err_template_spec_syntax_non_template)
1803 << TemplateId->
Name <<
static_cast<int>(TemplateId->
Kind) << Range;
1838 MaybeParseCXX11Attributes(Attributes);
1840 const PrintingPolicy &Policy = Actions.getASTContext().getPrintingPolicy();
1847 Tok.isOneOf(tok::comma, tok::ellipsis))
1850 AllowDefiningTypeSpec::No ||
1853 else if (Tok.is(tok::l_brace) ||
1854 (DSC != DeclSpecContext::DSC_association &&
1856 (isClassCompatibleKeyword() &&
1858 isClassCompatibleKeyword(
NextToken())))) {
1862 Diag(Tok.getLocation(), diag::err_friend_decl_defines_type)
1873 }
else if (isClassCompatibleKeyword() &&
1880 TentativeParsingAction PA(*
this);
1883 while (isClassCompatibleKeyword())
1888 if (Tok.is(tok::l_square) &&
NextToken().
is(tok::l_square)) {
1892 }
else if (Tok.is(tok::kw_alignas) &&
NextToken().
is(tok::l_paren)) {
1897 }
else if (Tok.isRegularKeywordAttribute()) {
1902 if (!
T.consumeOpen())
1910 if (Tok.isOneOf(tok::l_brace, tok::colon))
1916 }
else if (!isTypeSpecifier(DSC) &&
1917 (Tok.is(tok::semi) ||
1918 (Tok.isAtStartOfLine() && !isValidAfterTypeSpecifier(
false)))) {
1920 if (Tok.isNot(tok::semi)) {
1921 const PrintingPolicy &PPol = Actions.getASTContext().getPrintingPolicy();
1923 ExpectAndConsume(tok::semi, diag::err_expected_after,
1925 PP.EnterToken(Tok,
true);
1926 Tok.setKind(tok::semi);
1939 SourceRange AttrRange = Attributes.
Range;
1943 (FirstAttr && FirstAttr->isRegularKeywordAttribute()
1944 ?
Diag(Loc, diag::err_keyword_not_allowed) << FirstAttr
1945 :
Diag(Loc, diag::err_attributes_not_allowed))
1948 AttrFixitLoc, CharSourceRange(AttrRange,
true))
1957 if (!Name && !TemplateId &&
1962 Diag(StartLoc, diag::err_anon_type_definition)
1981 SkipBodyInfo SkipBody;
1992 ProhibitCXX11Attributes(attrs, diag::err_attributes_not_allowed,
1993 diag::err_keyword_not_allowed,
1996 TagOrTempResult = Actions.ActOnExplicitInstantiation(
1997 getCurScope(), TemplateInfo.ExternLoc, TemplateInfo.TemplateLoc,
1998 TagType, StartLoc, SS, TemplateId->
Template,
2009 ProhibitCXX11Attributes(attrs, diag::err_attributes_not_allowed,
2010 diag::err_keyword_not_allowed,
2033 "Expected a definition here");
2037 TemplateParams =
nullptr;
2039 SourceLocation LAngleLoc =
2040 PP.getLocForEndOfToken(TemplateInfo.TemplateLoc);
2042 diag::err_explicit_instantiation_with_definition)
2043 << SourceRange(TemplateInfo.TemplateLoc)
2049 FakedParamLists.push_back(Actions.ActOnTemplateParameterList(
2050 0, SourceLocation(), TemplateInfo.TemplateLoc, LAngleLoc, {},
2051 LAngleLoc,
nullptr));
2052 TemplateParams = &FakedParamLists;
2057 TagOrTempResult = Actions.ActOnClassTemplateSpecialization(
2059 SS, *TemplateId, attrs,
2062 TemplateParams ? TemplateParams->size() : 0),
2072 ProhibitAttributes(attrs);
2074 TagOrTempResult = Actions.ActOnExplicitInstantiation(
2075 getCurScope(), TemplateInfo.ExternLoc, TemplateInfo.TemplateLoc,
2076 TagType, StartLoc, SS, Name, NameLoc, attrs);
2079 ProhibitCXX11Attributes(attrs, diag::err_attributes_not_allowed,
2080 diag::err_keyword_not_allowed,
2084 SourceLocation EllipsisLoc;
2096 if (Tok.is(tok::comma)) {
2097 Diag(Tok.getLocation(),
2098 diag::err_friend_template_decl_multiple_specifiers);
2102 TagOrTempResult = Actions.ActOnTemplatedFriendTag(
2104 NameLoc, EllipsisLoc, attrs,
2106 TemplateParams ? TemplateParams->size() : 0));
2109 ProhibitCXX11Attributes(attrs, diag::err_attributes_not_allowed,
2110 diag::err_keyword_not_allowed,
2117 Diag(Tok, diag::err_template_defn_explicit_instantiation)
2119 TemplateParams =
nullptr;
2122 bool IsDependent =
false;
2132 stripTypeAttributesOffDeclSpec(attrs, DS, TUK);
2135 TagOrTempResult = Actions.ActOnTag(
2136 getCurScope(), TagType, TUK, StartLoc, SS, Name, NameLoc, attrs, AS,
2139 DSC == DeclSpecContext::DSC_type_specifier,
2140 DSC == DeclSpecContext::DSC_template_param ||
2141 DSC == DeclSpecContext::DSC_template_type_arg,
2142 OffsetOfState, &SkipBody);
2149 Name, StartLoc, NameLoc);
2156 if (shouldDelayDiagsInTag) {
2157 diagsFromTag.done();
2160 diagsFromTag.redelay();
2165 assert(Tok.is(tok::l_brace) ||
2167 isClassCompatibleKeyword());
2169 SkipCXXMemberSpecification(StartLoc, AttrFixitLoc, TagType,
2170 TagOrTempResult.
get());
2172 ParseCXXMemberSpecification(StartLoc, AttrFixitLoc, attrs, TagType,
2173 TagOrTempResult.
get());
2181 TagOrTempResult.
get(), SkipBody)) {
2190 Actions.ProcessDeclAttributeDelayed(TagOrTempResult.
get(), attrs);
2192 const char *PrevSpec =
nullptr;
2197 NameLoc.
isValid() ? NameLoc : StartLoc,
2199 }
else if (!TagOrTempResult.
isInvalid()) {
2201 TagType, StartLoc, NameLoc.
isValid() ? NameLoc : StartLoc, PrevSpec,
2202 DiagID, TagOrTempResult.
get(), Owned, Policy);
2209 Diag(StartLoc, DiagID) << PrevSpec;
2226 if (Tok.isNot(tok::semi)) {
2227 const PrintingPolicy &PPol = Actions.getASTContext().getPrintingPolicy();
2228 ExpectAndConsume(tok::semi, diag::err_expected_after,
2233 PP.EnterToken(Tok,
true);
2234 Tok.setKind(tok::semi);
2239void Parser::ParseBaseClause(
Decl *ClassDecl) {
2240 assert(Tok.is(tok::colon) &&
"Not a base clause");
2244 SmallVector<CXXBaseSpecifier *, 8> BaseInfo;
2249 if (!
Result.isUsable()) {
2255 BaseInfo.push_back(
Result.get());
2265 Actions.ActOnBaseSpecifiers(ClassDecl, BaseInfo);
2269 bool IsVirtual =
false;
2270 SourceLocation StartLoc = Tok.getLocation();
2272 ParsedAttributes Attributes(AttrFactory);
2273 MaybeParseCXX11Attributes(Attributes);
2279 CheckMisplacedCXX11Attribute(Attributes, StartLoc);
2286 Diag(Tok.getLocation(), diag::ext_hlsl_access_specifiers);
2289 CheckMisplacedCXX11Attribute(Attributes, StartLoc);
2293 if (Tok.is(tok::kw_virtual)) {
2297 Diag(VirtualLoc, diag::err_dup_virtual)
2305 Diag(Tok.getLocation(), diag::err_hlsl_virtual_inheritance);
2307 CheckMisplacedCXX11Attribute(Attributes, StartLoc);
2315 if (
getLangOpts().MSVCCompat && Tok.is(tok::kw__Atomic) &&
2317 Tok.setKind(tok::identifier);
2319 SourceLocation EndLocation;
2320 SourceLocation BaseLoc;
2321 TypeResult BaseType = ParseBaseTypeSpecifier(BaseLoc, EndLocation);
2328 SourceLocation EllipsisLoc;
2332 SourceRange
Range(StartLoc, EndLocation);
2336 return Actions.ActOnBaseSpecifier(ClassDecl, Range, Attributes, IsVirtual,
2337 Access, BaseType.
get(), BaseLoc,
2342 switch (Tok.getKind()) {
2345 case tok::kw_private:
2347 case tok::kw_protected:
2349 case tok::kw_public:
2354void Parser::HandleMemberFunctionDeclDelays(
Declarator &DeclaratorInfo,
2361 if (!NeedLateParse) {
2363 for (
unsigned ParamIdx = 0; ParamIdx < FTI.
NumParams; ++ParamIdx) {
2365 if (Param->hasUnparsedDefaultArg()) {
2366 NeedLateParse =
true;
2372 if (NeedLateParse) {
2375 auto LateMethod =
new LateParsedMethodDeclaration(
this, ThisDecl);
2376 getCurrentClass().LateParsedDeclarations.push_back(LateMethod);
2381 LateMethod->DefaultArgs.reserve(FTI.
NumParams);
2382 for (
unsigned ParamIdx = 0; ParamIdx < FTI.
NumParams; ++ParamIdx)
2383 LateMethod->DefaultArgs.push_back(LateParsedDefaultArgument(
2399 const IdentifierInfo *II = Tok.getIdentifierInfo();
2403 Ident_final = &PP.getIdentifierTable().get(
"final");
2405 Ident_GNU_final = &PP.getIdentifierTable().get(
"__final");
2407 Ident_sealed = &PP.getIdentifierTable().get(
"sealed");
2408 Ident_abstract = &PP.getIdentifierTable().get(
"abstract");
2410 Ident_override = &PP.getIdentifierTable().get(
"override");
2413 if (II == Ident_override)
2416 if (II == Ident_sealed)
2419 if (II == Ident_abstract)
2422 if (II == Ident_final)
2425 if (II == Ident_GNU_final)
2431void Parser::ParseOptionalCXX11VirtSpecifierSeq(
VirtSpecifiers &VS,
2440 Diag(Tok.getLocation(), diag::err_friend_decl_spec)
2443 << SourceRange(FriendLoc, FriendLoc);
2450 const char *PrevSpec =
nullptr;
2451 if (VS.
SetSpecifier(Specifier, Tok.getLocation(), PrevSpec))
2452 Diag(Tok.getLocation(), diag::err_duplicate_virt_specifier)
2457 Diag(Tok.getLocation(), diag::err_override_control_interface)
2460 Diag(Tok.getLocation(), diag::ext_ms_sealed_keyword);
2462 Diag(Tok.getLocation(), diag::ext_ms_abstract_keyword);
2464 Diag(Tok.getLocation(), diag::ext_warn_gnu_final);
2466 Diag(Tok.getLocation(),
2468 ? diag::warn_cxx98_compat_override_control_keyword
2469 : diag::ext_override_control_keyword)
2476bool Parser::isCXX11FinalKeyword()
const {
2483bool Parser::isClassCompatibleKeyword(
Token Tok)
const {
2491bool Parser::isClassCompatibleKeyword()
const {
2492 return isClassCompatibleKeyword(Tok);
2497bool Parser::ParseCXXMemberDeclaratorBeforeInitializer(
2499 LateParsedAttrList &LateParsedAttrs) {
2510 if (Tok.isNot(tok::colon))
2511 ParseDeclarator(DeclaratorInfo);
2516 MaybeParseHLSLAnnotations(DeclaratorInfo,
nullptr,
2521 "don't know where identifier would go yet?");
2525 }
else if (Tok.is(tok::kw_requires)) {
2526 ParseTrailingRequiresClause(DeclaratorInfo);
2528 ParseOptionalCXX11VirtSpecifierSeq(
2529 VS, getCurrentClass().IsInterface,
2532 MaybeParseAndDiagnoseDeclSpecAfterCXX11VirtSpecifierSeq(DeclaratorInfo,
2537 if (Tok.is(tok::kw_asm)) {
2539 ExprResult AsmLabel(ParseSimpleAsm(
true, &Loc));
2540 if (AsmLabel.isInvalid())
2550 DiagnoseAndSkipCXX11Attributes();
2551 MaybeParseGNUAttributes(DeclaratorInfo, &LateParsedAttrs);
2552 DiagnoseAndSkipCXX11Attributes();
2557 ParseOptionalCXX11VirtSpecifierSeq(
2558 VS, getCurrentClass().IsInterface,
2564 if (AL.isKnownToGCC() && !AL.isCXX11Attribute())
2565 Diag(AL.getLoc(), diag::warn_gcc_attribute_location);
2567 MaybeParseAndDiagnoseDeclSpecAfterCXX11VirtSpecifierSeq(DeclaratorInfo,
2582void Parser::MaybeParseAndDiagnoseDeclSpecAfterCXX11VirtSpecifierSeq(
2584 DeclSpec DS(AttrFactory);
2588 ParseTypeQualifierListOpt(
2589 DS, AR_NoAttributesParsed,
false,
2591 Actions.CodeCompletion().CodeCompleteFunctionQualifiers(DS, D, &VS);
2598 auto DeclSpecCheck = [&](
DeclSpec::TQ TypeQual, StringRef FixItName,
2599 SourceLocation SpecLoc) {
2600 FixItHint Insertion;
2601 auto &MQ =
Function.getOrCreateMethodQualifiers();
2602 if (!(MQ.getTypeQualifiers() & TypeQual)) {
2603 std::string Name(FixItName.data());
2606 MQ.SetTypeQual(TypeQual, SpecLoc);
2608 Diag(SpecLoc, diag::err_declspec_after_virtspec)
2617 bool RefQualifierIsLValueRef =
true;
2618 SourceLocation RefQualifierLoc;
2619 if (ParseRefQualifier(RefQualifierIsLValueRef, RefQualifierLoc)) {
2620 const char *Name = (RefQualifierIsLValueRef ?
"& " :
"&& ");
2621 FixItHint Insertion =
2623 Function.RefQualifierIsLValueRef = RefQualifierIsLValueRef;
2624 Function.RefQualifierLoc = RefQualifierLoc;
2626 Diag(RefQualifierLoc, diag::err_declspec_after_virtspec)
2627 << (RefQualifierIsLValueRef ?
"&" :
"&&")
2639 "ParseCXXClassMemberDeclaration should only be called in C++ mode");
2640 if (Tok.is(tok::at)) {
2642 Diag(Tok, diag::err_at_defs_cxx);
2644 Diag(Tok, diag::err_at_in_class);
2660 bool MalformedTypeSpec =
false;
2662 Tok.isOneOf(tok::identifier, tok::coloncolon, tok::kw___super)) {
2664 MalformedTypeSpec =
true;
2667 if (Tok.isNot(tok::annot_cxxscope))
2668 isAccessDecl =
false;
2677 ParseOptionalCXXScopeSpecifier(SS,
nullptr,
2687 SourceLocation TemplateKWLoc;
2690 false,
false,
true,
true,
2691 false, &TemplateKWLoc, Name)) {
2697 if (ExpectAndConsume(tok::semi, diag::err_expected_after,
2698 "access declaration")) {
2706 SourceLocation(), SS, Name,
2708 ParsedAttributesView())));
2715 Tok.isOneOf(tok::kw_static_assert, tok::kw__Static_assert)) {
2716 SourceLocation DeclEnd;
2718 DeclGroupRef(ParseStaticAssertDeclaration(DeclEnd)));
2721 if (Tok.is(tok::kw_template)) {
2722 assert(!TemplateInfo.TemplateParams &&
2723 "Nested template improperly parsed?");
2724 ObjCDeclContextSwitch ObjCDC(*
this);
2725 SourceLocation DeclEnd;
2727 DeclEnd, AccessAttrs, AS);
2731 if (Tok.is(tok::kw___extension__)) {
2733 ExtensionRAIIObject O(Diags);
2735 return ParseCXXClassMemberDeclaration(AS, AccessAttrs, TemplateInfo,
2739 ParsedAttributes DeclAttrs(AttrFactory);
2741 MaybeParseCXX11Attributes(DeclAttrs);
2746 if (Tok.is(tok::annot_attr_openmp))
2747 return ParseOpenMPDeclarativeDirectiveWithExtDecl(AS, DeclAttrs);
2749 if (Tok.is(tok::kw_using)) {
2754 while (Tok.is(tok::kw_template)) {
2756 Diag(TemplateLoc, diag::err_unexpected_template_after_using)
2760 if (Tok.is(tok::kw_namespace)) {
2761 Diag(UsingLoc, diag::err_using_namespace_in_class);
2765 SourceLocation DeclEnd;
2768 UsingLoc, DeclEnd, DeclAttrs, AS);
2771 ParsedAttributes DeclSpecAttrs(AttrFactory);
2773 LateParsedAttrList CommonLateParsedAttrs;
2775 while (MaybeParseCXX11Attributes(DeclAttrs) ||
2776 MaybeParseGNUAttributes(DeclSpecAttrs, &CommonLateParsedAttrs) ||
2777 MaybeParseMicrosoftAttributes(DeclSpecAttrs))
2780 SourceLocation DeclStart;
2781 if (DeclAttrs.Range.isValid()) {
2782 DeclStart = DeclSpecAttrs.Range.
isInvalid()
2783 ? DeclAttrs.Range.getBegin()
2784 : std::min(DeclAttrs.Range.getBegin(),
2785 DeclSpecAttrs.Range.getBegin());
2787 DeclStart = DeclSpecAttrs.Range.getBegin();
2792 ParsingDeclSpec DS(*
this, TemplateDiags);
2795 if (MalformedTypeSpec)
2803 bool IsTemplateSpecOrInst =
2806 SuppressAccessChecks diagsFromTag(*
this, IsTemplateSpecOrInst);
2808 ParseDeclarationSpecifiers(DS, TemplateInfo, AS, DeclSpecContext::DSC_class,
2809 &CommonLateParsedAttrs);
2811 if (IsTemplateSpecOrInst)
2812 diagsFromTag.done();
2824 DiagnoseMissingSemiAfterTagDefinition(DS, AS, DeclSpecContext::DSC_class,
2825 &CommonLateParsedAttrs))
2829 TemplateInfo.TemplateParams ? TemplateInfo.TemplateParams->data()
2831 TemplateInfo.TemplateParams ? TemplateInfo.TemplateParams->size() : 0);
2835 ProhibitAttributes(DeclAttrs);
2837 RecordDecl *AnonRecord =
nullptr;
2838 Decl *TheDecl = Actions.ParsedFreeStandingDeclSpec(
2839 getCurScope(), AS, DS, DeclAttrs, TemplateParams,
false, AnonRecord);
2840 Actions.ActOnDefinedDeclarationSpecifier(TheDecl);
2841 DS.complete(TheDecl);
2843 Decl *decls[] = {AnonRecord, TheDecl};
2844 return Actions.BuildDeclaratorGroup(decls);
2846 return Actions.ConvertDeclToDeclGroup(TheDecl);
2850 Actions.ActOnDefinedDeclarationSpecifier(DS.
getRepAsDecl());
2856 ? diag::warn_cxx23_variadic_friends
2857 : diag::ext_variadic_friends);
2860 SmallVector<Decl *> Decls;
2863 auto ParsedFriendDecl = [&](ParsingDeclSpec &DeclSpec) {
2864 SourceLocation VariadicLoc;
2867 RecordDecl *AnonRecord =
nullptr;
2868 Decl *D = Actions.ParsedFreeStandingDeclSpec(
2869 getCurScope(), AS, DeclSpec, DeclAttrs, TemplateParams,
false,
2870 AnonRecord, VariadicLoc);
2871 DeclSpec.complete(D);
2881 if (ParsedFriendDecl(DS))
2885 ParsingDeclSpec DeclSpec(*
this, TemplateDiags);
2886 const char *PrevSpec =
nullptr;
2887 unsigned DiagId = 0;
2888 DeclSpec.SetFriendSpec(FriendLoc, PrevSpec, DiagId);
2889 ParseDeclarationSpecifiers(DeclSpec, TemplateInfo, AS,
2890 DeclSpecContext::DSC_class,
nullptr);
2891 if (ParsedFriendDecl(DeclSpec))
2895 ExpectAndConsume(tok::semi, diag::err_expected_semi_after_stmt,
2896 "friend declaration");
2898 return Actions.BuildDeclaratorGroup(Decls);
2904 if (Tok.is(tok::kw_concept)) {
2908 ? llvm::to_underlying(diag::err_friend_concept)
2909 : llvm::to_underlying(
2911 err_concept_decls_may_only_appear_in_global_namespace_scope));
2916 ParsingDeclarator DeclaratorInfo(*
this, DS, DeclAttrs,
2918 if (TemplateInfo.TemplateParams)
2923 LateParsedAttrList LateParsedAttrs;
2925 SourceLocation EqualLoc;
2926 SourceLocation PureSpecLoc;
2928 auto TryConsumePureSpecifier = [&](
bool AllowDefinition) {
2929 if (Tok.isNot(tok::equal))
2933 SmallString<8> Buffer;
2934 if (
Zero.isNot(tok::numeric_constant) ||
2935 PP.getSpelling(
Zero, Buffer) !=
"0")
2939 if (!
After.isOneOf(tok::semi, tok::comma) &&
2940 !(AllowDefinition &&
2941 After.isOneOf(tok::l_brace, tok::colon, tok::kw_try)))
2949 SmallVector<Decl *, 8> DeclsInGroup;
2952 bool ExpectSemi =
true;
2957 SuppressAccessChecks SAC(*
this, IsTemplateSpecOrInst);
2960 if (ParseCXXMemberDeclaratorBeforeInitializer(
2961 DeclaratorInfo, VS, BitfieldSize, LateParsedAttrs)) {
2966 if (IsTemplateSpecOrInst)
2974 TryConsumePureSpecifier(
true);
2985 if (Tok.isOneOf(tok::l_brace, tok::colon, tok::kw_try)) {
2987 }
else if (Tok.is(tok::equal)) {
2989 if (KW.
is(tok::kw_default))
2991 else if (KW.
is(tok::kw_delete))
2993 else if (KW.
is(tok::code_completion)) {
2995 Actions.CodeCompletion().CodeCompleteAfterFunctionEquals(
3010 ProhibitAttributes(DeclAttrs);
3027 diag::err_function_declared_typedef);
3033 Decl *FunDecl = ParseCXXInlineMethodDef(AS, AccessAttrs, DeclaratorInfo,
3034 TemplateInfo, VS, PureSpecLoc);
3037 for (
unsigned i = 0, ni = CommonLateParsedAttrs.size(); i < ni; ++i) {
3038 CommonLateParsedAttrs[i]->addDecl(FunDecl);
3040 for (
unsigned i = 0, ni = LateParsedAttrs.size(); i < ni; ++i) {
3041 LateParsedAttrs[i]->addDecl(FunDecl);
3044 LateParsedAttrs.clear();
3047 if (Tok.is(tok::semi))
3060 bool HasStaticInitializer =
false;
3061 if (Tok.isOneOf(tok::equal, tok::l_brace) && PureSpecLoc.
isInvalid()) {
3065 Diag(Tok, diag::err_anon_bitfield_member_init);
3069 if (!TryConsumePureSpecifier(
false))
3071 HasStaticInitializer =
true;
3079 if (BitfieldSize.
get())
3081 ? diag::warn_cxx17_compat_bitfield_member_init
3082 : diag::ext_bitfield_member_init);
3085 HasStaticInitializer =
true;
3093 NamedDecl *ThisDecl =
nullptr;
3101 if (AL.isCXX11Attribute() || AL.isRegularKeywordAttribute()) {
3102 auto Loc = AL.getRange().getBegin();
3103 (AL.isRegularKeywordAttribute()
3104 ?
Diag(Loc, diag::err_keyword_not_allowed) << AL
3105 :
Diag(Loc, diag::err_attributes_not_allowed))
3109 ThisDecl = Actions.ActOnFriendFunctionDecl(
getCurScope(), DeclaratorInfo,
3112 ThisDecl = Actions.ActOnCXXMemberDeclarator(
3113 getCurScope(), AS, DeclaratorInfo, TemplateParams, BitfieldSize.
get(),
3114 VS, HasInClassInit);
3116 if (VarTemplateDecl *VT =
3117 ThisDecl ? dyn_cast<VarTemplateDecl>(ThisDecl) :
nullptr)
3120 ThisDecl = VT->getTemplatedDecl();
3123 Actions.ProcessDeclAttributeList(
getCurScope(), ThisDecl, AccessAttrs);
3132 HasStaticInitializer =
true;
3136 Diag(PureSpecLoc, diag::err_duplicate_virt_specifier) <<
"abstract";
3138 if (ThisDecl && PureSpecLoc.
isValid())
3139 Actions.ActOnPureSpecifier(ThisDecl, PureSpecLoc);
3147 ? diag::warn_cxx98_compat_nonstatic_member_init
3148 : diag::ext_nonstatic_member_init);
3156 Diag(Tok, diag::err_incomplete_array_member_init);
3163 ParseCXXNonStaticMemberInitializer(ThisDecl);
3164 }
else if (HasStaticInitializer) {
3169 if (
Init.isInvalid()) {
3171 Actions.ActOnUninitializedDecl(ThisDecl);
3173 }
else if (ThisDecl)
3174 Actions.AddInitializerToDecl(ThisDecl,
Init.get(),
3178 Actions.ActOnUninitializedDecl(ThisDecl);
3183 for (
unsigned i = 0, ni = CommonLateParsedAttrs.size(); i < ni; ++i)
3184 CommonLateParsedAttrs[i]->addDecl(ThisDecl);
3186 for (
unsigned i = 0, ni = LateParsedAttrs.size(); i < ni; ++i)
3187 LateParsedAttrs[i]->addDecl(ThisDecl);
3189 Actions.FinalizeDeclaration(ThisDecl);
3190 DeclsInGroup.push_back(ThisDecl);
3195 HandleMemberFunctionDeclDelays(DeclaratorInfo, ThisDecl);
3197 LateParsedAttrs.clear();
3199 DeclaratorInfo.complete(ThisDecl);
3203 SourceLocation CommaLoc;
3207 if (Tok.isAtStartOfLine() &&
3212 Diag(CommaLoc, diag::err_expected_semi_declaration)
3224 Diag(CommaLoc, diag::err_multiple_template_declarators)
3225 << TemplateInfo.Kind;
3229 DeclaratorInfo.
clear();
3232 EqualLoc = PureSpecLoc = SourceLocation();
3238 DiagnoseAndSkipCXX11Attributes();
3239 MaybeParseGNUAttributes(DeclaratorInfo);
3240 DiagnoseAndSkipCXX11Attributes();
3242 if (ParseCXXMemberDeclaratorBeforeInitializer(
3243 DeclaratorInfo, VS, BitfieldSize, LateParsedAttrs))
3248 ExpectAndConsume(tok::semi, diag::err_expected_semi_decl_list)) {
3256 return Actions.FinalizeDeclaratorGroup(
getCurScope(), DS, DeclsInGroup);
3259ExprResult Parser::ParseCXXMemberInitializer(
Decl *D,
bool IsFunction,
3261 assert(Tok.isOneOf(tok::equal, tok::l_brace) &&
3262 "Data member initializer not starting with '=' or '{'");
3264 bool IsFieldInitialization = isa_and_present<FieldDecl>(D);
3266 EnterExpressionEvaluationContext Context(
3268 IsFieldInitialization
3276 Actions.ExprEvalContexts.back().InImmediateEscalatingFunctionContext =
3277 IsFieldInitialization;
3280 if (Tok.is(tok::kw_delete)) {
3287 if (IsFunction ||
Next.isOneOf(tok::semi, tok::comma, tok::eof)) {
3293 SkipDeletedFunctionBody();
3296 }
else if (Tok.is(tok::kw_default)) {
3298 Diag(Tok, diag::err_default_delete_in_multiple_declaration)
3306 if (
const auto *PD = dyn_cast_or_null<MSPropertyDecl>(D)) {
3307 Diag(Tok, diag::err_ms_property_initializer) << PD;
3310 return ParseInitializer(D);
3317 while (isClassCompatibleKeyword())
3322 ParsedAttributes Attrs(AttrFactory);
3323 CheckMisplacedCXX11Attribute(Attrs, AttrFixitLoc);
3328 if (Tok.isNot(tok::colon) && Tok.isNot(tok::l_brace))
3334 if (Tok.is(tok::colon)) {
3337 ParsingClassDefinition ParsingDef(*
this, TagDecl,
true,
3340 Actions.ActOnTagStartSkippedDefinition(
getCurScope(), TagDecl);
3343 ParseBaseClause(
nullptr);
3345 Actions.ActOnTagFinishSkippedDefinition(OldContext);
3347 if (!Tok.is(tok::l_brace)) {
3348 Diag(PP.getLocForEndOfToken(PrevTokLocation),
3349 diag::err_expected_lbrace_after_base_specifiers);
3355 assert(Tok.is(tok::l_brace));
3361 if (Tok.is(tok::kw___attribute)) {
3362 ParsedAttributes Attrs(AttrFactory);
3363 MaybeParseGNUAttributes(Attrs);
3372 switch (Tok.getKind()) {
3373 case tok::kw___if_exists:
3374 case tok::kw___if_not_exists:
3375 ParseMicrosoftIfExistsClassDeclaration(TagType, AccessAttrs, AS);
3384 case tok::annot_pragma_vis:
3385 HandlePragmaVisibility();
3387 case tok::annot_pragma_pack:
3390 case tok::annot_pragma_align:
3391 HandlePragmaAlign();
3393 case tok::annot_pragma_ms_pointers_to_members:
3394 HandlePragmaMSPointersToMembers();
3396 case tok::annot_pragma_ms_pragma:
3397 HandlePragmaMSPragma();
3399 case tok::annot_pragma_ms_vtordisp:
3400 HandlePragmaMSVtorDisp();
3402 case tok::annot_pragma_export:
3403 HandlePragmaExport();
3405 case tok::annot_pragma_dump:
3409 case tok::kw_namespace:
3414 case tok::kw_private:
3418 ParsedTemplateInfo TemplateInfo;
3419 return ParseCXXClassMemberDeclaration(AS, AccessAttrs, TemplateInfo);
3422 case tok::kw_public:
3423 case tok::kw_protected: {
3425 Diag(Tok.getLocation(), diag::ext_hlsl_access_specifiers);
3430 SourceLocation ASLoc = Tok.getLocation();
3431 unsigned TokLength = Tok.getLength();
3433 AccessAttrs.
clear();
3434 MaybeParseGNUAttributes(AccessAttrs);
3436 SourceLocation EndLoc;
3439 Diag(EndLoc, diag::err_expected)
3443 Diag(EndLoc, diag::err_expected)
3453 if (Actions.ActOnAccessSpecifier(NewAS, ASLoc, EndLoc, AccessAttrs)) {
3455 AccessAttrs.
clear();
3461 case tok::annot_attr_openmp:
3462 case tok::annot_pragma_openmp:
3463 return ParseOpenMPDeclarativeDirectiveWithExtDecl(
3464 AS, AccessAttrs,
true, TagType, TagDecl);
3465 case tok::annot_pragma_openacc:
3470 Diag(Tok.getLocation(), diag::err_pragma_misplaced_in_decl)
3472 TagType, Actions.getASTContext().getPrintingPolicy());
3473 ConsumeAnnotationToken();
3476 ParsedTemplateInfo TemplateInfo;
3477 return ParseCXXClassMemberDeclaration(AS, AccessAttrs, TemplateInfo);
3488 "Invalid TagType!");
3490 llvm::TimeTraceScope TimeScope(
"ParseClass", [&]() {
3491 if (
auto *TD = dyn_cast_or_null<NamedDecl>(TagDecl))
3492 return TD->getQualifiedNameAsString();
3493 return std::string(
"<anonymous>");
3496 PrettyDeclStackTraceEntry CrashInfo(Actions.Context, TagDecl,
RecordLoc,
3497 "parsing struct/union/class body");
3501 bool NonNestedClass =
true;
3502 if (!ClassStack.empty()) {
3504 if (S->isClassScope()) {
3506 NonNestedClass =
false;
3509 if (getCurrentClass().IsInterface) {
3519 if (S->isFunctionScope())
3530 ParsingClassDefinition ParsingDef(*
this, TagDecl, NonNestedClass,
3534 Actions.ActOnTagStartDefinition(
getCurScope(), TagDecl);
3536 SourceLocation FinalLoc;
3537 SourceLocation AbstractLoc;
3538 bool IsFinalSpelledSealed =
false;
3539 bool IsAbstract =
false;
3548 if (isCXX11FinalKeyword()) {
3551 Diag(Skipped, diag::err_duplicate_class_virt_specifier)
3556 IsFinalSpelledSealed =
true;
3561 Diag(Skipped, diag::err_duplicate_class_virt_specifier)
3569 Diag(FinalLoc, diag::err_override_control_interface)
3573 ? diag::warn_cxx98_compat_override_control_keyword
3574 : diag::ext_override_control_keyword)
3577 Diag(FinalLoc, diag::ext_ms_sealed_keyword);
3579 Diag(AbstractLoc, diag::ext_ms_abstract_keyword);
3581 Diag(FinalLoc, diag::ext_warn_gnu_final);
3584 "not a class definition");
3590 CheckMisplacedCXX11Attribute(Attrs, AttrFixitLoc);
3599 if (!Tok.is(tok::colon) && !Tok.is(tok::l_brace)) {
3601 Actions.ActOnTagDefinitionError(
getCurScope(), TagDecl);
3606 if (Tok.is(tok::colon)) {
3610 ParseBaseClause(TagDecl);
3611 if (!Tok.is(tok::l_brace)) {
3612 bool SuggestFixIt =
false;
3613 SourceLocation BraceLoc = PP.getLocForEndOfToken(PrevTokLocation);
3614 if (Tok.isAtStartOfLine()) {
3615 switch (Tok.getKind()) {
3616 case tok::kw_private:
3617 case tok::kw_protected:
3618 case tok::kw_public:
3621 case tok::kw_static_assert:
3625 case tok::kw_template:
3626 SuggestFixIt =
true;
3628 case tok::identifier:
3629 SuggestFixIt = isConstructorDeclarator(
true);
3632 SuggestFixIt = isCXXSimpleDeclaration(
false);
3636 DiagnosticBuilder LBraceDiag =
3637 Diag(BraceLoc, diag::err_expected_lbrace_after_base_specifiers);
3641 PP.EnterToken(Tok,
true);
3642 Tok.setKind(tok::l_brace);
3645 Actions.ActOnTagDefinitionError(
getCurScope(), TagDecl);
3651 assert(Tok.is(tok::l_brace));
3656 Actions.ActOnStartCXXMemberDeclarations(
getCurScope(), TagDecl, FinalLoc,
3657 IsFinalSpelledSealed, IsAbstract,
3658 T.getOpenLocation());
3669 ParsedAttributes AccessAttrs(AttrFactory);
3673 while (!tryParseMisplacedModuleImport() && Tok.isNot(tok::r_brace) &&
3674 Tok.isNot(tok::eof)) {
3676 ParseCXXClassMemberDeclarationWithPragmas(
3677 CurAS, AccessAttrs,
static_cast<DeclSpec::TST>(TagType), TagDecl);
3678 MaybeDestroyTemplateIds();
3686 ParsedAttributes attrs(AttrFactory);
3687 MaybeParseGNUAttributes(attrs);
3691 T.getOpenLocation(),
3692 T.getCloseLocation(), attrs);
3699 if (TagDecl && NonNestedClass) {
3705 SourceLocation SavedPrevTokLocation = PrevTokLocation;
3706 ParseLexedPragmas(getCurrentClass());
3707 ParseLexedAttributes(getCurrentClass());
3708 ParseLexedMethodDeclarations(getCurrentClass());
3711 Actions.ActOnFinishCXXMemberDecls();
3713 ParseLexedMemberInitializers(getCurrentClass());
3714 ParseLexedMethodDefs(getCurrentClass());
3715 PrevTokLocation = SavedPrevTokLocation;
3719 Actions.ActOnFinishCXXNonNestedClass();
3723 Actions.ActOnTagFinishDefinition(
getCurScope(), TagDecl,
T.getRange());
3730void Parser::DiagnoseUnexpectedNamespace(
NamedDecl *D) {
3731 assert(Tok.is(tok::kw_namespace));
3736 Diag(Tok.getLocation(), diag::note_missing_end_of_definition_before) << D;
3739 PP.EnterToken(Tok,
true);
3742 Tok.
setLocation(PP.getLocForEndOfToken(PrevTokLocation));
3743 Tok.setKind(tok::semi);
3744 PP.EnterToken(Tok,
true);
3746 Tok.setKind(tok::r_brace);
3749void Parser::ParseConstructorInitializer(
Decl *ConstructorDecl) {
3750 assert(Tok.is(tok::colon) &&
3751 "Constructor initializer always starts with ':'");
3758 SmallVector<CXXCtorInitializer *, 4> MemInitializers;
3759 bool AnyErrors =
false;
3762 if (Tok.is(tok::code_completion)) {
3764 Actions.CodeCompletion().CodeCompleteConstructorInitializer(
3765 ConstructorDecl, MemInitializers);
3769 MemInitResult MemInit = ParseMemInitializer(ConstructorDecl);
3771 MemInitializers.push_back(MemInit.
get());
3775 if (Tok.is(tok::comma))
3777 else if (Tok.is(tok::l_brace))
3782 Tok.isOneOf(tok::identifier, tok::coloncolon)) {
3783 SourceLocation Loc = PP.getLocForEndOfToken(PrevTokLocation);
3784 Diag(Loc, diag::err_ctor_init_missing_comma)
3789 Diag(Tok.getLocation(), diag::err_expected_either)
3790 << tok::l_brace << tok::comma;
3796 Actions.ActOnMemInitializers(ConstructorDecl, ColonLoc, MemInitializers,
3803 if (ParseOptionalCXXScopeSpecifier(SS,
nullptr,
3809 IdentifierInfo *II =
nullptr;
3810 SourceLocation IdLoc = Tok.getLocation();
3812 DeclSpec DS(AttrFactory);
3816 if (Tok.is(tok::identifier)) {
3819 II = Tok.getIdentifierInfo();
3821 }
else if (Tok.is(tok::annot_decltype)) {
3826 ParseDecltypeSpecifier(DS);
3827 }
else if (Tok.is(tok::annot_pack_indexing_type)) {
3830 ParsePackIndexingType(DS);
3832 TemplateIdAnnotation *TemplateId = Tok.is(tok::annot_template_id)
3833 ? takeTemplateIdAnnotation(Tok)
3838 assert(Tok.is(tok::annot_typename) &&
"template-id -> type failed");
3840 ConsumeAnnotationToken();
3842 Diag(Tok, diag::err_expected_member_or_base_name);
3849 Diag(Tok, diag::warn_cxx98_compat_generalized_initializer_lists);
3852 ExprResult InitList = ParseBraceInitializer();
3856 SourceLocation EllipsisLoc;
3861 return Actions.ActOnMemInitializer(ConstructorDecl,
getCurScope(), SS, II,
3862 TemplateTypeTy.
get(), DS, IdLoc,
3863 InitList.
get(), EllipsisLoc);
3864 }
else if (Tok.is(tok::l_paren)) {
3869 ExprVector ArgExprs;
3870 auto RunSignatureHelp = [&] {
3873 QualType PreferredType =
3874 Actions.CodeCompletion().ProduceCtorInitMemberSignatureHelp(
3875 ConstructorDecl, SS, TemplateTypeTy.
get(), ArgExprs, II,
3876 T.getOpenLocation(),
false);
3877 CalledSignatureHelp =
true;
3878 return PreferredType;
3880 if (Tok.isNot(tok::r_paren) && ParseExpressionList(ArgExprs, [&] {
3881 PreferredType.enterFunctionArgument(Tok.getLocation(),
3884 if (PP.isCodeCompletionReached() && !CalledSignatureHelp)
3892 SourceLocation EllipsisLoc;
3897 return Actions.ActOnMemInitializer(
3898 ConstructorDecl,
getCurScope(), SS, II, TemplateTypeTy.
get(), DS, IdLoc,
3899 T.getOpenLocation(), ArgExprs,
T.getCloseLocation(), EllipsisLoc);
3906 return Diag(Tok, diag::err_expected_either) << tok::l_paren << tok::l_brace;
3908 return Diag(Tok, diag::err_expected) << tok::l_paren;
3917 ExceptionSpecTokens =
nullptr;
3921 if (Tok.isNot(tok::kw_throw) && Tok.isNot(tok::kw_noexcept))
3925 bool IsNoexcept = Tok.is(tok::kw_noexcept);
3926 Token StartTok = Tok;
3930 if (!Tok.is(tok::l_paren)) {
3933 Diag(Tok, diag::warn_cxx98_compat_noexcept_decl);
3934 NoexceptExpr =
nullptr;
3938 Diag(Tok, diag::err_expected_lparen_after) <<
"throw";
3944 ExceptionSpecTokens->push_back(StartTok);
3945 ExceptionSpecTokens->push_back(Tok);
3946 SpecificationRange.
setEnd(ConsumeParen());
3948 ConsumeAndStoreUntil(tok::r_paren, *ExceptionSpecTokens,
3951 SpecificationRange.
setEnd(ExceptionSpecTokens->back().getLocation());
3957 if (Tok.is(tok::kw_throw)) {
3958 Result = ParseDynamicExceptionSpecification(
3959 SpecificationRange, DynamicExceptions, DynamicExceptionRanges);
3960 assert(DynamicExceptions.size() == DynamicExceptionRanges.size() &&
3961 "Produced different number of exception types and ranges.");
3965 if (Tok.isNot(tok::kw_noexcept))
3968 Diag(Tok, diag::warn_cxx98_compat_noexcept_decl);
3972 SourceRange NoexceptRange;
3976 if (Tok.is(tok::l_paren)) {
3981 EnterExpressionEvaluationContext ConstantEvaluated(
3988 Actions.ActOnNoexceptSpec(NoexceptExpr.
get(), NoexceptType);
3989 NoexceptRange = SourceRange(KeywordLoc,
T.getCloseLocation());
3996 NoexceptRange = SourceRange(KeywordLoc, KeywordLoc);
4000 SpecificationRange = NoexceptRange;
4005 if (Tok.is(tok::kw_throw)) {
4006 Diag(Tok.getLocation(), diag::err_dynamic_and_noexcept_specification);
4007 ParseDynamicExceptionSpecification(NoexceptRange, DynamicExceptions,
4008 DynamicExceptionRanges);
4011 Diag(Tok.getLocation(), diag::err_dynamic_and_noexcept_specification);
4020 const char *Replacement = IsNoexcept ?
"noexcept" :
"noexcept(false)";
4022 ? diag::ext_dynamic_exception_spec
4023 : diag::warn_exception_spec_deprecated)
4025 P.
Diag(Range.getBegin(), diag::note_exception_spec_deprecated)
4033 assert(Tok.is(tok::kw_throw) &&
"expected throw");
4037 if (
T.consumeOpen()) {
4038 Diag(Tok, diag::err_expected_lparen_after) <<
"throw";
4045 if (Tok.is(tok::ellipsis)) {
4048 Diag(EllipsisLoc, diag::ext_ellipsis_exception_spec);
4050 SpecificationRange.
setEnd(
T.getCloseLocation());
4057 while (Tok.isNot(tok::r_paren)) {
4060 if (Tok.is(tok::ellipsis)) {
4065 Range.setEnd(Ellipsis);
4066 if (!Res.isInvalid())
4067 Res = Actions.ActOnPackExpansion(Res.get(), Ellipsis);
4070 if (!Res.isInvalid()) {
4071 Exceptions.push_back(Res.get());
4072 Ranges.push_back(Range);
4080 SpecificationRange.
setEnd(
T.getCloseLocation());
4082 Exceptions.empty());
4087 bool MayBeFollowedByDirectInit) {
4088 assert(Tok.is(tok::arrow) &&
"expected arrow");
4097void Parser::ParseTrailingRequiresClause(
Declarator &D) {
4098 assert(Tok.is(tok::kw_requires) &&
"expected requires");
4116 DeclaratorScopeObj DeclScopeObj(*
this, SS);
4118 DeclScopeObj.EnterDeclaratorScope();
4125 Actions.ActOnStartTrailingRequiresClause(
getCurScope(), D);
4127 std::optional<Sema::CXXThisScopeRAII> ThisScope;
4128 InitCXXThisScopeForDeclaratorIfRelevant(D, D.
getDeclSpec(), ThisScope);
4130 TrailingRequiresClause =
4133 TrailingRequiresClause =
4134 Actions.ActOnFinishTrailingRequiresClause(TrailingRequiresClause);
4138 diag::err_requires_clause_on_declarator_not_declaring_a_function);
4143 SkipUntil({tok::l_brace, tok::arrow, tok::kw_try, tok::comma, tok::colon},
4151 SourceLocation ArrowLoc = Tok.getLocation();
4154 ParseTrailingReturnType(Range,
false);
4158 diag::err_requires_clause_must_appear_after_trailing_return)
4162 FunctionChunk.TrailingReturnType = TrailingReturnType.
get();
4163 FunctionChunk.TrailingReturnTypeLoc =
Range.getBegin();
4165 SkipUntil({tok::equal, tok::l_brace, tok::arrow, tok::kw_try, tok::comma},
4171 bool NonNestedClass,
4173 assert((NonNestedClass || !ClassStack.empty()) &&
4174 "Nested class without outer class");
4175 ClassStack.push(
new ParsingClass(ClassDecl, NonNestedClass, IsInterface));
4176 return Actions.PushParsingClass();
4179void Parser::DeallocateParsedClasses(Parser::ParsingClass *
Class) {
4180 for (
unsigned I = 0, N =
Class->LateParsedDeclarations.size(); I != N; ++I)
4181 delete Class->LateParsedDeclarations[I];
4186 assert(!ClassStack.empty() &&
"Mismatched push/pop for class parsing");
4188 Actions.PopParsingClass(state);
4190 ParsingClass *Victim = ClassStack.top();
4192 if (Victim->TopLevelClass) {
4195 DeallocateParsedClasses(Victim);
4198 assert(!ClassStack.empty() &&
"Missing top-level class?");
4200 if (Victim->LateParsedDeclarations.empty()) {
4205 DeallocateParsedClasses(Victim);
4213 "Nested class outside of class scope?");
4214 ClassStack.top()->LateParsedDeclarations.push_back(
4215 new LateParsedClass(
this, Victim));
4221 switch (Tok.getKind()) {
4224 if (!Tok.isAnnotation()) {
4225 if (IdentifierInfo *II = Tok.getIdentifierInfo()) {
4232 case tok::code_completion:
4234 Actions.CodeCompletion().CodeCompleteAttribute(
4239 case tok::numeric_constant: {
4243 if (Tok.getLocation().isMacroID()) {
4244 SmallString<8> ExpansionBuf;
4245 SourceLocation ExpansionLoc =
4246 PP.getSourceManager().getExpansionLoc(Tok.getLocation());
4247 StringRef Spelling = PP.getSpelling(ExpansionLoc, ExpansionBuf);
4248 if (Spelling ==
"__clang__") {
4249 SourceRange TokRange(
4251 PP.getSourceManager().getExpansionLoc(Tok.getEndLoc()));
4252 Diag(Tok, diag::warn_wrong_clang_attr_namespace)
4255 return &PP.getIdentifierTable().get(
"_Clang");
4268 case tok::pipeequal:
4269 case tok::caretequal:
4271 case tok::exclaimequal:
4274 SmallString<8> SpellingBuf;
4275 SourceLocation SpellingLoc =
4276 PP.getSourceManager().getSpellingLoc(Tok.getLocation());
4277 StringRef Spelling = PP.getSpelling(SpellingLoc, SpellingBuf);
4280 return &PP.getIdentifierTable().get(Spelling);
4286void Parser::ParseOpenMPAttributeArgs(
const IdentifierInfo *AttrName,
4291 if (
T.consumeOpen()) {
4292 Diag(Tok, diag::err_expected) << tok::l_paren;
4296 if (
AttrName->isStr(
"directive")) {
4302 OMPBeginTok.
setKind(tok::annot_attr_openmp);
4304 OpenMPTokens.push_back(OMPBeginTok);
4306 ConsumeAndStoreUntil(tok::r_paren, OpenMPTokens,
false,
4310 OMPEndTok.
setKind(tok::annot_pragma_openmp_end);
4312 OpenMPTokens.push_back(OMPEndTok);
4314 assert(
AttrName->isStr(
"sequence") &&
4315 "Expected either 'directive' or 'sequence'");
4323 SourceLocation IdentLoc;
4324 const IdentifierInfo *Ident = TryParseCXX11AttributeIdentifier(IdentLoc);
4328 if (Ident && Ident->
isStr(
"omp") && !ExpectAndConsume(tok::coloncolon))
4329 Ident = TryParseCXX11AttributeIdentifier(IdentLoc);
4333 if (!Ident || (!Ident->
isStr(
"directive") && !Ident->
isStr(
"sequence"))) {
4334 Diag(Tok.getLocation(), diag::err_expected_sequence_or_directive);
4340 ParseOpenMPAttributeArgs(Ident, OpenMPTokens);
4354 case ParsedAttr::AT_CarriesDependency:
4355 case ParsedAttr::AT_Deprecated:
4356 case ParsedAttr::AT_FallThrough:
4357 case ParsedAttr::AT_CXX11NoReturn:
4358 case ParsedAttr::AT_NoUniqueAddress:
4359 case ParsedAttr::AT_Likely:
4360 case ParsedAttr::AT_Unlikely:
4362 case ParsedAttr::AT_WarnUnusedResult:
4363 return !ScopeName && AttrName->getName() ==
"nodiscard";
4364 case ParsedAttr::AT_Unused:
4365 return !ScopeName && AttrName->getName() ==
"maybe_unused";
4371bool Parser::ParseCXXAssumeAttributeArg(
4375 assert(Tok.is(tok::l_paren) &&
"Not a C++11 attribute argument list");
4383 TentativeParsingAction TPA(*
this);
4388 if (Tok.is(tok::r_paren))
4393 if (!Tok.isOneOf(tok::r_paren, tok::r_square)) {
4399 auto *E = Res.
get();
4400 Diag(E->getExprLoc(), diag::err_assume_attr_expects_cond_expr)
4404 << E->getSourceRange();
4413 auto RParen = Tok.getLocation();
4415 Attrs.
addNew(AttrName, SourceRange(AttrNameLoc, RParen),
4416 AttributeScopeInfo(ScopeName, ScopeLoc), &Assumption, 1, Form);
4424bool Parser::ParseCXX11AttributeArgs(
4428 assert(Tok.is(tok::l_paren) &&
"Not a C++11 attribute argument list");
4429 SourceLocation LParenLoc = Tok.getLocation();
4431 ParsedAttr::Form Form =
4432 LO.CPlusPlus ? ParsedAttr::Form::CXX11() : ParsedAttr::Form::
C23();
4438 Form = ParsedAttr::Form::Microsoft();
4442 TentativeParsingAction TPA(*this);
4443 bool HasInvalidArgument = false;
4444 while (Tok.isNot(tok::r_paren) && Tok.isNot(tok::eof)) {
4445 if (Tok.isOneOf(tok::hash, tok::hashhash)) {
4446 Diag(Tok.getLocation(), diag::ext_invalid_attribute_argument)
4447 << PP.getSpelling(Tok);
4448 HasInvalidArgument = true;
4453 if (HasInvalidArgument) {
4467 ScopeName, AttrName, getTargetInfo(), getLangOpts())) {
4470 SkipUntil(tok::r_paren);
4474 if (ScopeName && (ScopeName->
isStr(
"gnu") || ScopeName->
isStr(
"__gnu__"))) {
4477 ParseGNUAttributeArgs(AttrName, AttrNameLoc, Attrs, EndLoc, ScopeName,
4478 ScopeLoc, Form, nullptr);
4483 if (ScopeName && ScopeName->
isStr(
"omp") &&
4485 Diag(AttrNameLoc, getLangOpts().OpenMP >= 51
4486 ? diag::warn_omp51_compat_attributes
4487 : diag::ext_omp_attributes);
4489 ParseOpenMPAttributeArgs(AttrName, OpenMPTokens);
4498 if (ScopeName && (ScopeName->
isStr(
"clang") || ScopeName->
isStr(
"_Clang")))
4499 NumArgs = ParseClangAttributeArgs(AttrName, AttrNameLoc, Attrs, EndLoc,
4500 ScopeName, ScopeLoc, Form);
4502 else if (!ScopeName &&
AttrName->isStr(
"assume")) {
4503 if (ParseCXXAssumeAttributeArg(Attrs, AttrName, AttrNameLoc, nullptr,
4504 SourceLocation{}, EndLoc, Form))
4508 NumArgs = ParseAttributeArgsCommon(AttrName, AttrNameLoc, Attrs, EndLoc,
4509 ScopeName, ScopeLoc, Form);
4511 if (!Attrs.
empty() &&
4516 if (!
Attr.existsInTarget(getTargetInfo())) {
4517 Actions.DiagnoseUnknownAttribute(
Attr);
4518 Attr.setInvalid(
true);
4526 if (
Attr.getMaxArgs() && !NumArgs) {
4529 Diag(LParenLoc, diag::err_attribute_requires_arguments) <<
AttrName;
4530 Attr.setInvalid(
true);
4531 }
else if (!
Attr.getMaxArgs()) {
4535 Diag(LParenLoc, diag::err_cxx11_attribute_forbids_arguments)
4538 Attr.setInvalid(
true);
4547 if (Tok.is(tok::kw_alignas)) {
4553 Diag(Tok.getLocation(), diag::warn_cxx98_compat_alignas);
4554 ParseAlignmentSpecifier(Attrs, EndLoc);
4558 if (Tok.isRegularKeywordAttribute()) {
4559 SourceLocation Loc = Tok.getLocation();
4560 IdentifierInfo *
AttrName = Tok.getIdentifierInfo();
4561 ParsedAttr::Form Form = ParsedAttr::Form(Tok.getKind());
4565 if (!Tok.is(tok::l_paren))
4566 Diag(Tok.getLocation(), diag::err_expected_lparen_after) <<
AttrName;
4568 ParseAttributeArgsCommon(AttrName, Loc, Attrs, EndLoc,
4572 Attrs.
addNew(AttrName, Loc, AttributeScopeInfo(),
nullptr, 0, Form);
4576 assert(Tok.is(tok::l_square) &&
NextToken().
is(tok::l_square) &&
4577 "Not a double square bracket attribute list");
4579 SourceLocation OpenLoc = Tok.getLocation();
4582 : diag::warn_ext_cxx11_attributes);
4585 : diag::warn_ext_c23_attributes);
4589 checkCompoundToken(OpenLoc, tok::l_square, CompoundToken::AttrBegin);
4592 SourceLocation CommonScopeLoc;
4593 IdentifierInfo *CommonScopeName =
nullptr;
4594 if (Tok.is(tok::kw_using)) {
4596 ? diag::warn_cxx14_compat_using_attribute_ns
4597 : diag::ext_using_attribute_ns);
4600 CommonScopeName = TryParseCXX11AttributeIdentifier(
4602 if (!CommonScopeName) {
4603 Diag(Tok.getLocation(), diag::err_expected) << tok::identifier;
4607 Diag(Tok.getLocation(), diag::err_expected) << tok::colon;
4610 bool AttrParsed =
false;
4611 while (!Tok.isOneOf(tok::r_square, tok::semi, tok::eof)) {
4615 if (ExpectAndConsume(tok::comma)) {
4626 SourceLocation ScopeLoc, AttrLoc;
4627 IdentifierInfo *ScopeName =
nullptr, *
AttrName =
nullptr;
4629 AttrName = TryParseCXX11AttributeIdentifier(
4641 AttrName = TryParseCXX11AttributeIdentifier(
4645 Diag(Tok.getLocation(), diag::err_expected) << tok::identifier;
4651 if (CommonScopeName) {
4653 Diag(ScopeLoc, diag::err_using_attribute_ns_conflict)
4654 << SourceRange(CommonScopeLoc);
4656 ScopeName = CommonScopeName;
4657 ScopeLoc = CommonScopeLoc;
4662 if (Tok.is(tok::l_paren))
4663 AttrParsed = ParseCXX11AttributeArgs(AttrName, AttrLoc, Attrs, EndLoc,
4664 ScopeName, ScopeLoc, OpenMPTokens);
4672 AttributeScopeInfo(ScopeName, ScopeLoc, CommonScopeLoc),
4675 : ParsedAttr::Form::C23());
4680 Diag(Tok, diag::err_cxx11_attribute_forbids_ellipsis) <<
AttrName;
4685 if (Tok.is(tok::semi)) {
4690 SourceLocation CloseLoc = Tok.getLocation();
4691 if (ExpectAndConsume(tok::r_square))
4693 else if (Tok.is(tok::r_square))
4694 checkCompoundToken(CloseLoc, tok::r_square, CompoundToken::AttrEnd);
4696 *EndLoc = Tok.getLocation();
4697 if (ExpectAndConsume(tok::r_square))
4702 SourceLocation StartLoc = Tok.getLocation();
4703 SourceLocation EndLoc = StartLoc;
4706 ParseCXX11AttributeSpecifier(Attrs, &EndLoc);
4707 }
while (isAllowedCXX11AttributeSpecifier());
4709 Attrs.
Range = SourceRange(StartLoc, EndLoc);
4712void Parser::DiagnoseAndSkipCXX11Attributes() {
4714 Tok.isRegularKeywordAttribute() ? Tok.getIdentifierInfo() :
nullptr;
4716 SourceLocation StartLoc = Tok.getLocation();
4717 SourceLocation EndLoc = SkipCXX11Attributes();
4720 SourceRange
Range(StartLoc, EndLoc);
4722 :
Diag(StartLoc, diag::err_attributes_not_allowed))
4728 SourceLocation EndLoc;
4734 if (Tok.is(tok::l_square)) {
4738 EndLoc =
T.getCloseLocation();
4739 }
else if (Tok.isRegularKeywordAttribute() &&
4741 EndLoc = Tok.getLocation();
4744 assert((Tok.is(tok::kw_alignas) || Tok.isRegularKeywordAttribute()) &&
4745 "not an attribute specifier");
4748 if (!
T.consumeOpen())
4750 EndLoc =
T.getCloseLocation();
4752 }
while (isCXX11AttributeSpecifier() !=
4759 assert(Tok.is(tok::identifier) &&
"Not a Microsoft attribute list");
4760 IdentifierInfo *UuidIdent = Tok.getIdentifierInfo();
4761 assert(UuidIdent->
getName() ==
"uuid" &&
"Not a Microsoft attribute list");
4763 SourceLocation UuidLoc = Tok.getLocation();
4768 if (
T.consumeOpen()) {
4769 Diag(Tok, diag::err_expected) << tok::l_paren;
4774 if (isTokenStringLiteral()) {
4779 ArgExprs.push_back(StringResult.
get());
4785 SmallString<42> StrBuffer;
4795 SourceLocation StartLoc = Tok.getLocation();
4796 while (Tok.isNot(tok::r_paren)) {
4797 if (Tok.hasLeadingSpace() || Tok.isAtStartOfLine()) {
4798 Diag(Tok, diag::err_attribute_uuid_malformed_guid);
4802 SmallString<16> SpellingBuffer;
4803 SpellingBuffer.resize(Tok.getLength() + 1);
4804 bool Invalid =
false;
4805 StringRef TokSpelling = PP.getSpelling(Tok, SpellingBuffer, &Invalid);
4810 StrBuffer += TokSpelling;
4815 if (Tok.hasLeadingSpace() || Tok.isAtStartOfLine()) {
4816 Diag(Tok, diag::err_attribute_uuid_malformed_guid);
4826 Toks[0].
setKind(tok::string_literal);
4830 StringLiteral *UuidString =
4832 ArgExprs.push_back(UuidString);
4835 if (!
T.consumeClose()) {
4836 Attrs.
addNew(UuidIdent, SourceRange(UuidLoc,
T.getCloseLocation()),
4837 AttributeScopeInfo(), ArgExprs.data(), ArgExprs.size(),
4838 ParsedAttr::Form::Microsoft());
4843 assert(Tok.is(tok::identifier) &&
4844 "Expected an identifier to denote which MS attribute to consider");
4845 IdentifierInfo *RootSignatureIdent = Tok.getIdentifierInfo();
4846 assert(RootSignatureIdent->
getName() ==
"RootSignature" &&
4847 "Expected RootSignature identifier for root signature attribute");
4849 SourceLocation RootSignatureLoc = Tok.getLocation();
4854 if (
T.consumeOpen()) {
4855 Diag(Tok, diag::err_expected) << tok::l_paren;
4859 auto ProcessStringLiteral = [
this]() -> std::optional<StringLiteral *> {
4860 if (!isTokenStringLiteral())
4861 return std::nullopt;
4865 return std::nullopt;
4867 if (
auto Lit = dyn_cast<StringLiteral>(StringResult.
get()))
4870 return std::nullopt;
4873 auto Signature = ProcessStringLiteral();
4874 if (!Signature.has_value()) {
4875 Diag(Tok, diag::err_expected_string_literal)
4876 << 4 <<
"RootSignature";
4882 Actions,
getLangOpts().HLSLRootSigVer, *Signature);
4890 IdentifierLoc *ILoc = ::new (Actions.getASTContext())
4891 IdentifierLoc(RootSignatureLoc, DeclIdent);
4895 if (!
T.consumeClose())
4896 Attrs.
addNew(RootSignatureIdent,
4897 SourceRange(RootSignatureLoc,
T.getCloseLocation()),
4898 AttributeScopeInfo(), Args.data(), Args.size(),
4899 ParsedAttr::Form::Microsoft());
4903 assert(Tok.is(tok::l_square) &&
"Not a Microsoft attribute list");
4905 SourceLocation StartLoc = Tok.getLocation();
4906 SourceLocation EndLoc = StartLoc;
4914 SkipUntil(tok::r_square, tok::identifier,
4916 if (Tok.is(tok::code_completion)) {
4918 Actions.CodeCompletion().CodeCompleteAttribute(
4924 if (Tok.isNot(tok::identifier))
4926 if (Tok.getIdentifierInfo()->getName() ==
"uuid")
4927 ParseMicrosoftUuidAttributeArgs(Attrs);
4928 else if (Tok.getIdentifierInfo()->getName() ==
"RootSignature")
4929 ParseHLSLRootSignatureAttributeArgs(Attrs);
4931 IdentifierInfo *II = Tok.getIdentifierInfo();
4932 SourceLocation NameLoc = Tok.getLocation();
4939 bool AttrParsed =
false;
4940 if (Tok.is(tok::l_paren)) {
4943 ParseCXX11AttributeArgs(II, NameLoc, Attrs, &EndLoc,
nullptr,
4944 SourceLocation(), OpenMPTokens);
4945 ReplayOpenMPAttributeTokens(OpenMPTokens);
4948 Attrs.
addNew(II, NameLoc, AttributeScopeInfo(),
nullptr, 0,
4949 ParsedAttr::Form::Microsoft());
4956 EndLoc =
T.getCloseLocation();
4957 }
while (Tok.is(tok::l_square));
4959 Attrs.
Range = SourceRange(StartLoc, EndLoc);
4962void Parser::ParseMicrosoftIfExistsClassDeclaration(
4965 IfExistsCondition
Result;
4966 if (ParseMicrosoftIfExistsCondition(
Result))
4970 if (
Braces.consumeOpen()) {
4971 Diag(Tok, diag::err_expected) << tok::l_brace;
4975 switch (
Result.Behavior) {
4981 Diag(
Result.KeywordLoc, diag::warn_microsoft_dependent_exists)
4991 while (Tok.isNot(tok::r_brace) && !isEofOrEom()) {
4993 if (Tok.isOneOf(tok::kw___if_exists, tok::kw___if_not_exists)) {
4994 ParseMicrosoftIfExistsClassDeclaration(TagType, AccessAttrs, CurAS);
4999 if (Tok.is(tok::semi)) {
5008 SourceLocation ASLoc = Tok.getLocation();
5010 if (Tok.is(tok::colon))
5011 Actions.ActOnAccessSpecifier(AS, ASLoc, Tok.getLocation(),
5012 ParsedAttributesView{});
5014 Diag(Tok, diag::err_expected) << tok::colon;
5019 ParsedTemplateInfo TemplateInfo;
5021 ParseCXXClassMemberDeclaration(CurAS, AccessAttrs, TemplateInfo);
Defines the clang::ASTContext interface.
This file defines the classes used to store parsed information about declaration-specifiers and decla...
Defines the C++ template declaration subclasses.
static DiagnosticBuilder Diag(DiagnosticsEngine *Diags, const LangOptions &Features, FullSourceLoc TokLoc, const char *TokBegin, const char *TokRangeBegin, const char *TokRangeEnd, unsigned DiagID)
Produce a diagnostic highlighting some portion of a literal.
llvm::MachO::RecordLoc RecordLoc
static void diagnoseDynamicExceptionSpecification(Parser &P, SourceRange Range, bool IsNoexcept)
static bool IsBuiltInOrStandardCXX11Attribute(IdentifierInfo *AttrName, IdentifierInfo *ScopeName)
static FixItHint getStaticAssertNoMessageFixIt(const Expr *AssertExpr, SourceLocation EndExprLoc)
This file declares facilities that support code completion.
This file declares semantic analysis for HLSL constructs.
Defines the clang::TokenKind enum and support functions.
#define TRANSFORM_TYPE_TRAIT_DEF(Enum, _)
Attr - This represents one attribute.
@ AS_Microsoft
[uuid("...")] class Foo
Kind getParsedKind() const
RAII class that helps handle the parsing of an open/close delimiter pair, such as braces { ....
SourceLocation getOpenLocation() const
SourceLocation getCloseLocation() const
bool isNotEmpty() const
A scope specifier is present, but may be valid or invalid.
bool isValid() const
A scope specifier is present, and it refers to a real scope.
SourceRange getRange() const
SourceLocation getBeginLoc() const
bool isSet() const
Deprecated.
bool isInvalid() const
An error occurred during parsing of the scope specifier.
void setTemplateParamLists(ArrayRef< TemplateParameterList * > L)
static CharSourceRange getTokenRange(SourceRange R)
Captures information about "declaration specifiers".
void setTypeArgumentRange(SourceRange range)
static const TST TST_typename
void ClearStorageClassSpecs()
TST getTypeSpecType() const
SCS getStorageClassSpec() const
bool SetTypeSpecType(TST T, SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID, const PrintingPolicy &Policy)
SourceRange getSourceRange() const LLVM_READONLY
void SetPackIndexingExpr(SourceLocation EllipsisLoc, Expr *Pack)
void SetRangeEnd(SourceLocation Loc)
static const TST TST_interface
unsigned getTypeQualifiers() const
getTypeQualifiers - Return a set of TQs.
void SetRangeStart(SourceLocation Loc)
static const TST TST_union
static const TST TST_typename_pack_indexing
SourceLocation getFriendSpecLoc() const
SourceLocation getModulePrivateSpecLoc() const
bool isFriendSpecifiedFirst() const
Expr * getRepAsExpr() const
static const TST TST_decltype
void takeAttributesAppendingingFrom(ParsedAttributes &attrs)
static const TST TST_class
bool hasTagDefinition() const
static const char * getSpecifierName(DeclSpec::TST T, const PrintingPolicy &Policy)
Turn a type-specifier-type into a string like "_Bool" or "union".
Decl * getRepAsDecl() const
CXXScopeSpec & getTypeSpecScope()
static const TST TST_decltype_auto
void setExternInLinkageSpec(bool Value)
static const TST TST_error
void forEachQualifier(llvm::function_ref< void(TQ, StringRef, SourceLocation)> Handle)
This method calls the passed in handler on each qual being set.
FriendSpecified isFriendSpecified() const
static const TST TST_struct
Decl - This represents one declaration (or definition), e.g.
void setInvalidDecl(bool Invalid=true)
setInvalidDecl - Indicates the Decl had a semantic error.
bool isInvalidDecl() const
SourceLocation getLocation() const
void setLocation(SourceLocation L)
Information about one declarator, including the parsed type information and the identifier.
bool isFunctionDeclarator(unsigned &idx) const
isFunctionDeclarator - This method returns true if the declarator is a function declarator (looking t...
bool isPastIdentifier() const
isPastIdentifier - Return true if we have parsed beyond the point where the name would appear.
bool isArrayOfUnknownBound() const
isArrayOfUnknownBound - This method returns true if the declarator is a declarator for an array of un...
bool isDeclarationOfFunction() const
Determine whether the declaration that will be produced from this declaration will be a function.
void setCommaLoc(SourceLocation CL)
const DeclSpec & getDeclSpec() const
getDeclSpec - Return the declaration-specifier that this declarator was declared with.
const ParsedAttributes & getAttributes() const
SourceLocation getIdentifierLoc() const
void SetIdentifier(const IdentifierInfo *Id, SourceLocation IdLoc)
Set the name of this declarator to be the given identifier.
void setTrailingRequiresClause(Expr *TRC)
Sets a trailing requires clause for this declarator.
void setTemplateParameterLists(ArrayRef< TemplateParameterList * > TPLs)
Sets the template parameter lists that preceded the declarator.
bool isFirstDeclarator() const
void setFunctionDefinitionKind(FunctionDefinitionKind Val)
const CXXScopeSpec & getCXXScopeSpec() const
getCXXScopeSpec - Return the C++ scope specifier (global scope or nested-name-specifier) that is part...
bool hasName() const
hasName - Whether this declarator has a name, which might be an identifier (accessible via getIdentif...
void clear()
Reset the contents of this Declarator.
void setAsmLabel(Expr *E)
void ExtendWithDeclSpec(const DeclSpec &DS)
ExtendWithDeclSpec - Extend the declarator source range to include the given declspec,...
void SetRangeEnd(SourceLocation Loc)
SetRangeEnd - Set the end of the source range to Loc, unless it's invalid.
bool isStaticMember()
Returns true if this declares a static member.
DeclaratorChunk::FunctionTypeInfo & getFunctionTypeInfo()
getFunctionTypeInfo - Retrieves the function type info object (looking through parentheses).
This represents one expression.
Annotates a diagnostic with some code that should be inserted, removed, or replaced to fix the proble...
static FixItHint CreateInsertionFromRange(SourceLocation InsertionLoc, CharSourceRange FromRange, bool BeforePreviousInsertions=false)
Create a code modification hint that inserts the given code from FromRange at a specific location.
static FixItHint CreateReplacement(CharSourceRange RemoveRange, StringRef Code)
Create a code modification hint that replaces the given source range with the given code string.
static FixItHint CreateRemoval(CharSourceRange RemoveRange)
Create a code modification hint that removes the given source range.
static FixItHint CreateInsertion(SourceLocation InsertionLoc, StringRef Code, bool BeforePreviousInsertions=false)
Create a code modification hint that inserts the given code string at a specific location.
One of these records is kept for each identifier that is lexed.
bool isStr(const char(&Str)[StrLen]) const
Return true if this is the identifier for the specified string.
void revertTokenIDToIdentifier()
Revert TokenID to tok::identifier; used for GNU libstdc++ 4.2 compatibility.
StringRef getName() const
Return the actual identifier string.
static IntegerLiteral * Create(const ASTContext &C, const llvm::APInt &V, QualType type, SourceLocation l)
Returns a new integer literal with value 'V' and type 'type'.
This represents a decl that may have a name.
@ Namespace
A namespace-like entity, stored as a NamespaceBaseDecl*.
static OpaquePtr make(DeclGroupRef P)
ParsedAttr - Represents a syntactic attribute.
static const ParsedAttributesView & none()
void prepend(iterator B, iterator E)
ParsedAttributes - A collection of parsed attributes.
void takeAllPrependingFrom(ParsedAttributes &Other)
void takeAllAppendingFrom(ParsedAttributes &Other)
ParsedAttr * addNew(IdentifierInfo *attrName, SourceRange attrRange, AttributeScopeInfo scope, ArgsUnion *args, unsigned numArgs, ParsedAttr::Form form, SourceLocation ellipsisLoc=SourceLocation())
Add attribute with expression arguments.
ParseScope - Introduces a new scope for parsing.
Parser - This implements a parser for the C family of languages.
TypeResult ParseTypeName(SourceRange *Range=nullptr, DeclaratorContext Context=DeclaratorContext::TypeName, AccessSpecifier AS=AS_none, Decl **OwnedType=nullptr, ParsedAttributes *Attrs=nullptr)
ParseTypeName.
DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID)
SourceLocation ConsumeToken()
ConsumeToken - Consume the current 'peek token' and lex the next one.
static TypeResult getTypeAnnotation(const Token &Tok)
getTypeAnnotation - Read a parsed type out of an annotation token.
ExprResult ParseConstraintLogicalOrExpression(bool IsTrailingRequiresClause)
Parse a constraint-logical-or-expression.
ExprResult ParseConstantExpressionInExprEvalContext(TypoCorrectionTypeBehavior CorrectionBehavior=TypoCorrectionTypeBehavior::AllowNonTypes)
bool ParseUnqualifiedId(CXXScopeSpec &SS, ParsedType ObjectType, bool ObjectHadErrors, bool EnteringContext, bool AllowDestructorName, bool AllowConstructorName, bool AllowDeductionGuide, SourceLocation *TemplateKWLoc, UnqualifiedId &Result)
Parse a C++ unqualified-id (or a C identifier), which describes the name of an entity.
friend class ColonProtectionRAIIObject
DeclGroupPtrTy ParseOpenACCDirectiveDecl(AccessSpecifier &AS, ParsedAttributes &Attrs, DeclSpec::TST TagType, Decl *TagDecl)
Parse OpenACC directive on a declaration.
SourceLocation ConsumeAnyToken(bool ConsumeCodeCompletionTok=false)
ConsumeAnyToken - Dispatch to the right Consume* method based on the current token type.
const Token & GetLookAheadToken(unsigned N)
GetLookAheadToken - This peeks ahead N tokens and returns that token without consuming any tokens.
ExprResult ParseConstantExpression()
ExprResult ParseConditionalExpression()
bool TryConsumeToken(tok::TokenKind Expected)
OpaquePtr< DeclGroupRef > DeclGroupPtrTy
Scope * getCurScope() const
const TargetInfo & getTargetInfo() const
OpaquePtr< TemplateName > TemplateTy
bool SkipUntil(tok::TokenKind T, SkipUntilFlags Flags=static_cast< SkipUntilFlags >(0))
SkipUntil - Read tokens until we get to the specified token, then consume it (unless StopBeforeMatch ...
void SkipMalformedDecl()
SkipMalformedDecl - Read tokens until we get to some likely good stopping point for skipping past a s...
friend class PoisonSEHIdentifiersRAIIObject
const LangOptions & getLangOpts() const
friend class ParenBraceBracketBalancer
ExprResult ParseExpression(TypoCorrectionTypeBehavior CorrectionBehavior=TypoCorrectionTypeBehavior::AllowNonTypes)
Simple precedence-based parser for binary/ternary operators.
@ StopBeforeMatch
Stop skipping at specified token, but don't skip the token itself.
@ StopAtCodeCompletion
Stop at code completion.
@ StopAtSemi
Stop skipping at semicolon.
ExprResult ParseUnevaluatedStringLiteralExpression()
const Token & NextToken()
NextToken - This peeks ahead one token and returns it without consuming it.
friend class BalancedDelimiterTracker
SmallVector< TemplateParameterList *, 4 > TemplateParameterLists
bool TryAnnotateCXXScopeToken(bool EnteringContext=false)
TryAnnotateScopeToken - Like TryAnnotateTypeOrScopeToken but only annotates C++ scope specifiers and ...
RAII object used to inform the actions that we're currently parsing a declaration.
A class for parsing a DeclSpec.
Scope - A scope is a transient data structure that is used while parsing the program.
unsigned getFlags() const
getFlags - Return the flags for this scope.
const Scope * getParent() const
getParent - Return the scope that this is nested in.
@ FunctionPrototypeScope
This is a scope that corresponds to the parameters within a function prototype.
@ TypeAliasScope
This is a scope of type alias declaration.
@ ClassInheritanceScope
We are between inheritance colon and the real class/struct definition scope.
@ ClassScope
The scope of a struct/union/class definition.
@ FunctionDeclarationScope
This is a scope that corresponds to the parameters within a function prototype for a function declara...
@ DeclScope
This is a scope that can contain a declaration.
@ PCC_TopLevelOrExpression
Code completion occurs at top-level in a REPL session.
@ PCC_Namespace
Code completion occurs at top-level or namespace context.
ProcessingContextState ParsingClassState
@ ConstantEvaluated
The current context is "potentially evaluated" in C++11 terms, but the expression is evaluated at com...
@ PotentiallyEvaluated
The current expression is potentially evaluated at run time, which means that code may be generated t...
@ Unevaluated
The current expression and its subexpressions occur within an unevaluated operand (C++11 [expr]p7),...
@ PotentiallyEvaluatedIfUsed
The current expression is potentially evaluated, but any declarations referenced inside that expressi...
Encodes a location in the source.
bool isValid() const
Return true if this is a valid SourceLocation object.
SourceLocation getLocWithOffset(IntTy Offset) const
Return a source location with the specified offset from this SourceLocation.
A trivial tuple used to represent a source range.
void setBegin(SourceLocation b)
SourceLocation getBegin() const
void setEnd(SourceLocation e)
Represents the declaration of a struct/union/class/enum.
Token - This structure provides full information about a lexed token.
IdentifierInfo * getIdentifierInfo() const
void setLiteralData(const char *Ptr)
SourceLocation getLocation() const
Return a source location identifier for the specified offset in the current file.
void setLength(unsigned Len)
void setKind(tok::TokenKind K)
bool is(tok::TokenKind K) const
is/isNot - Predicates to check if this token is a specific kind, as in "if (Tok.is(tok::l_brace)) {....
tok::TokenKind getKind() const
void setLocation(SourceLocation L)
void startToken()
Reset all flags to cleared.
Represents a C++11 virt-specifier-seq.
Specifier getLastSpecifier() const
SourceLocation getFirstLocation() const
SourceLocation getAbstractLoc() const
static const char * getSpecifierName(Specifier VS)
bool SetSpecifier(Specifier VS, SourceLocation Loc, const char *&PrevSpec)
Defines the clang::TargetInfo interface.
@ After
Like System, but searched after the system directories.
IdentifierInfo * ParseHLSLRootSignature(Sema &Actions, llvm::dxbc::RootSignatureVersion Version, StringLiteral *Signature)
std::variant< struct RequiresDecl, struct HeaderDecl, struct UmbrellaDirDecl, struct ModuleDecl, struct ExcludeDecl, struct ExportDecl, struct ExportAsDecl, struct ExternModuleDecl, struct UseDecl, struct LinkDecl, struct ConfigMacrosDecl, struct ConflictDecl > Decl
All declarations that can appear in a module declaration.
TokenKind
Provides a simple uniform namespace for tokens from all C languages.
constexpr bool isRegularKeywordAttribute(TokenKind K)
bool isPragmaAnnotation(TokenKind K)
Return true if this is an annotation token representing a pragma.
The JSON file list parser is used to communicate input to InstallAPI.
bool doesKeywordAttributeTakeArgs(tok::TokenKind Kind)
bool isa(CodeGen::Address addr)
@ NotAttributeSpecifier
This is not an attribute specifier.
MutableArrayRef< TemplateParameterList * > MultiTemplateParamsArg
if(T->getSizeExpr()) TRY_TO(TraverseStmt(const_cast< Expr * >(T -> getSizeExpr())))
FunctionDefinitionKind
Described the kind of function definition (if any) provided for a function.
int hasAttribute(AttributeCommonInfo::Syntax Syntax, llvm::StringRef ScopeName, llvm::StringRef AttrName, const TargetInfo &Target, const LangOptions &LangOpts, bool CheckPlugins)
Return the version number associated with the attribute if we recognize and implement the attribute s...
InClassInitStyle
In-class initialization styles for non-static data members.
@ ICIS_CopyInit
Copy initialization.
@ ICIS_ListInit
Direct list-initialization.
@ ICIS_NoInit
No in-class initializer.
llvm::PointerUnion< Expr *, IdentifierLoc * > ArgsUnion
A union of the various pointer types that can be passed to an ParsedAttr as an argument.
@ TemplateName
The identifier is a template name. FIXME: Add an annotation for that.
bool tokenIsLikeStringLiteral(const Token &Tok, const LangOptions &LO)
Return true if the token is a string literal, or a function local predefined macro,...
@ IK_TemplateId
A template-id, e.g., f<int>.
@ IK_Identifier
An identifier.
AccessSpecifier
A C++ access specifier (public, private, protected), plus the special value "none" which means differ...
ActionResult< Decl * > DeclResult
nullptr
This class represents a compute construct, representing a 'Kind' of ‘parallel’, 'serial',...
llvm::SmallVector< ArgsUnion, 12U > ArgsVector
@ Dependent
Parse the block as a dependent block, which may be used in some template instantiations but not other...
@ Skip
Skip the block entirely; this code is never used.
@ Parse
Parse the block; this code is always used.
LLVM_READONLY bool isLetter(unsigned char c)
Return true if this character is an ASCII letter: [a-zA-Z].
@ Result
The result type of a method or function.
ActionResult< ParsedType > TypeResult
ActionResult< CXXCtorInitializer * > MemInitResult
const FunctionProtoType * T
@ Template
We are parsing a template declaration.
@ ExplicitSpecialization
We are parsing an explicit specialization.
@ ExplicitInstantiation
We are parsing an explicit instantiation.
@ NonTemplate
We are not parsing a template at all.
ActionResult< CXXBaseSpecifier * > BaseResult
@ Keyword
The name has been typo-corrected to a keyword.
@ Type
The name was classified as a type.
MutableArrayRef< ParsedTemplateArgument > ASTTemplateArgsPtr
@ AfterMemberFunctionDefinition
TemplateNameKind
Specifies the kind of template name that an identifier refers to.
@ TNK_Non_template
The name does not refer to a template.
@ TNK_Undeclared_template
Lookup for the name failed, but we're assuming it was a template name anyway.
U cast(CodeGen::Address addr)
SmallVector< Token, 4 > CachedTokens
A set of tokens that has been cached for later parsing.
OpaquePtr< QualType > ParsedType
An opaque type for threading parsed type information through the parser.
@ Class
The "class" keyword introduces the elaborated-type-specifier.
ActionResult< Expr * > ExprResult
@ Braces
New-expression has a C++11 list-initializer.
ExceptionSpecificationType
The various types of exception specifications that exist in C++11.
@ EST_Unparsed
not parsed yet
@ EST_None
no exception specification
@ EST_MSAny
Microsoft throw(...) extension.
@ EST_BasicNoexcept
noexcept
@ EST_Dynamic
throw(T1, T2)
CachedTokens * ExceptionSpecTokens
Pointer to the cached tokens for an exception-specification that has not yet been parsed.
ParamInfo * Params
Params - This is a pointer to a new[]'d array of ParamInfo objects that describe the parameters speci...
unsigned NumParams
NumParams - This is the number of formal parameters specified by the declarator.
unsigned HasTrailingReturnType
HasTrailingReturnType - If this is true, a trailing return type was specified.
ExceptionSpecificationType getExceptionSpecType() const
Get the type of exception specification this function has.
std::unique_ptr< CachedTokens > DefaultArgTokens
DefaultArgTokens - When the parameter's default argument cannot be parsed immediately (because it occ...
const IdentifierInfo * Name
FIXME: Temporarily stores the name of a specialization.
TemplateNameKind Kind
The kind of template that Template refers to.
unsigned NumArgs
NumArgs - The number of template arguments.
SourceLocation TemplateNameLoc
TemplateNameLoc - The location of the template name within the source.
ParsedTemplateArgument * getTemplateArgs()
Retrieves a pointer to the template arguments.
SourceLocation RAngleLoc
The location of the '>' after the template argument list.
SourceLocation LAngleLoc
The location of the '<' before the template argument list.
SourceLocation TemplateKWLoc
TemplateKWLoc - The location of the template keyword.
bool mightBeType() const
Determine whether this might be a type template.
ParsedTemplateTy Template
The declaration of the template corresponding to the template-name.