47 #include "llvm/ADT/SmallString.h"
48 #include "llvm/ADT/Triple.h"
52 #include <unordered_map>
54 using namespace clang;
70 TypeNameValidatorCCC(
bool AllowInvalid,
bool WantClass =
false,
71 bool AllowTemplates =
false,
72 bool AllowNonTemplates =
true)
73 : AllowInvalidDecl(AllowInvalid), WantClassName(WantClass),
74 AllowTemplates(AllowTemplates), AllowNonTemplates(AllowNonTemplates) {
75 WantExpressionKeywords =
false;
76 WantCXXNamedCasts =
false;
77 WantRemainingKeywords =
false;
82 if (!AllowInvalidDecl && ND->isInvalidDecl())
86 return AllowTemplates;
88 bool IsType = isa<TypeDecl>(ND) || isa<ObjCInterfaceDecl>(ND);
92 if (AllowNonTemplates)
98 auto *RD = dyn_cast<CXXRecordDecl>(ND);
99 if (!RD || !RD->isInjectedClassName())
101 RD = cast<CXXRecordDecl>(RD->getDeclContext());
102 return RD->getDescribedClassTemplate() ||
103 isa<ClassTemplateSpecializationDecl>(RD);
109 return !WantClassName && candidate.
isKeyword();
112 std::unique_ptr<CorrectionCandidateCallback> clone()
override {
113 return std::make_unique<TypeNameValidatorCCC>(*
this);
117 bool AllowInvalidDecl;
120 bool AllowNonTemplates;
132 case tok::kw___int64:
133 case tok::kw___int128:
135 case tok::kw_unsigned:
143 case tok::kw__Float16:
144 case tok::kw___float128:
145 case tok::kw___ibm128:
146 case tok::kw_wchar_t:
148 case tok::kw___underlying_type:
149 case tok::kw___auto_type:
152 case tok::annot_typename:
153 case tok::kw_char16_t:
154 case tok::kw_char32_t:
156 case tok::annot_decltype:
157 case tok::kw_decltype:
158 return getLangOpts().CPlusPlus;
160 case tok::kw_char8_t:
161 return getLangOpts().Char8;
171 enum class UnqualifiedTypeNameLookupResult {
182 static UnqualifiedTypeNameLookupResult
187 return UnqualifiedTypeNameLookupResult::NotFound;
189 UnqualifiedTypeNameLookupResult FoundTypeDecl =
190 UnqualifiedTypeNameLookupResult::NotFound;
193 if (
auto *BaseTT =
Base.getType()->getAs<
TagType>())
194 BaseRD = BaseTT->getAsCXXRecordDecl();
198 if (!TST || !TST->isDependentType())
200 auto *TD = TST->getTemplateName().getAsTemplateDecl();
203 if (
auto *BasePrimaryTemplate =
204 dyn_cast_or_null<CXXRecordDecl>(TD->getTemplatedDecl())) {
206 BaseRD = BasePrimaryTemplate;
207 else if (
auto *CTD = dyn_cast<ClassTemplateDecl>(TD)) {
209 CTD->findPartialSpecialization(
Base.getType()))
217 if (!isa<TypeDecl>(ND))
218 return UnqualifiedTypeNameLookupResult::FoundNonType;
219 FoundTypeDecl = UnqualifiedTypeNameLookupResult::FoundType;
221 if (FoundTypeDecl == UnqualifiedTypeNameLookupResult::NotFound) {
223 case UnqualifiedTypeNameLookupResult::FoundNonType:
224 return UnqualifiedTypeNameLookupResult::FoundNonType;
225 case UnqualifiedTypeNameLookupResult::FoundType:
226 FoundTypeDecl = UnqualifiedTypeNameLookupResult::FoundType;
228 case UnqualifiedTypeNameLookupResult::NotFound:
235 return FoundTypeDecl;
243 UnqualifiedTypeNameLookupResult FoundTypeDecl =
244 UnqualifiedTypeNameLookupResult::NotFound;
246 DC && FoundTypeDecl == UnqualifiedTypeNameLookupResult::NotFound;
247 DC = DC->getParent()) {
250 RD = dyn_cast<CXXRecordDecl>(DC);
254 if (FoundTypeDecl != UnqualifiedTypeNameLookupResult::FoundType)
260 S.
Diag(NameLoc, diag::ext_found_in_dependent_base) << &II;
288 bool isClassName,
bool HasTrailingDot,
290 bool IsCtorOrDtorName,
291 bool WantNontrivialTypeSourceInfo,
292 bool IsClassTemplateDeductionContext,
295 bool AllowDeducedTemplate = IsClassTemplateDeductionContext &&
296 getLangOpts().CPlusPlus17 && !IsCtorOrDtorName &&
297 !isClassName && !HasTrailingDot;
304 LookupCtx = computeDeclContext(ObjectType);
306 LookupCtx = computeDeclContext(*SS,
false);
309 if (isDependentScopeSpecifier(*SS)) {
319 if (!isClassName && !IsCtorOrDtorName)
324 if (WantNontrivialTypeSourceInfo)
325 return ActOnTypenameType(S,
SourceLocation(), *SS, II, NameLoc).get();
337 RequireCompleteDeclContext(*SS, LookupCtx))
351 LookupQualifiedName(Result, LookupCtx);
353 if (ObjectTypePtr && Result.empty()) {
360 LookupName(Result, S);
364 LookupName(Result, S);
368 if (Result.empty() && getLangOpts().MSVCCompat && (!SS || SS->
isEmpty())) {
377 switch (Result.getResultKind()) {
381 TypeNameValidatorCCC CCC(
true, isClassName,
382 AllowDeducedTemplate);
384 S, SS, CCC, CTK_ErrorRecovery);
387 bool MemberOfUnknownSpecialization;
396 if (Correction && (NNS || NewII != &II) &&
401 isTemplateName(S, *NewSSPtr,
false,
TemplateName,
nullptr,
false,
402 Template, MemberOfUnknownSpecialization))) {
404 isClassName, HasTrailingDot, ObjectTypePtr,
406 WantNontrivialTypeSourceInfo,
407 IsClassTemplateDeductionContext);
409 diagnoseTypo(Correction,
410 PDiag(diag::err_unknown_type_or_class_name_suggest)
411 << Result.getLookupName() << isClassName);
414 *CorrectedII = NewII;
423 Result.suppressDiagnostics();
433 Result.suppressDiagnostics();
439 Res != ResEnd; ++Res) {
441 if (isa<TypeDecl, ObjCInterfaceDecl, UnresolvedUsingIfExistsDecl>(
448 FoundUsingShadow = dyn_cast<UsingShadowDecl>(*Res);
460 Result.suppressDiagnostics();
471 IIDecl = Result.getFoundDecl();
472 FoundUsingShadow = dyn_cast<UsingShadowDecl>(*Result.begin());
476 assert(IIDecl &&
"Didn't find decl");
479 if (
TypeDecl *TD = dyn_cast<TypeDecl>(IIDecl)) {
483 auto *LookupRD = dyn_cast_or_null<CXXRecordDecl>(LookupCtx);
484 auto *FoundRD = dyn_cast<CXXRecordDecl>(TD);
485 if (!isClassName && !IsCtorOrDtorName && LookupRD && FoundRD &&
486 FoundRD->isInjectedClassName() &&
488 Diag(NameLoc, diag::err_out_of_line_qualified_id_type_names_constructor)
491 DiagnoseUseOfDecl(IIDecl, NameLoc);
494 MarkAnyDeclReferenced(TD->getLocation(), TD,
false);
496 (void)DiagnoseUseOfDecl(IDecl, NameLoc);
499 FoundUsingShadow =
nullptr;
500 }
else if (
auto *UD = dyn_cast<UnresolvedUsingIfExistsDecl>(IIDecl)) {
501 (void)DiagnoseUseOfDecl(UD, NameLoc);
504 FoundUsingShadow =
nullptr;
505 }
else if (AllowDeducedTemplate) {
507 assert(!FoundUsingShadow || FoundUsingShadow->
getTargetDecl() == TD);
513 FoundUsingShadow =
nullptr;
519 Result.suppressDiagnostics();
523 if (FoundUsingShadow)
529 if (SS && SS->
isNotEmpty() && !IsCtorOrDtorName &&
530 !isa<ObjCInterfaceDecl, UnresolvedUsingIfExistsDecl>(IIDecl)) {
531 if (WantNontrivialTypeSourceInfo) {
534 Builder.pushTypeSpec(T).setNameLoc(NameLoc);
536 T = getElaboratedType(
ETK_None, *SS, T);
540 return CreateParsedType(T, Builder.getTypeSourceInfo(Context, T));
542 T = getElaboratedType(
ETK_None, *SS, T);
554 auto *ND = dyn_cast<NamespaceDecl>(DC);
555 if (ND && !ND->isInline() && !ND->isAnonymousNamespace())
557 else if (
auto *RD = dyn_cast<CXXRecordDecl>(DC))
559 RD->getTypeForDecl());
560 else if (isa<TranslationUnitDecl>(DC))
563 llvm_unreachable(
"something isn't in TU scope?");
574 if (
const auto *MD = dyn_cast<CXXMethodDecl>(DC))
575 if (MD->getParent()->hasAnyDependentBases())
583 bool IsTemplateTypeArg) {
584 assert(getLangOpts().MSVCCompat &&
"shouldn't be called in non-MSVC mode");
587 if (IsTemplateTypeArg && getCurScope()->isTemplateParamScope()) {
596 Diag(NameLoc, diag::ext_ms_delayed_template_argument) << &II;
602 RD->getTypeForDecl());
606 Diag(NameLoc, diag::ext_undeclared_unqual_id_with_dependent_base) << &II
626 return CreateParsedType(T, Builder.getTypeSourceInfo(Context, T));
637 LookupName(R, S,
false);
641 switch (TD->getTagKind()) {
668 if (CurContext->isRecord()) {
678 return S->isFunctionPrototypeScope();
680 return CurContext->isFunctionOrMethod() || S->isFunctionPrototypeScope();
688 bool IsTemplateName) {
693 SuggestedType =
nullptr;
697 TypeNameValidatorCCC CCC(
false,
false,
702 CCC, CTK_ErrorRecovery)) {
704 bool CanRecover = !IsTemplateName;
705 if (Corrected.isKeyword()) {
707 diagnoseTypo(Corrected,
708 PDiag(IsTemplateName ? diag::err_no_template_suggest
709 : diag::err_unknown_typename_suggest)
711 II = Corrected.getCorrectionAsIdentifierInfo();
714 if (!SS || !SS->
isSet()) {
715 diagnoseTypo(Corrected,
716 PDiag(IsTemplateName ? diag::err_no_template_suggest
717 : diag::err_unknown_typename_suggest)
719 }
else if (
DeclContext *DC = computeDeclContext(*SS,
false)) {
720 std::string CorrectedStr(Corrected.getAsString(getLangOpts()));
721 bool DroppedSpecifier = Corrected.WillReplaceSpecifier() &&
722 II->
getName().equals(CorrectedStr);
723 diagnoseTypo(Corrected,
725 ? diag::err_no_member_template_suggest
726 : diag::err_unknown_nested_typename_suggest)
727 << II << DC << DroppedSpecifier << SS->
getRange(),
730 llvm_unreachable(
"could not have corrected a typo here");
737 if (Corrected.getCorrectionSpecifier())
738 tmpSS.
MakeTrivial(Context, Corrected.getCorrectionSpecifier(),
742 getTypeName(*Corrected.getCorrectionAsIdentifierInfo(), IILoc, S,
743 tmpSS.
isSet() ? &tmpSS : SS,
false,
false,
nullptr,
750 if (getLangOpts().
CPlusPlus && !IsTemplateName) {
753 Name.setIdentifier(II, IILoc);
756 bool MemberOfUnknownSpecialization;
757 if (isTemplateName(S, SS ? *SS : EmptySS,
false,
758 Name,
nullptr,
true, TemplateResult,
760 diagnoseMissingTemplateArguments(TemplateResult.
get(), IILoc);
769 Diag(IILoc, IsTemplateName ? diag::err_no_template
770 : diag::err_unknown_typename)
772 else if (
DeclContext *DC = computeDeclContext(*SS,
false))
773 Diag(IILoc, IsTemplateName ? diag::err_no_member_template
774 : diag::err_typename_nested_not_found)
779 }
else if (isDependentScopeSpecifier(*SS)) {
780 unsigned DiagID = diag::err_typename_missing;
781 if (getLangOpts().MSVCCompat && isMicrosoftMissingTypename(SS, S))
782 DiagID = diag::ext_typename_missing;
789 *SS, *II, IILoc).
get();
792 "Invalid scope specifier has already been diagnosed");
800 NextToken.
is(tok::less);
803 if (isa<TypeDecl>(*I) || isa<ObjCInterfaceDecl>(*I))
806 if (CheckTemplate && isa<TemplateDecl>(*I))
820 StringRef FixItTagName;
821 switch (Tag->getTagKind()) {
823 FixItTagName =
"class ";
827 FixItTagName =
"enum ";
831 FixItTagName =
"struct ";
835 FixItTagName =
"__interface ";
839 FixItTagName =
"union ";
843 StringRef TagName = FixItTagName.drop_back();
844 SemaRef.
Diag(NameLoc, diag::err_use_of_tag_name_without_tag)
845 << Name << TagName << SemaRef.
getLangOpts().CPlusPlus
850 SemaRef.
Diag((*I)->getLocation(), diag::note_decl_hiding_tag_type)
865 const Token &NextToken,
870 assert(NextToken.
isNot(tok::coloncolon) &&
871 "parse nested name specifiers before calling ClassifyName");
873 isCurrentClassName(*Name, S, &SS)) {
881 LookupResult Result(*
this, Name, NameLoc, LookupOrdinaryName);
882 LookupParsedName(Result, S, &SS, !CurMethod);
889 if (Result.empty() && SS.
isEmpty() && getLangOpts().MSVCCompat) {
900 DeclResult Ivar = LookupIvarInObjCMethod(Result, S, Name);
904 return NameClassification::NonType(cast<NamedDecl>(Ivar.
get()));
908 LookupBuiltin(Result);
911 bool SecondTry =
false;
912 bool IsFilteredTemplateName =
false;
915 switch (Result.getResultKind()) {
919 if (SS.
isEmpty() && NextToken.
is(tok::l_paren)) {
923 return NameClassification::UndeclaredNonType();
939 if (getLangOpts().implicitFunctionsAllowed()) {
940 if (
NamedDecl *D = ImplicitlyDefineFunction(NameLoc, *Name, S))
941 return NameClassification::NonType(D);
952 return NameClassification::UndeclaredTemplate(Template);
958 if (!getLangOpts().
CPlusPlus && !SecondTry &&
965 if (!SecondTry && CCC) {
968 CorrectTypo(Result.getLookupNameInfo(), Result.getLookupKind(), S,
969 &SS, *CCC, CTK_ErrorRecovery)) {
970 unsigned UnqualifiedDiag = diag::err_undeclared_var_use_suggest;
971 unsigned QualifiedDiag = diag::err_no_member_suggest;
973 NamedDecl *FirstDecl = Corrected.getFoundDecl();
974 NamedDecl *UnderlyingFirstDecl = Corrected.getCorrectionDecl();
975 if (getLangOpts().
CPlusPlus && NextToken.
is(tok::less) &&
976 UnderlyingFirstDecl && isa<TemplateDecl>(UnderlyingFirstDecl)) {
977 UnqualifiedDiag = diag::err_no_template_suggest;
978 QualifiedDiag = diag::err_no_member_template_suggest;
979 }
else if (UnderlyingFirstDecl &&
980 (isa<TypeDecl>(UnderlyingFirstDecl) ||
981 isa<ObjCInterfaceDecl>(UnderlyingFirstDecl) ||
982 isa<ObjCCompatibleAliasDecl>(UnderlyingFirstDecl))) {
983 UnqualifiedDiag = diag::err_unknown_typename_suggest;
984 QualifiedDiag = diag::err_unknown_nested_typename_suggest;
988 diagnoseTypo(Corrected, PDiag(UnqualifiedDiag) << Name);
990 std::string CorrectedStr(Corrected.getAsString(getLangOpts()));
991 bool DroppedSpecifier = Corrected.WillReplaceSpecifier() &&
992 Name->getName().equals(CorrectedStr);
993 diagnoseTypo(Corrected, PDiag(QualifiedDiag)
994 << Name << computeDeclContext(SS,
false)
995 << DroppedSpecifier << SS.
getRange());
999 Name = Corrected.getCorrectionAsIdentifierInfo();
1002 if (Corrected.isKeyword())
1008 Result.setLookupName(Corrected.getCorrection());
1010 Result.addDecl(FirstDecl);
1018 LookupIvarInObjCMethod(Result, S, Ivar->getIdentifier());
1022 return NameClassification::NonType(Ivar);
1030 Result.suppressDiagnostics();
1048 return NameClassification::DependentNonType();
1057 if (getLangOpts().
CPlusPlus && NextToken.
is(tok::less) &&
1058 hasAnyAcceptableTemplateNames(Result,
true,
1071 FilterAcceptableTemplateNames(Result);
1072 if (!Result.isAmbiguous()) {
1073 IsFilteredTemplateName =
true;
1082 if (getLangOpts().
CPlusPlus && NextToken.
is(tok::less) &&
1083 (IsFilteredTemplateName ||
1084 hasAnyAcceptableTemplateNames(
1099 if (!IsFilteredTemplateName)
1100 FilterAcceptableTemplateNames(Result);
1102 bool IsFunctionTemplate;
1105 if (Result.end() - Result.begin() > 1) {
1106 IsFunctionTemplate =
true;
1109 }
else if (!Result.empty()) {
1110 auto *TD = cast<TemplateDecl>(getAsTemplateNameDecl(
1111 *Result.begin(),
true,
1113 IsFunctionTemplate = isa<FunctionTemplateDecl>(TD);
1114 IsVarTemplate = isa<VarTemplateDecl>(TD);
1117 dyn_cast<UsingShadowDecl>(*Result.begin());
1118 assert(!FoundUsingShadow ||
1119 TD == cast<TemplateDecl>(FoundUsingShadow->
getTargetDecl()));
1129 IsFunctionTemplate =
true;
1133 if (IsFunctionTemplate) {
1137 Result.suppressDiagnostics();
1139 return NameClassification::FunctionTemplate(Template);
1142 return IsVarTemplate ? NameClassification::VarTemplate(Template)
1143 : NameClassification::TypeTemplate(Template);
1148 if (
const auto *USD = dyn_cast<UsingShadowDecl>(Found))
1155 Builder.pushTypeSpec(T).setNameLoc(NameLoc);
1156 T = getElaboratedType(
ETK_None, SS, T);
1160 return CreateParsedType(T, Builder.getTypeSourceInfo(Context, T));
1163 NamedDecl *FirstDecl = (*Result.begin())->getUnderlyingDecl();
1165 DiagnoseUseOfDecl(
Type, NameLoc);
1166 MarkAnyDeclReferenced(
Type->getLocation(),
Type,
false);
1167 return BuildTypeFor(
Type, *Result.begin());
1174 dyn_cast<ObjCCompatibleAliasDecl>(FirstDecl))
1175 Class = Alias->getClassInterface();
1179 DiagnoseUseOfDecl(Class, NameLoc);
1181 if (NextToken.
is(tok::period)) {
1184 Result.suppressDiagnostics();
1192 if (isa<ConceptDecl>(FirstDecl))
1193 return NameClassification::Concept(
1196 if (
auto *EmptyD = dyn_cast<UnresolvedUsingIfExistsDecl>(FirstDecl)) {
1197 (void)DiagnoseUseOfDecl(EmptyD, NameLoc);
1202 if (isa<TemplateDecl>(FirstDecl) && !isa<FunctionTemplateDecl>(FirstDecl) &&
1203 !isa<VarTemplateDecl>(FirstDecl))
1204 return NameClassification::TypeTemplate(
1209 bool NextIsOp = NextToken.
isOneOf(tok::amp, tok::star);
1210 if ((NextToken.
is(tok::identifier) ||
1215 DiagnoseUseOfDecl(
Type, NameLoc);
1216 return BuildTypeFor(
Type, *Result.begin());
1223 bool ADL = UseArgumentDependentLookup(SS, Result, NextToken.
is(tok::l_paren));
1225 return NameClassification::NonType(Result.getRepresentativeDecl());
1228 Result.suppressDiagnostics();
1231 Result.getLookupNameInfo(), ADL, Result.isOverloadedResult(),
1232 Result.begin(), Result.end()));
1238 assert(getLangOpts().
CPlusPlus &&
"ADL-only call in C?");
1240 LookupResult Result(*
this, Name, NameLoc, LookupOrdinaryName);
1241 return BuildDeclarationNameExpr(SS, Result,
true);
1248 bool IsAddressOfOperand) {
1251 NameInfo, IsAddressOfOperand,
1258 const Token &NextToken) {
1259 if (getCurMethodDecl() && SS.
isEmpty())
1261 return BuildIvarRefExpr(S, NameLoc, Ivar);
1265 Result.addDecl(Found);
1266 Result.resolveKind();
1268 bool ADL = UseArgumentDependentLookup(SS, Result, NextToken.
is(tok::l_paren));
1269 return BuildDeclarationNameExpr(SS, Result, ADL);
1275 auto *ULE = cast<UnresolvedLookupExpr>(E);
1276 if ((*ULE->decls_begin())->isCXXClassMember()) {
1278 SS.
Adopt(ULE->getQualifierLoc());
1281 LookupResult Result(*
this, ULE->getName(), ULE->getNameLoc(),
1282 LookupOrdinaryName);
1283 Result.setNamingClass(ULE->getNamingClass());
1284 for (
auto I = ULE->decls_begin(), E = ULE->decls_end(); I != E; ++I)
1285 Result.addDecl(*I, I.getAccess());
1286 Result.resolveKind();
1287 return BuildPossibleImplicitMemberExpr(SS,
SourceLocation(), Result,
1298 auto *TD = Name.getAsTemplateDecl();
1300 return TemplateNameKindForDiagnostics::DependentTemplate;
1301 if (isa<ClassTemplateDecl>(TD))
1302 return TemplateNameKindForDiagnostics::ClassTemplate;
1303 if (isa<FunctionTemplateDecl>(TD))
1304 return TemplateNameKindForDiagnostics::FunctionTemplate;
1305 if (isa<VarTemplateDecl>(TD))
1306 return TemplateNameKindForDiagnostics::VarTemplate;
1307 if (isa<TypeAliasTemplateDecl>(TD))
1308 return TemplateNameKindForDiagnostics::AliasTemplate;
1309 if (isa<TemplateTemplateParmDecl>(TD))
1310 return TemplateNameKindForDiagnostics::TemplateTemplateParam;
1311 if (isa<ConceptDecl>(TD))
1312 return TemplateNameKindForDiagnostics::Concept;
1313 return TemplateNameKindForDiagnostics::DependentTemplate;
1318 "The next DeclContext should be lexically contained in the current one.");
1324 assert(CurContext &&
"DeclContext imbalance!");
1326 CurContext = CurContext->getLexicalParent();
1327 assert(CurContext &&
"Popped translation unit!");
1336 CurContext = cast<TagDecl>(D)->getDefinition();
1337 assert(CurContext &&
"skipping definition of undefined tag");
1340 S->setEntity(CurContext->getLookupParent());
1345 CurContext =
static_cast<decltype(CurContext)
>(Context);
1368 assert(!S->getEntity() &&
"scope already has entity");
1371 Scope *Ancestor = S->getParent();
1373 assert(Ancestor->
getEntity() == CurContext &&
"ancestor context mismatch");
1379 if (S->getParent()->isTemplateParamScope()) {
1382 EnterTemplatedContext(S->getParent(), DC);
1387 assert(S->getEntity() == CurContext &&
"Context imbalance!");
1391 Scope *Ancestor = S->getParent();
1400 assert(S->isTemplateParamScope() &&
1401 "expected to be initializing a template parameter scope");
1424 unsigned ScopeDepth = getTemplateDepth(S);
1425 for (; S && S->isTemplateParamScope(); S = S->getParent(), --ScopeDepth) {
1429 cast<Decl>(DC)->getDescribedTemplateParams()) {
1430 unsigned DCDepth = TPL->getDepth() + 1;
1431 if (DCDepth > ScopeDepth)
1433 if (ScopeDepth == DCDepth)
1438 S->setLookupEntity(SearchDCAfterScope);
1452 "The next DeclContext should be lexically contained in the current one.");
1454 S->setEntity(CurContext);
1456 for (
unsigned P = 0, NumParams = FD->
getNumParams();
P < NumParams; ++
P) {
1461 IdResolver.AddDecl(Param);
1469 assert(CurContext &&
"DeclContext imbalance!");
1470 CurContext = CurContext->getLexicalParent();
1471 assert(CurContext &&
"Popped translation unit!");
1500 return ND->
hasAttr<OverloadableAttr>();
1503 return Previous.getFoundDecl()->hasAttr<OverloadableAttr>();
1513 while (S->getEntity() && S->getEntity()->isTransparentContext())
1520 CurContext->addDecl(D);
1528 if (isa<FunctionDecl>(D) &&
1529 cast<FunctionDecl>(D)->isFunctionTemplateSpecialization())
1534 IEnd = IdResolver.end();
1535 for (; I != IEnd; ++I) {
1538 IdResolver.RemoveDecl(*I);
1547 if (isa<LabelDecl>(D) && !cast<LabelDecl>(D)->isGnuLocal()) {
1551 for (I = IdResolver.begin(D->
getDeclName()); I != IEnd; ++I) {
1553 if (IDC == CurContext) {
1554 if (!S->isDeclScope(*I))
1556 }
else if (IDC->
Encloses(CurContext))
1560 IdResolver.InsertDeclAfter(I, D);
1562 IdResolver.AddDecl(D);
1564 warnOnReservedIdentifier(D);
1568 bool AllowInlineNamespace) {
1569 return IdResolver.isDeclInScope(D, Ctx, S, AllowInlineNamespace);
1576 if (ScopeDC->getPrimaryContext() == TargetDC)
1578 }
while ((S = S->getParent()));
1590 bool ConsiderLinkage,
1591 bool AllowInlineNamespace) {
1596 if (isDeclInScope(D, Ctx, S, AllowInlineNamespace))
1621 makeMergedDefinitionVisible(New);
1646 if (NewIsModuleInterface || OldIsModuleInterface) {
1652 << NewIsModuleInterface
1654 << OldIsModuleInterface
1685 if (!IsNewExported && !IsOldExported)
1691 assert(IsNewExported);
1699 Diag(New->
getLocation(), diag::err_redeclaration_non_exported) << New << S;
1707 if (CheckRedeclarationModuleOwnership(New, Old))
1710 if (CheckRedeclarationExported(New, Old))
1717 return isa<UsingShadowDecl>(D) ||
1718 isa<UnresolvedUsingTypenameDecl>(D) ||
1719 isa<UnresolvedUsingValueDecl>(D);
1746 return CD->isCopyConstructor();
1762 bool Sema::mightHaveNonExternalLinkage(
const DeclaratorDecl *D) {
1765 if (
const RecordDecl *RD = dyn_cast<RecordDecl>(DC)){
1766 if (!RD->hasNameForLinkage())
1795 if (
const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
1801 FD->getMemberSpecializationInfo() && !FD->isOutOfLine())
1804 if (
const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(FD)) {
1809 if (FD->isInlined() && !
isMainFileLoc(*
this, FD->getLocation()))
1813 if (FD->doesThisDeclarationHaveABody() &&
1816 }
else if (
const VarDecl *VD = dyn_cast<VarDecl>(D)) {
1826 if (VD->isStaticDataMember() &&
1829 if (VD->isStaticDataMember() &&
1831 VD->getMemberSpecializationInfo() && !VD->isOutOfLine())
1834 if (VD->isInline() && !
isMainFileLoc(*
this, VD->getLocation()))
1843 return mightHaveNonExternalLinkage(D);
1850 if (
const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
1852 if (FD !=
First && ShouldWarnIfUnusedFileScopedDecl(
First))
1856 if (
const VarDecl *VD = dyn_cast<VarDecl>(D)) {
1858 if (VD !=
First && ShouldWarnIfUnusedFileScopedDecl(
First))
1862 if (ShouldWarnIfUnusedFileScopedDecl(D))
1863 UnusedFileScopedDecls.push_back(D);
1870 if (
auto *DD = dyn_cast<DecompositionDecl>(D)) {
1874 for (
auto *BD : DD->bindings())
1875 if (BD->isReferenced())
1883 if (D->
hasAttr<UnusedAttr>() || D->
hasAttr<ObjCPreciseLifetimeAttr>())
1886 if (isa<LabelDecl>(D))
1892 if (
const auto *R = dyn_cast<CXXRecordDecl>(D->
getDeclContext()))
1895 WithinFunction || (R->isLocalClass() && !R->isDependentType());
1896 if (!WithinFunction)
1899 if (isa<TypedefNameDecl>(D))
1903 if (!isa<VarDecl>(D) || isa<ParmVarDecl>(D) || isa<ImplicitParamDecl>(D))
1907 if (
const VarDecl *VD = dyn_cast<VarDecl>(D)) {
1909 const Expr *Init = VD->getInit();
1910 if (
const auto *Cleanups = dyn_cast_or_null<ExprWithCleanups>(Init))
1911 Init = Cleanups->getSubExpr();
1913 const auto *Ty = VD->getType().getTypePtr();
1918 if (TT->getDecl()->hasAttr<UnusedAttr>())
1924 if (
const auto *MTE = dyn_cast_or_null<MaterializeTemporaryExpr>(Init)) {
1925 if (MTE->getExtendingDecl()) {
1926 Ty = VD->getType().getNonReferenceType().getTypePtr();
1927 Init = MTE->getSubExpr()->IgnoreImplicitAsWritten();
1933 if (Ty->isIncompleteType() || Ty->isDependentType())
1938 Ty = Ty->getBaseElementTypeUnsafe();
1941 const TagDecl *Tag = TT->getDecl();
1942 if (Tag->
hasAttr<UnusedAttr>())
1945 if (
const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(Tag)) {
1946 if (!RD->hasTrivialDestructor() && !RD->hasAttr<WarnUnusedAttr>())
1951 dyn_cast<CXXConstructExpr>(Init);
1954 if (!CD->
isTrivial() && !RD->hasAttr<WarnUnusedAttr>() &&
1955 (VD->getInit()->isValueDependent() || !VD->evaluateValue()))
1961 if (Init->isTypeDependent()) {
1963 if (!Ctor->isTrivial())
1969 if (isa<CXXUnresolvedConstructExpr>(Init))
1983 if (isa<LabelDecl>(D)) {
1998 for (
auto *TmpD : D->
decls()) {
1999 if (
const auto *T = dyn_cast<TypedefNameDecl>(TmpD))
2000 DiagnoseUnusedDecl(T);
2001 else if(
const auto *R = dyn_cast<RecordDecl>(TmpD))
2002 DiagnoseUnusedNestedTypedefs(R);
2012 if (
auto *TD = dyn_cast<TypedefNameDecl>(D)) {
2015 UnusedLocalTypedefNameCandidates.insert(TD);
2023 if (isa<VarDecl>(D) && cast<VarDecl>(D)->isExceptionVariable())
2024 DiagID = diag::warn_unused_exception_param;
2025 else if (isa<LabelDecl>(D))
2026 DiagID = diag::warn_unused_label;
2028 DiagID = diag::warn_unused_variable;
2042 if (Ty->isReferenceType() || Ty->isDependentType())
2046 const TagDecl *Tag = TT->getDecl();
2047 if (Tag->
hasAttr<UnusedAttr>())
2051 if (
const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(Tag)) {
2052 if (!RD->hasAttr<WarnUnusedAttr>())
2060 if (VD->
hasAttr<BlocksAttr>() && Ty->isObjCObjectPointerType())
2066 if (VD->
hasAttr<ObjCPreciseLifetimeAttr>() && Ty->isObjCObjectPointerType())
2069 auto iter = RefsMinusAssignments.find(VD);
2070 if (iter == RefsMinusAssignments.end())
2073 assert(iter->getSecond() >= 0 &&
2074 "Found a negative number of references to a VarDecl");
2075 if (iter->getSecond() != 0)
2077 unsigned DiagID = isa<ParmVarDecl>(VD) ? diag::warn_unused_but_set_parameter
2078 : diag::warn_unused_but_set_variable;
2087 bool Diagnose =
false;
2091 Diagnose = L->
getStmt() ==
nullptr;
2097 S->mergeNRVOIntoParent();
2099 if (S->decl_empty())
return;
2101 "Scope shouldn't contain decls!");
2103 for (
auto *TmpD : S->decls()) {
2104 assert(TmpD &&
"This decl didn't get pushed??");
2106 assert(isa<NamedDecl>(TmpD) &&
"Decl isn't NamedDecl?");
2110 if (!S->hasUnrecoverableErrorOccurred()) {
2111 DiagnoseUnusedDecl(D);
2112 if (
const auto *RD = dyn_cast<RecordDecl>(D))
2113 DiagnoseUnusedNestedTypedefs(RD);
2114 if (
VarDecl *VD = dyn_cast<VarDecl>(D)) {
2115 DiagnoseUnusedButSetDecl(VD);
2116 RefsMinusAssignments.erase(VD);
2123 if (
LabelDecl *LD = dyn_cast<LabelDecl>(D))
2128 IdResolver.RemoveDecl(D);
2129 auto ShadowI = ShadowingDecls.find(D);
2130 if (ShadowI != ShadowingDecls.end()) {
2131 if (
const auto *FD = dyn_cast<FieldDecl>(ShadowI->second)) {
2133 << D << FD << FD->getParent();
2134 Diag(FD->getLocation(), diag::note_previous_declaration);
2136 ShadowingDecls.erase(ShadowI);
2156 bool DoTypoCorrection) {
2159 NamedDecl *IDecl = LookupSingleName(TUScope,
Id, IdLoc, LookupOrdinaryName);
2161 if (!IDecl && DoTypoCorrection) {
2167 TUScope,
nullptr, CCC, CTK_ErrorRecovery)) {
2168 diagnoseTypo(C, PDiag(diag::err_undef_interface_suggest) <<
Id);
2205 (S->getEntity() && S->getEntity()->isTransparentContext()) ||
2206 (S->isClassScope() && !getLangOpts().
CPlusPlus))
2223 return "ucontext.h";
2225 llvm_unreachable(
"unhandled error kind");
2236 Parent->addDecl(CLinkageDecl);
2242 getCurFPFeatures().isFPConstrained(),
2245 New->
addAttr(BuiltinAttr::CreateImplicit(Context,
ID));
2251 for (
unsigned i = 0, e = FT->getNumParams(); i != e; ++i) {
2254 FT->getParamType(i),
nullptr,
SC_None,
nullptr);
2256 Params.push_back(parm);
2258 New->setParams(Params);
2261 AddKnownFunctionAttributes(New);
2270 Scope *S,
bool ForRedeclaration,
2272 LookupNecessaryTypesForBuiltin(S,
ID);
2277 if (!ForRedeclaration)
2289 Diag(Loc, diag::warn_implicit_decl_no_jmp_buf)
2296 Diag(Loc, diag::warn_implicit_decl_requires_sysheader)
2302 if (!ForRedeclaration &&
2305 Diag(Loc, LangOpts.C99 ? diag::ext_implicit_lib_function_decl_c99
2306 : diag::ext_implicit_lib_function_decl)
2309 Diag(Loc, diag::note_include_header_or_declare)
2317 RegisterLocallyScopedExternCDecl(New, S);
2325 PushOnScopeChains(New, TUScope);
2326 CurContext = SavedContext;
2346 while (
Filter.hasNext()) {
2355 if (
auto *OldTD = dyn_cast<TypedefNameDecl>(Old)) {
2357 Decl->getUnderlyingType()))
2362 if (OldTD->getAnonDeclWithTypedefName(
true) &&
2363 Decl->getAnonDeclWithTypedefName())
2376 OldType = OldTypedef->getUnderlyingType();
2383 int Kind = isa<TypeAliasDecl>(Old) ? 1 : 0;
2384 Diag(New->
getLocation(), diag::err_redefinition_variably_modified_typedef)
2392 if (OldType != NewType &&
2396 int Kind = isa<TypeAliasDecl>(Old) ? 1 : 0;
2398 <<
Kind << NewType << OldType;
2420 if (getLangOpts().ObjC) {
2422 switch (
TypeID->getLength()) {
2426 if (!
TypeID->isStr(
"id"))
2442 if (!
TypeID->isStr(
"Class"))
2449 if (!
TypeID->isStr(
"SEL"))
2476 if (
auto *OldTD = dyn_cast<TypedefNameDecl>(Old)) {
2477 auto *OldTag = OldTD->getAnonDeclWithTypedefName(
true);
2480 if (OldTag && NewTag &&
2481 OldTag->getCanonicalDecl() != NewTag->getCanonicalDecl() &&
2482 !hasVisibleDefinition(OldTag, &Hidden)) {
2486 if (OldTD->isModed())
2488 OldTD->getUnderlyingType());
2493 makeMergedDefinitionVisible(Hidden);
2497 if (isa<EnumDecl>(NewTag)) {
2498 Scope *EnumScope = getNonFieldDeclScope(S);
2499 for (
auto *D : NewTag->decls()) {
2500 auto *ED = cast<EnumConstantDecl>(D);
2503 IdResolver.RemoveDecl(ED);
2504 ED->getLexicalDeclContext()->removeDecl(ED);
2512 if (isIncompatibleTypedef(Old, New))
2519 mergeDeclAttributes(New, Old);
2522 if (getLangOpts().MicrosoftExt)
2530 if (!isa<CXXRecordDecl>(CurContext))
2554 if (!isa<TypedefNameDecl>(Old))
2564 if (getLangOpts().Modules || getLangOpts().
C11)
2571 if (getDiagnostics().getSuppressSystemWarnings() &&
2586 const OwnershipAttr *OA = dyn_cast<OwnershipAttr>(A);
2587 const AnnotateAttr *Ann = dyn_cast<AnnotateAttr>(A);
2588 for (
const auto *i : D->
attrs())
2589 if (i->getKind() == A->
getKind()) {
2591 if (Ann->getAnnotation() == cast<AnnotateAttr>(i)->getAnnotation())
2596 if (OA && isa<OwnershipAttr>(i))
2597 return OA->getOwnKind() == cast<OwnershipAttr>(i)->getOwnKind();
2605 if (
VarDecl *VD = dyn_cast<VarDecl>(D))
2606 return VD->isThisDeclarationADefinition();
2607 if (
TagDecl *TD = dyn_cast<TagDecl>(D))
2608 return TD->isCompleteDefinition() || TD->isBeingDefined();
2619 AlignedAttr *OldAlignasAttr =
nullptr;
2620 AlignedAttr *OldStrictestAlignAttr =
nullptr;
2621 unsigned OldAlign = 0;
2629 if (I->isAlignmentDependent())
2635 unsigned Align = I->getAlignment(S.
Context);
2636 if (Align > OldAlign) {
2638 OldStrictestAlignAttr = I;
2643 AlignedAttr *NewAlignasAttr =
nullptr;
2644 unsigned NewAlign = 0;
2646 if (I->isAlignmentDependent())
2652 unsigned Align = I->getAlignment(S.
Context);
2653 if (Align > NewAlign)
2657 if (OldAlignasAttr && NewAlignasAttr && OldAlign != NewAlign) {
2665 if (OldAlign == 0 || NewAlign == 0) {
2667 if (
ValueDecl *VD = dyn_cast<ValueDecl>(New))
2678 if (OldAlign != NewAlign) {
2679 S.
Diag(NewAlignasAttr->getLocation(), diag::err_alignas_mismatch)
2682 S.
Diag(OldAlignasAttr->getLocation(), diag::note_previous_declaration);
2697 S.
Diag(OldAlignasAttr->getLocation(), diag::note_alignas_on_declaration)
2701 bool AnyAdded =
false;
2704 if (OldAlign > NewAlign) {
2705 AlignedAttr *Clone = OldStrictestAlignAttr->clone(S.
Context);
2706 Clone->setInherited(
true);
2712 if (OldAlignasAttr && !NewAlignasAttr &&
2713 !(AnyAdded && OldStrictestAlignAttr->isAlignas())) {
2714 AlignedAttr *Clone = OldAlignasAttr->clone(S.
Context);
2715 Clone->setInherited(
true);
2723 #define WANT_DECL_MERGE_LOGIC
2724 #include "clang/Sema/AttrParsedAttrImpl.inc"
2725 #undef WANT_DECL_MERGE_LOGIC
2732 if (!DiagnoseMutualExclusions(S, D,
Attr))
2743 if (
const auto *AA = dyn_cast<AvailabilityAttr>(
Attr))
2745 D, *AA, AA->getPlatform(), AA->
isImplicit(), AA->getIntroduced(),
2746 AA->getDeprecated(), AA->getObsoleted(), AA->getUnavailable(),
2747 AA->getMessage(), AA->getStrict(), AA->getReplacement(), AMK,
2749 else if (
const auto *VA = dyn_cast<VisibilityAttr>(
Attr))
2751 else if (
const auto *VA = dyn_cast<TypeVisibilityAttr>(
Attr))
2753 else if (
const auto *ImportA = dyn_cast<DLLImportAttr>(
Attr))
2755 else if (
const auto *ExportA = dyn_cast<DLLExportAttr>(
Attr))
2757 else if (
const auto *EA = dyn_cast<ErrorAttr>(
Attr))
2759 else if (
const auto *FA = dyn_cast<FormatAttr>(
Attr))
2760 NewAttr = S.
mergeFormatAttr(D, *FA, FA->getType(), FA->getFormatIdx(),
2762 else if (
const auto *SA = dyn_cast<SectionAttr>(
Attr))
2764 else if (
const auto *CSA = dyn_cast<CodeSegAttr>(
Attr))
2766 else if (
const auto *IA = dyn_cast<MSInheritanceAttr>(
Attr))
2768 IA->getInheritanceModel());
2769 else if (
const auto *AA = dyn_cast<AlwaysInlineAttr>(
Attr))
2772 else if (S.
getLangOpts().CUDA && isa<FunctionDecl>(D) &&
2773 (isa<CUDAHostAttr>(
Attr) || isa<CUDADeviceAttr>(
Attr) ||
2774 isa<CUDAGlobalAttr>(
Attr))) {
2778 }
else if (
const auto *MA = dyn_cast<MinSizeAttr>(
Attr))
2780 else if (
const auto *SNA = dyn_cast<SwiftNameAttr>(
Attr))
2782 else if (
const auto *OA = dyn_cast<OptimizeNoneAttr>(
Attr))
2784 else if (
const auto *InternalLinkageA = dyn_cast<InternalLinkageAttr>(
Attr))
2786 else if (isa<AlignedAttr>(
Attr))
2790 else if ((isa<DeprecatedAttr>(
Attr) || isa<UnavailableAttr>(
Attr)) &&
2795 else if (
const auto *UA = dyn_cast<UuidAttr>(
Attr))
2796 NewAttr = S.
mergeUuidAttr(D, *UA, UA->getGuid(), UA->getGuidDecl());
2797 else if (
const auto *IMA = dyn_cast<WebAssemblyImportModuleAttr>(
Attr))
2799 else if (
const auto *INA = dyn_cast<WebAssemblyImportNameAttr>(
Attr))
2801 else if (
const auto *TCBA = dyn_cast<EnforceTCBAttr>(
Attr))
2803 else if (
const auto *TCBLA = dyn_cast<EnforceTCBLeafAttr>(
Attr))
2805 else if (
const auto *BTFA = dyn_cast<BTFDeclTagAttr>(
Attr))
2807 else if (
const auto *NT = dyn_cast<HLSLNumThreadsAttr>(
Attr))
2810 else if (
const auto *SA = dyn_cast<HLSLShaderAttr>(
Attr))
2818 if (isa<MSInheritanceAttr>(NewAttr))
2827 if (
const TagDecl *TD = dyn_cast<TagDecl>(D))
2828 return TD->getDefinition();
2829 if (
const VarDecl *VD = dyn_cast<VarDecl>(D)) {
2835 if (
const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
2837 if (FD->isDefined(Def,
true))
2844 for (
const auto *Attribute : D->
attrs())
2845 if (Attribute->getKind() ==
Kind)
2857 if (!Def || Def == New)
2861 for (
unsigned I = 0, E = NewAttributes.size(); I != E;) {
2862 const Attr *NewAttribute = NewAttributes[I];
2864 if (isa<AliasAttr>(NewAttribute) || isa<IFuncAttr>(NewAttribute)) {
2871 NewAttributes.erase(NewAttributes.begin() + I);
2876 VarDecl *VD = cast<VarDecl>(New);
2877 unsigned Diag = cast<VarDecl>(Def)->isThisDeclarationADefinition() ==
2879 ? diag::err_alias_after_tentative
2880 : diag::err_redefinition;
2882 if (
Diag == diag::err_redefinition)
2892 if (
const VarDecl *VD = dyn_cast<VarDecl>(Def)) {
2905 if (isa<C11NoReturnAttr>(NewAttribute)) {
2909 }
else if (isa<UuidAttr>(NewAttribute)) {
2913 }
else if (
const AlignedAttr *AA = dyn_cast<AlignedAttr>(NewAttribute)) {
2914 if (AA->isAlignas()) {
2925 S.
Diag(NewAttribute->
getLocation(), diag::note_alignas_on_declaration)
2927 NewAttributes.erase(NewAttributes.begin() + I);
2931 }
else if (isa<LoaderUninitializedAttr>(NewAttribute)) {
2937 diag::err_loader_uninitialized_redeclaration);
2939 NewAttributes.erase(NewAttributes.begin() + I);
2943 }
else if (isa<SelectAnyAttr>(NewAttribute) &&
2944 cast<VarDecl>(New)->isInline() &&
2945 !cast<VarDecl>(New)->isInlineSpecified()) {
2952 }
else if (isa<OMPDeclareVariantAttr>(NewAttribute)) {
2960 diag::warn_attribute_precede_definition);
2962 NewAttributes.erase(NewAttributes.begin() + I);
2968 const ConstInitAttr *CIAttr,
2969 bool AttrBeforeInit) {
2980 if (SuitableSpelling.empty() && S.
getLangOpts().CPlusPlus11)
2982 InsertLoc, {tok::l_square, tok::l_square,
2983 S.PP.getIdentifierInfo(
"clang"), tok::coloncolon,
2984 S.PP.getIdentifierInfo(
"require_constant_initialization"),
2985 tok::r_square, tok::r_square}));
2986 if (SuitableSpelling.empty())
2988 InsertLoc, {tok::kw___attribute, tok::l_paren, tok::r_paren,
2989 S.PP.getIdentifierInfo(
"require_constant_initialization"),
2990 tok::r_paren, tok::r_paren}));
2991 if (SuitableSpelling.empty() && S.
getLangOpts().CPlusPlus20)
2992 SuitableSpelling =
"constinit";
2993 if (SuitableSpelling.empty() && S.
getLangOpts().CPlusPlus11)
2994 SuitableSpelling =
"[[clang::require_constant_initialization]]";
2995 if (SuitableSpelling.empty())
2996 SuitableSpelling =
"__attribute__((require_constant_initialization))";
2997 SuitableSpelling +=
" ";
2999 if (AttrBeforeInit) {
3002 assert(CIAttr->isConstinit() &&
"should not diagnose this for attribute");
3005 S.
Diag(CIAttr->getLocation(), diag::note_constinit_specified_here);
3009 S.
Diag(CIAttr->getLocation(),
3010 CIAttr->isConstinit() ? diag::err_constinit_added_too_late
3011 : diag::warn_require_const_init_added_too_late)
3014 << CIAttr->isConstinit()
3023 UsedAttr *NewAttr = OldAttr->clone(Context);
3024 NewAttr->setInherited(
true);
3028 RetainAttr *NewAttr = OldAttr->clone(Context);
3029 NewAttr->setInherited(
true);
3039 const auto *OldConstInit = Old->
getAttr<ConstInitAttr>();
3040 const auto *NewConstInit = New->
getAttr<ConstInitAttr>();
3041 if (
bool(OldConstInit) !=
bool(NewConstInit)) {
3042 const auto *OldVD = cast<VarDecl>(Old);
3043 auto *NewVD = cast<VarDecl>(New);
3049 (NewVD->hasInit() || NewVD->isThisDeclarationADefinition()))
3052 if (InitDecl == NewVD) {
3056 if (OldConstInit && OldConstInit->isConstinit())
3059 }
else if (NewConstInit) {
3063 if (InitDecl && InitDecl != NewVD) {
3066 NewVD->dropAttr<ConstInitAttr>();
3074 if (AsmLabelAttr *NewA = New->
getAttr<AsmLabelAttr>()) {
3075 if (AsmLabelAttr *OldA = Old->
getAttr<AsmLabelAttr>()) {
3076 if (!OldA->isEquivalent(NewA)) {
3079 Diag(OldA->getLocation(), diag::note_previous_declaration);
3081 }
else if (Old->
isUsed()) {
3085 << isa<FunctionDecl>(Old) << New->
getAttr<AsmLabelAttr>()->getRange();
3090 if (
const auto *NewAbiTagAttr = New->
getAttr<AbiTagAttr>()) {
3091 if (
const auto *OldAbiTagAttr = Old->
getAttr<AbiTagAttr>()) {
3092 for (
const auto &NewTag : NewAbiTagAttr->tags()) {
3093 if (!llvm::is_contained(OldAbiTagAttr->tags(), NewTag)) {
3094 Diag(NewAbiTagAttr->getLocation(),
3095 diag::err_new_abi_tag_on_redeclaration)
3097 Diag(OldAbiTagAttr->getLocation(), diag::note_previous_declaration);
3101 Diag(NewAbiTagAttr->getLocation(), diag::err_abi_tag_on_redeclaration);
3107 if (New->
hasAttr<SectionAttr>() && !Old->
hasAttr<SectionAttr>()) {
3108 if (
auto *VD = dyn_cast<VarDecl>(New)) {
3110 Diag(New->
getLocation(), diag::warn_attribute_section_on_redeclaration);
3117 const auto *NewCSA = New->
getAttr<CodeSegAttr>();
3118 if (NewCSA && !Old->
hasAttr<CodeSegAttr>() &&
3119 !NewCSA->isImplicit() && isa<CXXMethodDecl>(New)) {
3137 if (isa<DeprecatedAttr>(I) ||
3138 isa<UnavailableAttr>(I) ||
3139 isa<AvailabilityAttr>(I)) {
3144 case AMK_Redeclaration:
3146 case AMK_ProtocolImplementation:
3147 case AMK_OptionalProtocolImplementation:
3154 if (isa<UsedAttr>(I) || isa<RetainAttr>(I))
3176 const CarriesDependencyAttr *CDA = newDecl->
getAttr<CarriesDependencyAttr>();
3177 if (CDA && !oldDecl->
hasAttr<CarriesDependencyAttr>()) {
3178 S.
Diag(CDA->getLocation(),
3179 diag::err_carries_dependency_missing_on_first_decl) << 1;
3187 diag::note_carries_dependency_missing_first_decl) << 1;
3193 bool foundAny = newDecl->
hasAttrs();
3202 cast<InheritableParamAttr>(I->clone(S.
Context));
3217 if (*Oldnullability != *Newnullability) {
3218 S.
Diag(NewParam->
getLocation(), diag::warn_mismatched_nullability_attr)
3243 struct GNUCompatibleParamWarning {
3253 template <
typename T>
3254 static std::pair<diag::kind, SourceLocation>
3258 if (Old->isThisDeclarationADefinition())
3259 PrevDiag = diag::note_previous_definition;
3260 else if (Old->isImplicit()) {
3261 PrevDiag = diag::note_previous_implicit_declaration;
3262 if (
const auto *FD = dyn_cast<FunctionDecl>(Old)) {
3263 if (FD->getBuiltinID())
3264 PrevDiag = diag::note_previous_builtin_declaration;
3267 OldLocation = New->getLocation();
3269 PrevDiag = diag::note_previous_declaration;
3270 return std::make_pair(PrevDiag, OldLocation);
3278 return ((FD->
hasAttr<GNUInlineAttr>() || LangOpts.GNUInline) &&
3279 !LangOpts.CPlusPlus &&
3291 template <
typename T>
3305 template<
typename T>
static bool isExternC(T *D) {
return D->isExternC(); }
3312 template<
typename ExpectedDecl>
3334 !Old->getDeclContext()->getRedeclContext()->Equals(
3335 New->getDeclContext()->getRedeclContext()) &&
3340 S.
Diag(New->getLocation(), diag::err_using_decl_conflict_reverse);
3353 const auto *AttrA = A->
getAttr<PassObjectSizeAttr>();
3354 const auto *AttrB = B->
getAttr<PassObjectSizeAttr>();
3357 return AttrA && AttrB && AttrA->getType() == AttrB->getType() &&
3358 AttrA->isDynamic() == AttrB->isDynamic();
3361 return std::equal(A->param_begin(), A->param_end(), B->
param_begin(), AttrEq);
3384 if (NamedDC->Equals(SemaDC))
3387 assert((NamedDC->InEnclosingNamespaceSetOf(SemaDC) ||
3389 "unexpected context for redeclaration");
3400 if (
auto *FD = dyn_cast<FunctionDecl>(NewD))
3401 FixSemaDC(FD->getDescribedFunctionTemplate());
3402 else if (
auto *VD = dyn_cast<VarDecl>(NewD))
3403 FixSemaDC(VD->getDescribedVarTemplate());
3418 bool MergeTypeWithOld,
bool NewDeclIsDefn) {
3425 Diag(Shadow->getTargetDecl()->getLocation(),
3426 diag::note_using_decl_target);
3427 Diag(Shadow->getIntroducer()->getLocation(), diag::note_using_decl)
3436 if (checkUsingShadowRedecl<FunctionTemplateDecl>(*
this, Shadow,
3439 OldD = Old = cast<FunctionTemplateDecl>(Shadow->getTargetDecl())
3442 if (checkUsingShadowRedecl<FunctionDecl>(*
this, Shadow, New))
3444 OldD = Old = cast<FunctionDecl>(Shadow->getTargetDecl());
3463 if (!getASTContext().canBuiltinBeRedeclared(Old)) {
3472 std::tie(PrevDiag, OldLocation) =
3479 if (!isa<CXXMethodDecl>(New) && !isa<CXXMethodDecl>(Old) &&
3484 if (getLangOpts().MicrosoftExt) {
3486 Diag(OldLocation, PrevDiag);
3489 Diag(OldLocation, PrevDiag);
3494 if (
const auto *ILA = New->
getAttr<InternalLinkageAttr>())
3495 if (!Old->
hasAttr<InternalLinkageAttr>()) {
3499 New->
dropAttr<InternalLinkageAttr>();
3502 if (
auto *EA = New->
getAttr<ErrorAttr>()) {
3503 if (!Old->
hasAttr<ErrorAttr>()) {
3504 Diag(EA->getLocation(), diag::err_attribute_missing_on_first_decl) << EA;
3510 if (CheckRedeclarationInModule(New, Old))
3513 if (!getLangOpts().CPlusPlus) {
3514 bool OldOvl = Old->
hasAttr<OverloadableAttr>();
3525 const Decl *DiagOld = Old;
3527 auto OldIter = llvm::find_if(Old->
redecls(), [](
const Decl *D) {
3528 const auto *A = D->getAttr<OverloadableAttr>();
3529 return A && !A->isImplicit();
3533 DiagOld = OldIter == Old->
redecls_end() ? nullptr : *OldIter;
3538 diag::note_attribute_overloadable_prev_overload)
3542 New->
addAttr(OverloadableAttr::CreateImplicit(Context));
3563 const FunctionType *OldType = cast<FunctionType>(OldQType);
3564 const FunctionType *NewType = cast<FunctionType>(NewQType);
3567 bool RequiresAdjustment =
false;
3569 if (OldTypeInfo.
getCC() != NewTypeInfo.
getCC()) {
3574 bool NewCCExplicit = getCallingConvAttributedType(New->
getType());
3575 if (!NewCCExplicit) {
3579 RequiresAdjustment =
true;
3589 << (
int)CallingConventionIgnoredReason::BuiltinFunction;
3591 RequiresAdjustment =
true;
3594 bool FirstCCExplicit = getCallingConvAttributedType(
First->getType());
3598 << (!FirstCCExplicit ?
"" :
3602 Diag(
First->getLocation(), diag::note_previous_declaration);
3610 RequiresAdjustment =
true;
3620 Diag(OldLocation, diag::note_previous_declaration);
3625 RequiresAdjustment =
true;
3632 <<
"'ns_returns_retained'";
3633 Diag(OldLocation, diag::note_previous_declaration);
3638 RequiresAdjustment =
true;
3644 AnyX86NoCallerSavedRegistersAttr *
Attr =
3645 New->
getAttr<AnyX86NoCallerSavedRegistersAttr>();
3647 Diag(OldLocation, diag::note_previous_declaration);
3652 RequiresAdjustment =
true;
3655 if (RequiresAdjustment) {
3665 !New->
hasAttr<GNUInlineAttr>() &&
3666 !getLangOpts().GNUInline &&
3674 if (New->
hasAttr<GNUInlineAttr>() &&
3685 Diag(OldLocation, PrevDiag) << Old << Old->
getType();
3700 if (CheckEquivalentExceptionSpec(Old, New))
3712 if (!Context.
hasSameType(OldDeclaredReturnType, NewDeclaredReturnType) &&
3713 canFullyTypeCheckRedeclaration(New, Old, NewDeclaredReturnType,
3714 OldDeclaredReturnType)) {
3722 Diag(New->
getLocation(), diag::err_member_def_does_not_match_ret_type)
3727 Diag(OldLocation, PrevDiag) << Old << Old->
getType()
3736 QualType NewReturnType = cast<FunctionType>(NewQType)->getReturnType();
3737 if (OldReturnType != NewReturnType) {
3753 const CXXMethodDecl *OldMethod = dyn_cast<CXXMethodDecl>(Old);
3755 if (OldMethod && NewMethod) {
3762 bool IsClassScopeExplicitSpecialization =
3768 !IsClassScopeExplicitSpecialization) {
3774 Diag(OldLocation, PrevDiag) << Old << Old->
getType();
3782 if (!inTemplateInstantiation()) {
3784 if (isa<CXXConstructorDecl>(OldMethod))
3785 NewDiag = diag::err_constructor_redeclared;
3786 else if (isa<CXXDestructorDecl>(NewMethod))
3787 NewDiag = diag::err_destructor_redeclared;
3788 else if (isa<CXXConversionDecl>(NewMethod))
3789 NewDiag = diag::err_conv_function_redeclared;
3791 NewDiag = diag::err_member_redeclared;
3795 Diag(New->
getLocation(), diag::err_member_redeclared_in_instantiation)
3798 Diag(OldLocation, PrevDiag) << Old << Old->
getType();
3811 diag::err_definition_of_implicitly_declared_member)
3812 << New << getSpecialMember(OldMethod);
3817 diag::err_definition_of_explicitly_defaulted_member)
3818 << getSpecialMember(OldMethod);
3827 if (
const auto *NRA = New->
getAttr<CXX11NoReturnAttr>())
3828 if (!Old->
hasAttr<CXX11NoReturnAttr>()) {
3829 Diag(NRA->getLocation(), diag::err_attribute_missing_on_first_decl)
3838 const CarriesDependencyAttr *CDA = New->
getAttr<CarriesDependencyAttr>();
3839 if (CDA && !Old->
hasAttr<CarriesDependencyAttr>()) {
3840 Diag(CDA->getLocation(),
3841 diag::err_carries_dependency_missing_on_first_decl) << 0;
3843 diag::note_carries_dependency_missing_first_decl) << 0;
3852 QualType OldQTypeForComparison = OldQType;
3857 OldQTypeForComparison =
QualType(OldTypeForComparison, 0);
3872 Diag(OldLocation, PrevDiag);
3874 Diag(New->
getLocation(), diag::err_different_language_linkage) << New;
3875 Diag(OldLocation, PrevDiag);
3886 return MergeCompatibleFunctionDecls(New, Old, S, MergeTypeWithOld);
3891 if (!canFullyTypeCheckRedeclaration(New, Old, NewQType, OldQType))
3946 bool IsWithoutProtoADef =
false, IsWithProtoADef =
false;
3947 if (WithoutProto == New)
3948 IsWithoutProtoADef = NewDeclIsDefn;
3950 IsWithProtoADef = NewDeclIsDefn;
3952 diag::warn_non_prototype_changes_behavior)
3953 << IsWithoutProtoADef << (WithoutProto->
getNumParams() ? 0 : 1)
3954 << (WithoutProto == Old) << IsWithProtoADef;
3964 !IsWithoutProtoADef)
3974 if (MergeTypeWithOld && isa<FunctionNoProtoType>(NewFuncType) &&
3975 (OldProto = dyn_cast<FunctionProtoType>(OldFuncType))) {
3978 assert(!OldProto->hasExceptionSpec() &&
"Exception spec in C");
3982 OldProto->getExtProtoInfo());
3988 for (
const auto &ParamType : OldProto->param_types()) {
3991 ParamType,
nullptr,
SC_None,
nullptr);
3994 Params.push_back(Param);
3997 New->setParams(Params);
4000 return MergeCompatibleFunctionDecls(New, Old, S, MergeTypeWithOld);
4033 NewProto->getReturnType());
4034 bool LooseCompatible = !MergedReturn.
isNull();
4036 LooseCompatible && Idx !=
End; ++Idx) {
4040 NewProto->getParamType(Idx))) {
4041 ArgTypes.push_back(NewParm->
getType());
4045 GNUCompatibleParamWarning Warn = { OldParm, NewParm,
4046 NewProto->getParamType(Idx) };
4047 Warnings.push_back(Warn);
4048 ArgTypes.push_back(NewParm->
getType());
4050 LooseCompatible =
false;
4053 if (LooseCompatible) {
4054 for (
unsigned Warn = 0; Warn < Warnings.size(); ++Warn) {
4055 Diag(Warnings[Warn].NewParm->getLocation(),
4056 diag::ext_param_promoted_not_compatible_with_prototype)
4057 << Warnings[Warn].PromotedType
4058 << Warnings[Warn].OldParm->getType();
4059 if (Warnings[Warn].OldParm->getLocation().isValid())
4060 Diag(Warnings[Warn].OldParm->getLocation(),
4061 diag::note_previous_declaration);
4064 if (MergeTypeWithOld)
4067 return MergeCompatibleFunctionDecls(New, Old, S, MergeTypeWithOld);
4084 Diag(OldLocation, diag::note_previous_builtin_declaration)
4089 PrevDiag = diag::note_previous_builtin_declaration;
4093 Diag(OldLocation, PrevDiag) << Old << Old->
getType();
4107 Scope *S,
bool MergeTypeWithOld) {
4109 mergeDeclAttributes(New, Old);
4122 for (
unsigned i = 0, e = New->
getNumParams(); i != e; ++i) {
4130 return MergeCXXFunctionDecl(New, Old, S);
4136 if (!Merged.isNull() && MergeTypeWithOld)
4147 ? (oldMethod->
isOptional() ? AMK_OptionalProtocolImplementation
4148 : AMK_ProtocolImplementation)
4149 : isa<ObjCImplDecl>(newMethod->
getDeclContext()) ? AMK_Redeclaration
4152 mergeDeclAttributes(newMethod, oldMethod, MergeKind);
4159 ni != ne && oi != oe; ++ni, ++oi)
4162 CheckObjCMethodOverride(newMethod, oldMethod);
4169 ? diag::err_redefinition_different_type
4170 : diag::err_redeclaration_different_type)
4175 std::tie(PrevDiag, OldLocation)
4177 S.
Diag(OldLocation, PrevDiag);
4189 bool MergeTypeWithOld) {
4200 return MergeVarDeclExceptionSpecs(New, Old);
4217 QualType PrevVDTy = PrevVD->getType();
4271 if (MergeTypeWithOld)
4317 if (!shouldLinkPossiblyHiddenDecl(
Previous, New))
4327 OldTemplate = dyn_cast<VarTemplateDecl>(
Previous.getFoundDecl());
4331 dyn_cast<UsingShadowDecl>(
Previous.getRepresentativeDecl()))
4332 if (checkUsingShadowRedecl<VarTemplateDecl>(*
this, Shadow, NewTemplate))
4335 Old = dyn_cast<VarDecl>(
Previous.getFoundDecl());
4338 dyn_cast<UsingShadowDecl>(
Previous.getRepresentativeDecl()))
4339 if (checkUsingShadowRedecl<VarDecl>(*
this, Shadow, New))
4346 notePreviousDefinition(
Previous.getRepresentativeDecl(),
4359 true, TPL_TemplateMatch))
4373 mergeDeclAttributes(New, Old);
4376 if (New->
hasAttr<WeakImportAttr>() &&
4378 !Old->
hasAttr<WeakImportAttr>()) {
4385 if (
const auto *ILA = New->
getAttr<InternalLinkageAttr>())
4386 if (!Old->
hasAttr<InternalLinkageAttr>()) {
4390 New->
dropAttr<InternalLinkageAttr>();
4395 if (MostRecent != Old) {
4396 MergeVarDeclTypes(New, MostRecent,
4408 std::tie(PrevDiag, OldLocation) =
4415 if (getLangOpts().MicrosoftExt) {
4418 Diag(OldLocation, PrevDiag);
4422 Diag(OldLocation, PrevDiag);
4441 Diag(OldLocation, PrevDiag);
4449 Diag(OldLocation, PrevDiag);
4455 Diag(OldLocation, PrevDiag);
4459 if (CheckRedeclarationInModule(New, Old))
4471 Diag(OldLocation, PrevDiag);
4481 Diag(Def->getLocation(), diag::note_previous_definition);
4495 Diag(OldLocation, PrevDiag);
4498 Diag(OldLocation, PrevDiag);
4506 Diag(OldLocation, PrevDiag);
4516 diag::warn_deprecated_redundant_constexpr_static_def);
4519 if (Def && checkVarDeclRedefinition(Def, New))
4525 Diag(New->
getLocation(), diag::err_different_language_linkage) << New;
4526 Diag(OldLocation, PrevDiag);
4555 auto &HSI = PP.getHeaderSearchInfo();
4556 StringRef HdrFilename =
4559 auto noteFromModuleOrInclude = [&](
Module *Mod,
4565 if (IncLoc.isValid()) {
4567 Diag(IncLoc, diag::note_redefinition_modules_same_file)
4573 Diag(IncLoc, diag::note_redefinition_include_same_file)
4574 << HdrFilename.str();
4584 if (FNew == FOld && FNewDecLoc.second == FOldDecLoc.second) {
4589 EmittedDiag |= noteFromModuleOrInclude(getCurrentModule(), NewIncLoc);
4592 if (FOld && !HSI.isFileMultipleIncludeGuarded(FOld))
4607 if (!hasVisibleDefinition(Old) &&
4619 makeMergedDefinitionVisible(OldTD);
4620 makeMergedDefinitionVisible(Old);
4636 return ParsedFreeStandingDeclSpec(
4648 ? S->getMSCurManglingNumber()
4649 : S->getMSLastManglingNumber();
4656 if (isa<CXXRecordDecl>(Tag->
getParent())) {
4671 Decl *ManglingContextDecl;
4672 std::tie(MCtx, ManglingContextDecl) =
4682 struct NonCLikeKind {
4694 explicit operator bool() {
return Kind != None; }
4709 return {NonCLikeKind::BaseClass,
4712 bool Invalid =
false;
4721 if (
auto *FD = dyn_cast<FieldDecl>(D)) {
4722 if (FD->hasInClassInitializer()) {
4723 auto *Init = FD->getInClassInitializer();
4724 return {NonCLikeKind::DefaultMemberInit,
4732 if (isa<FriendDecl>(D))
4737 if (isa<StaticAssertDecl>(D) || isa<IndirectFieldDecl>(D) ||
4740 auto *MemberRD = dyn_cast<CXXRecordDecl>(D);
4748 if (MemberRD->isLambda())
4749 return {NonCLikeKind::Lambda, MemberRD->getSourceRange()};
4753 if (MemberRD->isThisDeclarationADefinition()) {
4789 const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(TagFromDeclSpec);
4793 if (NonCLike || ChangesLinkage) {
4797 unsigned DiagID = diag::ext_non_c_like_anon_struct_in_typedef;
4798 if (ChangesLinkage) {
4801 DiagID = diag::err_typedef_changes_linkage;
4803 DiagID = diag::err_non_c_like_anon_struct_in_typedef;
4809 TextToInsert +=
' ';
4812 Diag(FixitLoc, DiagID)
4813 << isa<TypeAliasDecl>(NewTD)
4816 Diag(NonCLike.Range.getBegin(), diag::note_non_c_like_anon_struct)
4817 << NonCLike.Kind - 1 << NonCLike.Range;
4820 << NewTD << isa<TypeAliasDecl>(NewTD);
4843 llvm_unreachable(
"unexpected type specifier");
4854 bool IsExplicitInstantiation,
4856 Decl *TagD =
nullptr;
4871 if (isa<TagDecl>(TagD))
4872 Tag = cast<TagDecl>(TagD);
4874 Tag = CTD->getTemplatedDecl();
4878 handleTagNumbering(Tag, S);
4889 diag::err_typecheck_invalid_restrict_not_pointer_noarg)
4895 << getLangOpts().CPlusPlus17;
4913 DiagnoseFunctionSpecifiers(DS);
4920 return ActOnFriendTypeDecl(S, DS, TemplateParams);
4924 bool IsExplicitSpecialization =
4925 !TemplateParams.empty() && TemplateParams.back()->size() == 0;
4927 !IsExplicitInstantiation && !IsExplicitSpecialization &&
4928 !isa<ClassTemplatePartialSpecializationDecl>(Tag)) {
4937 Diag(SS.
getBeginLoc(), diag::err_standalone_class_nested_name_specifier)
4943 bool DeclaresAnything =
true;
4946 if (
RecordDecl *Record = dyn_cast_or_null<RecordDecl>(Tag)) {
4947 if (!Record->getDeclName() && Record->isCompleteDefinition() &&
4950 Record->getDeclContext()->isRecord()) {
4958 if (CurContext->isFunctionOrMethod())
4959 AnonRecord = Record;
4960 return BuildAnonymousStructOrUnion(S, DS, AS, Record,
4964 DeclaresAnything =
false;
4974 if (!getLangOpts().
CPlusPlus && CurContext->isRecord() &&
4987 Record = dyn_cast<RecordDecl>(Tag);
4990 Record = RT->getDecl();
4992 Record = UT->getDecl();
4994 if (Record && getLangOpts().MicrosoftExt) {
4997 return BuildMicrosoftCAnonymousStruct(S, DS, Record);
5000 DeclaresAnything =
false;
5011 if (
EnumDecl *Enum = dyn_cast_or_null<EnumDecl>(Tag))
5012 if (Enum->enumerator_begin() == Enum->enumerator_end() &&
5013 !Enum->getIdentifier() && !Enum->isInvalidDecl())
5014 DeclaresAnything =
false;
5022 DeclaresAnything =
false;
5031 ActOnDocumentableDecl(TagD);
5041 if (!DeclaresAnything) {
5044 Diag(DS.
getBeginLoc(), (IsExplicitInstantiation || !TemplateParams.empty())
5045 ? diag::err_no_declarators
5046 : diag::ext_no_declarators)
5059 unsigned DiagID = diag::warn_standalone_specifier;
5061 DiagID = diag::ext_standalone_specifier;
5102 Diag(AL.getLoc(), diag::warn_declspec_attribute_ignored)
5105 Diag(AL.getLoc(), diag::warn_declspec_attribute_ignored)
5129 assert(PrevDecl &&
"Expected a non-null Decl");
5134 SemaRef.
Diag(NameLoc, diag::err_anonymous_record_member_redecl)
5136 SemaRef.
Diag(PrevDecl->
getLocation(), diag::note_previous_declaration);
5161 bool Invalid =
false;
5164 for (
auto *D : AnonRecord->
decls()) {
5165 if ((isa<FieldDecl>(D) || isa<IndirectFieldDecl>(D)) &&
5166 cast<NamedDecl>(D)->getDeclName()) {
5182 unsigned OldChainingSize = Chaining.size();
5184 Chaining.append(IF->chain_begin(), IF->chain_end());
5186 Chaining.push_back(VD);
5188 assert(Chaining.size() >= 2);
5191 for (
unsigned i = 0; i < Chaining.size(); i++)
5192 NamedChain[i] = Chaining[i];
5196 VD->
getType(), {NamedChain, Chaining.size()});
5208 Chaining.resize(OldChainingSize);
5223 "Parser allowed 'typedef' as storage class VarDecl.");
5224 switch (StorageClassSpec) {
5238 llvm_unreachable(
"unknown storage class specifier");
5244 for (
const auto *I : Record->
decls()) {
5245 const auto *FD = dyn_cast<FieldDecl>(I);
5246 if (
const auto *IFD = dyn_cast<IndirectFieldDecl>(I))
5247 FD = IFD->getAnonField();
5248 if (FD && FD->hasInClassInitializer())
5249 return FD->getLocation();
5252 llvm_unreachable(
"couldn't find in-class initializer");
5257 if (!
Parent->isUnion() || !
Parent->hasInClassInitializer())
5260 S.
Diag(DefaultInitLoc, diag::err_multiple_mem_union_initialization);
5266 if (!
Parent->isUnion() || !
Parent->hasInClassInitializer())
5287 else if (!Record->
isUnion() && !getLangOpts().
C11)
5292 bool Invalid =
false;
5294 const char *PrevSpec =
nullptr;
5305 !cast<NamespaceDecl>(OwnerScope)->isAnonymousNamespace()))) {
5311 PrevSpec, DiagID, Policy);
5317 isa<RecordDecl>(Owner)) {
5319 diag::err_anonymous_union_with_storage_spec)
5333 << Record->
isUnion() <<
"const"
5337 diag::ext_anonymous_struct_union_qualified)
5338 << Record->
isUnion() <<
"volatile"
5342 diag::ext_anonymous_struct_union_qualified)
5343 << Record->
isUnion() <<
"restrict"
5347 diag::ext_anonymous_struct_union_qualified)
5348 << Record->
isUnion() <<
"_Atomic"
5352 diag::ext_anonymous_struct_union_qualified)
5353 << Record->
isUnion() <<
"__unaligned"
5363 for (
auto *Mem : Record->
decls()) {
5365 if (Mem->isInvalidDecl())
5368 if (
auto *FD = dyn_cast<FieldDecl>(Mem)) {
5372 assert(FD->getAccess() !=
AS_none);
5374 Diag(FD->getLocation(), diag::err_anonymous_record_nonpublic_member)
5384 if (CheckNontrivialField(FD))
5386 }
else if (Mem->isImplicit()) {
5388 }
else if (isa<TagDecl>(Mem) && Mem->getDeclContext() != Record) {
5393 }
else if (
auto *MemRecord = dyn_cast<RecordDecl>(Mem)) {
5394 if (!MemRecord->isAnonymousStructOrUnion() &&
5395 MemRecord->getDeclName()) {
5397 if (getLangOpts().MicrosoftExt)
5398 Diag(MemRecord->getLocation(), diag::ext_anonymous_record_with_type)
5402 Diag(MemRecord->getLocation(), diag::err_anonymous_record_with_type)
5410 Diag(MemRecord->getLocation(),
5411 diag::ext_anonymous_record_with_anonymous_type)
5414 }
else if (isa<AccessSpecDecl>(Mem)) {
5416 }
else if (isa<StaticAssertDecl>(Mem)) {
5421 unsigned DK = diag::err_anonymous_record_bad_member;
5422 if (isa<TypeDecl>(Mem))
5423 DK = diag::err_anonymous_record_with_type;
5424 else if (isa<FunctionDecl>(Mem))
5425 DK = diag::err_anonymous_record_with_function;
5426 else if (isa<VarDecl>(Mem))
5427 DK = diag::err_anonymous_record_with_static;
5430 if (getLangOpts().MicrosoftExt &&
5431 DK == diag::err_anonymous_record_with_type)
5432 Diag(Mem->getLocation(), diag::ext_anonymous_record_with_type)
5435 Diag(Mem->getLocation(), DK) << Record->
isUnion();
5444 if (cast<CXXRecordDecl>(Record)->hasInClassInitializer() &&
5447 cast<CXXRecordDecl>(Record));
5452 << getLangOpts().CPlusPlus;
5471 assert(TInfo &&
"couldn't build declarator info for anonymous struct/union");
5475 if (
RecordDecl *OwningClass = dyn_cast<RecordDecl>(Owner)) {
5482 ProcessDeclAttributes(S, Anon, Dc);
5485 FieldCollector->Add(cast<FieldDecl>(Anon));
5506 ActOnUninitializedDecl(Anon);