59#include "llvm/ADT/STLForwardCompat.h"
60#include "llvm/ADT/SmallString.h"
61#include "llvm/ADT/StringExtras.h"
62#include "llvm/TargetParser/Triple.h"
67#include <unordered_map>
74 Decl *Group[2] = { OwnedType, Ptr };
85 TypeNameValidatorCCC(
bool AllowInvalid,
bool WantClass =
false,
86 bool AllowTemplates =
false,
87 bool AllowNonTemplates =
true)
88 : AllowInvalidDecl(AllowInvalid), WantClassName(WantClass),
89 AllowTemplates(AllowTemplates), AllowNonTemplates(AllowNonTemplates) {
90 WantExpressionKeywords =
false;
91 WantCXXNamedCasts =
false;
92 WantRemainingKeywords =
false;
97 if (!AllowInvalidDecl && ND->isInvalidDecl())
101 return AllowTemplates;
103 bool IsType = isa<TypeDecl>(ND) || isa<ObjCInterfaceDecl>(ND);
107 if (AllowNonTemplates)
112 if (AllowTemplates) {
113 auto *RD = dyn_cast<CXXRecordDecl>(ND);
114 if (!RD || !RD->isInjectedClassName())
116 RD = cast<CXXRecordDecl>(RD->getDeclContext());
117 return RD->getDescribedClassTemplate() ||
118 isa<ClassTemplateSpecializationDecl>(RD);
124 return !WantClassName && candidate.
isKeyword();
127 std::unique_ptr<CorrectionCandidateCallback> clone()
override {
128 return std::make_unique<TypeNameValidatorCCC>(*
this);
132 bool AllowInvalidDecl;
135 bool AllowNonTemplates;
141enum class UnqualifiedTypeNameLookupResult {
152static UnqualifiedTypeNameLookupResult
157 return UnqualifiedTypeNameLookupResult::NotFound;
159 UnqualifiedTypeNameLookupResult FoundTypeDecl =
160 UnqualifiedTypeNameLookupResult::NotFound;
163 if (
auto *BaseTT =
Base.getType()->getAs<
TagType>())
164 BaseRD = BaseTT->getAsCXXRecordDecl();
168 if (!TST || !TST->isDependentType())
170 auto *TD = TST->getTemplateName().getAsTemplateDecl();
173 if (
auto *BasePrimaryTemplate =
174 dyn_cast_or_null<CXXRecordDecl>(TD->getTemplatedDecl())) {
176 BaseRD = BasePrimaryTemplate;
177 else if (
auto *CTD = dyn_cast<ClassTemplateDecl>(TD)) {
179 CTD->findPartialSpecialization(
Base.getType()))
187 if (!isa<TypeDecl>(ND))
188 return UnqualifiedTypeNameLookupResult::FoundNonType;
189 FoundTypeDecl = UnqualifiedTypeNameLookupResult::FoundType;
191 if (FoundTypeDecl == UnqualifiedTypeNameLookupResult::NotFound) {
193 case UnqualifiedTypeNameLookupResult::FoundNonType:
194 return UnqualifiedTypeNameLookupResult::FoundNonType;
195 case UnqualifiedTypeNameLookupResult::FoundType:
196 FoundTypeDecl = UnqualifiedTypeNameLookupResult::FoundType;
198 case UnqualifiedTypeNameLookupResult::NotFound:
205 return FoundTypeDecl;
213 UnqualifiedTypeNameLookupResult FoundTypeDecl =
214 UnqualifiedTypeNameLookupResult::NotFound;
216 DC && FoundTypeDecl == UnqualifiedTypeNameLookupResult::NotFound;
220 RD = dyn_cast<CXXRecordDecl>(DC);
224 if (FoundTypeDecl != UnqualifiedTypeNameLookupResult::FoundType)
230 S.
Diag(NameLoc, diag::ext_found_in_dependent_base) << &II;
252 bool WantNontrivialTypeSourceInfo =
true) {
254 case Type::DeducedTemplateSpecialization:
256 case Type::InjectedClassName:
259 case Type::UnresolvedUsing:
264 case Type::ObjCInterface:
265 case Type::ObjCTypeParam:
266 case Type::TemplateTypeParm:
269 llvm_unreachable(
"Unexpected Type Class");
277 if (!WantNontrivialTypeSourceInfo)
281 Builder.pushTypeSpec(
T).setNameLoc(NameLoc);
290 bool HasTrailingDot,
ParsedType ObjectTypePtr,
291 bool IsCtorOrDtorName,
292 bool WantNontrivialTypeSourceInfo,
293 bool IsClassTemplateDeductionContext,
297 bool AllowDeducedTemplate = IsClassTemplateDeductionContext &&
299 !isClassName && !HasTrailingDot;
324 !isClassName && !IsCtorOrDtorName)
326 bool IsImplicitTypename = !isClassName && !IsCtorOrDtorName;
327 if (IsImplicitTypename) {
330 Diag(QualifiedLoc, diag::warn_cxx17_compat_implicit_typename);
332 Diag(QualifiedLoc, diag::ext_implicit_typename)
339 if (WantNontrivialTypeSourceInfo)
372 if (ObjectTypePtr &&
Result.empty()) {
396 switch (
Result.getResultKind()) {
399 TypeNameValidatorCCC CCC(
true, isClassName,
400 AllowDeducedTemplate);
405 bool MemberOfUnknownSpecialization;
414 if (Correction && (NNS || NewII != &II) &&
420 Template, MemberOfUnknownSpecialization))) {
422 isClassName, HasTrailingDot, ObjectTypePtr,
424 WantNontrivialTypeSourceInfo,
425 IsClassTemplateDeductionContext);
428 PDiag(diag::err_unknown_type_or_class_name_suggest)
429 <<
Result.getLookupName() << isClassName);
432 *CorrectedII = NewII;
437 Result.suppressDiagnostics();
453 Result.suppressDiagnostics();
463 Result.suppressDiagnostics();
469 Res != ResEnd; ++Res) {
471 if (isa<TypeDecl, ObjCInterfaceDecl, UnresolvedUsingIfExistsDecl>(
478 FoundUsingShadow = dyn_cast<UsingShadowDecl>(*Res);
490 Result.suppressDiagnostics();
501 IIDecl =
Result.getFoundDecl();
502 FoundUsingShadow = dyn_cast<UsingShadowDecl>(*
Result.begin());
506 assert(IIDecl &&
"Didn't find decl");
509 if (
TypeDecl *TD = dyn_cast<TypeDecl>(IIDecl)) {
513 auto *LookupRD = dyn_cast_or_null<CXXRecordDecl>(LookupCtx);
514 auto *FoundRD = dyn_cast<CXXRecordDecl>(TD);
515 if (!isClassName && !IsCtorOrDtorName && LookupRD && FoundRD &&
516 FoundRD->isInjectedClassName() &&
518 Diag(NameLoc, diag::err_out_of_line_qualified_id_type_names_constructor)
529 FoundUsingShadow =
nullptr;
530 }
else if (
auto *UD = dyn_cast<UnresolvedUsingIfExistsDecl>(IIDecl)) {
534 }
else if (AllowDeducedTemplate) {
536 assert(!FoundUsingShadow || FoundUsingShadow->
getTargetDecl() == TD);
543 FoundUsingShadow =
nullptr;
549 Result.suppressDiagnostics();
553 if (FoundUsingShadow)
556 return buildNamedType(*
this, SS,
T, NameLoc, WantNontrivialTypeSourceInfo);
564 auto *ND = dyn_cast<NamespaceDecl>(DC);
565 if (ND && !ND->isInline() && !ND->isAnonymousNamespace())
567 else if (
auto *RD = dyn_cast<CXXRecordDecl>(DC))
569 RD->getTypeForDecl());
570 else if (isa<TranslationUnitDecl>(DC))
573 llvm_unreachable(
"something isn't in TU scope?");
584 if (
const auto *MD = dyn_cast<CXXMethodDecl>(DC))
585 if (MD->getParent()->hasAnyDependentBases())
593 bool IsTemplateTypeArg) {
594 assert(
getLangOpts().MSVCCompat &&
"shouldn't be called in non-MSVC mode");
597 if (IsTemplateTypeArg &&
getCurScope()->isTemplateParamScope()) {
606 Diag(NameLoc, diag::ext_ms_delayed_template_argument) << &II;
612 RD->getTypeForDecl());
616 Diag(NameLoc, diag::ext_undeclared_unqual_id_with_dependent_base) << &II
647 switch (TD->getTagKind()) {
675 return S->isFunctionPrototypeScope();
685 bool IsTemplateName) {
690 SuggestedType =
nullptr;
694 TypeNameValidatorCCC CCC(
false,
false,
701 bool CanRecover = !IsTemplateName;
702 if (Corrected.isKeyword()) {
705 PDiag(IsTemplateName ? diag::err_no_template_suggest
706 : diag::err_unknown_typename_suggest)
708 II = Corrected.getCorrectionAsIdentifierInfo();
711 if (!SS || !SS->
isSet()) {
713 PDiag(IsTemplateName ? diag::err_no_template_suggest
714 : diag::err_unknown_typename_suggest)
717 std::string CorrectedStr(Corrected.getAsString(
getLangOpts()));
718 bool DroppedSpecifier =
719 Corrected.WillReplaceSpecifier() && II->
getName() == CorrectedStr;
722 ? diag::err_no_member_template_suggest
723 : diag::err_unknown_nested_typename_suggest)
724 << II << DC << DroppedSpecifier << SS->
getRange(),
727 llvm_unreachable(
"could not have corrected a typo here");
734 if (Corrected.getCorrectionSpecifier())
739 getTypeName(*Corrected.getCorrectionAsIdentifierInfo(), IILoc, S,
740 tmpSS.
isSet() ? &tmpSS : SS,
false,
false,
nullptr,
750 Name.setIdentifier(II, IILoc);
753 bool MemberOfUnknownSpecialization;
755 Name,
nullptr,
true, TemplateResult,
766 Diag(IILoc, IsTemplateName ? diag::err_no_template
767 : diag::err_unknown_typename)
770 Diag(IILoc, IsTemplateName ? diag::err_no_member_template
771 : diag::err_typename_nested_not_found)
777 unsigned DiagID = diag::err_typename_missing;
779 DiagID = diag::ext_typename_missing;
786 *SS, *II, IILoc).
get();
789 "Invalid scope specifier has already been diagnosed");
797 NextToken.
is(tok::less);
800 if (isa<TypeDecl>(*I) || isa<ObjCInterfaceDecl>(*I))
803 if (CheckTemplate && isa<TemplateDecl>(*I))
817 StringRef FixItTagName;
818 switch (Tag->getTagKind()) {
820 FixItTagName =
"class ";
824 FixItTagName =
"enum ";
828 FixItTagName =
"struct ";
832 FixItTagName =
"__interface ";
836 FixItTagName =
"union ";
840 StringRef TagName = FixItTagName.drop_back();
841 SemaRef.
Diag(NameLoc, diag::err_use_of_tag_name_without_tag)
842 << Name << TagName << SemaRef.
getLangOpts().CPlusPlus
847 SemaRef.
Diag((*I)->getLocation(), diag::note_decl_hiding_tag_type)
862 const Token &NextToken,
867 assert(NextToken.
isNot(tok::coloncolon) &&
868 "parse nested name specifiers before calling ClassifyName");
909 bool SecondTry =
false;
910 bool IsFilteredTemplateName =
false;
913 switch (
Result.getResultKind()) {
917 if (SS.
isEmpty() && NextToken.
is(tok::l_paren)) {
963 if (!SecondTry && CCC) {
968 unsigned UnqualifiedDiag = diag::err_undeclared_var_use_suggest;
969 unsigned QualifiedDiag = diag::err_no_member_suggest;
972 NamedDecl *UnderlyingFirstDecl = Corrected.getCorrectionDecl();
974 UnderlyingFirstDecl && isa<TemplateDecl>(UnderlyingFirstDecl)) {
975 UnqualifiedDiag = diag::err_no_template_suggest;
976 QualifiedDiag = diag::err_no_member_template_suggest;
977 }
else if (UnderlyingFirstDecl &&
978 (isa<TypeDecl>(UnderlyingFirstDecl) ||
979 isa<ObjCInterfaceDecl>(UnderlyingFirstDecl) ||
980 isa<ObjCCompatibleAliasDecl>(UnderlyingFirstDecl))) {
981 UnqualifiedDiag = diag::err_unknown_typename_suggest;
982 QualifiedDiag = diag::err_unknown_nested_typename_suggest;
988 std::string CorrectedStr(Corrected.getAsString(
getLangOpts()));
989 bool DroppedSpecifier = Corrected.WillReplaceSpecifier() &&
990 Name->getName() == CorrectedStr;
993 << DroppedSpecifier << SS.
getRange());
997 Name = Corrected.getCorrectionAsIdentifierInfo();
1000 if (Corrected.isKeyword())
1006 Result.setLookupName(Corrected.getCorrection());
1028 Result.suppressDiagnostics();
1070 if (!
Result.isAmbiguous()) {
1071 IsFilteredTemplateName =
true;
1081 (IsFilteredTemplateName ||
1097 if (!IsFilteredTemplateName)
1100 bool IsFunctionTemplate;
1104 IsFunctionTemplate =
true;
1107 }
else if (!
Result.empty()) {
1111 IsFunctionTemplate = isa<FunctionTemplateDecl>(TD);
1112 IsVarTemplate = isa<VarTemplateDecl>(TD);
1115 dyn_cast<UsingShadowDecl>(*
Result.begin());
1116 assert(!FoundUsingShadow ||
1117 TD == cast<TemplateDecl>(FoundUsingShadow->
getTargetDecl()));
1125 IsFunctionTemplate =
true;
1129 if (IsFunctionTemplate) {
1133 Result.suppressDiagnostics();
1144 if (
const auto *USD = dyn_cast<UsingShadowDecl>(
Found))
1160 dyn_cast<ObjCCompatibleAliasDecl>(
FirstDecl))
1161 Class = Alias->getClassInterface();
1167 if (NextToken.
is(tok::period)) {
1170 Result.suppressDiagnostics();
1180 if (
auto *USD = dyn_cast<UsingShadowDecl>(
Result.getRepresentativeDecl()))
1186 if (
auto *EmptyD = dyn_cast<UnresolvedUsingIfExistsDecl>(
FirstDecl)) {
1199 bool NextIsOp = NextToken.
isOneOf(tok::amp, tok::star);
1200 if ((NextToken.
is(tok::identifier) ||
1202 FirstDecl->getUnderlyingDecl()->isFunctionOrFunctionTemplate())) &&
1214 if (
Result.isSingleResult() && !ADL &&
1219 Result.suppressDiagnostics();
1239 bool IsAddressOfOperand) {
1242 NameInfo, IsAddressOfOperand,
1249 const Token &NextToken) {
1251 if (
auto *Ivar = dyn_cast<ObjCIvarDecl>(
Found->getUnderlyingDecl()))
1266 auto *ULE = cast<UnresolvedLookupExpr>(
E);
1267 if ((*ULE->decls_begin())->isCXXClassMember()) {
1269 SS.
Adopt(ULE->getQualifierLoc());
1274 Result.setNamingClass(ULE->getNamingClass());
1275 for (
auto I = ULE->decls_begin(),
E = ULE->decls_end(); I !=
E; ++I)
1276 Result.addDecl(*I, I.getAccess());
1289 auto *TD = Name.getAsTemplateDecl();
1292 if (isa<ClassTemplateDecl>(TD))
1294 if (isa<FunctionTemplateDecl>(TD))
1296 if (isa<VarTemplateDecl>(TD))
1298 if (isa<TypeAliasTemplateDecl>(TD))
1300 if (isa<TemplateTemplateParmDecl>(TD))
1302 if (isa<ConceptDecl>(TD))
1309 "The next DeclContext should be lexically contained in the current one.");
1315 assert(
CurContext &&
"DeclContext imbalance!");
1318 assert(
CurContext &&
"Popped translation unit!");
1328 assert(
CurContext &&
"skipping definition of undefined tag");
1356 assert(!S->getEntity() &&
"scope already has entity");
1359 Scope *Ancestor = S->getParent();
1367 if (S->getParent()->isTemplateParamScope()) {
1375 assert(S->getEntity() ==
CurContext &&
"Context imbalance!");
1379 Scope *Ancestor = S->getParent();
1388 assert(S->isTemplateParamScope() &&
1389 "expected to be initializing a template parameter scope");
1413 for (; S && S->isTemplateParamScope(); S = S->getParent(), --ScopeDepth) {
1417 cast<Decl>(DC)->getDescribedTemplateParams()) {
1418 unsigned DCDepth = TPL->getDepth() + 1;
1419 if (DCDepth > ScopeDepth)
1421 if (ScopeDepth == DCDepth)
1426 S->setLookupEntity(SearchDCAfterScope);
1440 "The next DeclContext should be lexically contained in the current one.");
1444 for (
unsigned P = 0, NumParams = FD->
getNumParams();
P < NumParams; ++
P) {
1457 assert(
CurContext &&
"DeclContext imbalance!");
1459 assert(
CurContext &&
"Popped translation unit!");
1488 return ND->
hasAttr<OverloadableAttr>();
1491 return Previous.getFoundDecl()->hasAttr<OverloadableAttr>();
1500 while (S->getEntity() && S->getEntity()->isTransparentContext())
1515 if (isa<FunctionDecl>(
D) &&
1516 cast<FunctionDecl>(
D)->isFunctionTemplateSpecialization())
1519 if (isa<UsingEnumDecl>(
D) &&
D->getDeclName().isEmpty()) {
1526 for (; I != IEnd; ++I) {
1527 if (S->isDeclScope(*I) &&
D->declarationReplaces(*I)) {
1538 if (isa<LabelDecl>(
D) && !cast<LabelDecl>(
D)->isGnuLocal()) {
1545 if (!S->isDeclScope(*I))
1559 bool AllowInlineNamespace)
const {
1567 if (ScopeDC->getPrimaryContext() == TargetDC)
1569 }
while ((S = S->getParent()));
1579 bool ConsiderLinkage,
1580 bool AllowInlineNamespace) {
1638 if (NewIsModuleInterface || OldIsModuleInterface) {
1644 << NewIsModuleInterface
1646 << OldIsModuleInterface
1674 if (!IsNewExported && !IsOldExported)
1689 assert(IsNewExported);
1697 Diag(New->
getLocation(), diag::err_redeclaration_non_exported) << New << S;
1715 "New and Old are not the same definition, we should diagnostic it "
1716 "immediately instead of checking it.");
1719 "We shouldn't see unreachable definitions here.");
1767 return OldM == NewM;
1774 return isa<UsingShadowDecl>(
D) ||
1775 isa<UnresolvedUsingTypenameDecl>(
D) ||
1776 isa<UnresolvedUsingValueDecl>(
D);
1800 if (
D->doesThisDeclarationHaveABody())
1804 return CD->isCopyConstructor();
1805 return D->isCopyAssignmentOperator();
1811 if (
const RecordDecl *RD = dyn_cast<RecordDecl>(DC)){
1812 if (!RD->hasNameForLinkage())
1818 return !
D->isExternallyVisible();
1847 FD->getMemberSpecializationInfo() && !FD->isOutOfLine())
1850 if (
const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(FD)) {
1855 if (FD->isInlined() && !
isMainFileLoc(*
this, FD->getLocation()))
1859 if (FD->doesThisDeclarationHaveABody() &&
1862 }
else if (
const VarDecl *VD = dyn_cast<VarDecl>(
D)) {
1872 if (VD->isStaticDataMember() &&
1875 if (VD->isStaticDataMember() &&
1877 VD->getMemberSpecializationInfo() && !VD->isOutOfLine())
1880 if (VD->isInline() && !
isMainFileLoc(*
this, VD->getLocation()))
1889 return mightHaveNonExternalLinkage(
D);
1902 if (
const VarDecl *VD = dyn_cast<VarDecl>(
D)) {
1917 if (
const auto *DD = dyn_cast<DecompositionDecl>(
D)) {
1921 bool IsAllPlaceholders =
true;
1922 for (
const auto *BD : DD->bindings()) {
1923 if (BD->isReferenced() || BD->hasAttr<UnusedAttr>())
1925 IsAllPlaceholders = IsAllPlaceholders && BD->isPlaceholderVar(LangOpts);
1927 if (IsAllPlaceholders)
1929 }
else if (!
D->getDeclName()) {
1935 if (
D->isPlaceholderVar(LangOpts))
1942 if (isa<LabelDecl>(
D))
1951 WithinFunction || (R->isLocalClass() && !R->isDependentType());
1952 if (!WithinFunction)
1955 if (isa<TypedefNameDecl>(
D))
1959 if (!isa<VarDecl>(
D) || isa<ParmVarDecl>(
D) || isa<ImplicitParamDecl>(
D))
1963 if (
const VarDecl *VD = dyn_cast<VarDecl>(
D)) {
1966 if (
const auto *Cleanups = dyn_cast_if_present<ExprWithCleanups>(
Init))
1967 Init = Cleanups->getSubExpr();
1969 const auto *Ty = VD->getType().getTypePtr();
1974 if (TT->getDecl()->hasAttr<UnusedAttr>())
1980 if (
const auto *MTE = dyn_cast_if_present<MaterializeTemporaryExpr>(
Init);
1981 MTE && MTE->getExtendingDecl()) {
1982 Ty = VD->getType().getNonReferenceType().getTypePtr();
1983 Init = MTE->getSubExpr()->IgnoreImplicitAsWritten();
1988 if (Ty->isIncompleteType() || Ty->isDependentType())
1993 Ty = Ty->getBaseElementTypeUnsafe();
1996 const TagDecl *Tag = TT->getDecl();
1997 if (Tag->hasAttr<UnusedAttr>())
2000 if (
const auto *RD = dyn_cast<CXXRecordDecl>(Tag)) {
2001 if (!RD->hasTrivialDestructor() && !RD->hasAttr<WarnUnusedAttr>())
2005 const auto *Construct =
2006 dyn_cast<CXXConstructExpr>(
Init->IgnoreImpCasts());
2007 if (Construct && !Construct->isElidable()) {
2009 if (!CD->
isTrivial() && !RD->hasAttr<WarnUnusedAttr>() &&
2010 (VD->getInit()->isValueDependent() || !VD->evaluateValue()))
2016 if (
Init->isTypeDependent()) {
2018 if (!Ctor->isTrivial())
2024 if (isa<CXXUnresolvedConstructExpr>(
Init))
2038 if (isa<LabelDecl>(
D)) {
2056 if (
D->getTypeForDecl()->isDependentType())
2059 for (
auto *TmpD :
D->decls()) {
2060 if (
const auto *
T = dyn_cast<TypedefNameDecl>(TmpD))
2062 else if(
const auto *R = dyn_cast<RecordDecl>(TmpD))
2076 if (
auto *TD = dyn_cast<TypedefNameDecl>(
D)) {
2087 if (isa<VarDecl>(
D) && cast<VarDecl>(
D)->isExceptionVariable())
2088 DiagID = diag::warn_unused_exception_param;
2089 else if (isa<LabelDecl>(
D))
2090 DiagID = diag::warn_unused_label;
2092 DiagID = diag::warn_unused_variable;
2111 if (Ty->isReferenceType() || Ty->isDependentType())
2115 const TagDecl *Tag = TT->getDecl();
2116 if (Tag->hasAttr<UnusedAttr>())
2120 if (
const auto *RD = dyn_cast<CXXRecordDecl>(Tag);
2121 RD && !RD->hasAttr<WarnUnusedAttr>())
2128 if (VD->
hasAttr<BlocksAttr>() && Ty->isObjCObjectPointerType())
2134 if (VD->
hasAttr<ObjCPreciseLifetimeAttr>() && Ty->isObjCObjectPointerType())
2141 assert(iter->getSecond() >= 0 &&
2142 "Found a negative number of references to a VarDecl");
2143 if (
int RefCnt = iter->getSecond(); RefCnt > 0) {
2153 bool UnusedCXXCondDecl = VD->
isCXXCondDecl() && (RefCnt == 1);
2154 if (!UnusedCXXCondDecl)
2158 unsigned DiagID = isa<ParmVarDecl>(VD) ? diag::warn_unused_but_set_parameter
2159 : diag::warn_unused_but_set_variable;
2169 bool Diagnose =
false;
2173 Diagnose = L->
getStmt() ==
nullptr;
2182 if (S->decl_empty())
return;
2184 "Scope shouldn't contain decls!");
2191 std::optional<SourceLocation> PreviousDeclLoc;
2196 DeclDiags.push_back(LocAndDiag{
Loc, std::nullopt, std::move(PD)});
2201 DeclDiags.push_back(LocAndDiag{
Loc, PreviousDeclLoc, std::move(PD)});
2204 for (
auto *TmpD : S->decls()) {
2205 assert(TmpD &&
"This decl didn't get pushed??");
2207 assert(isa<NamedDecl>(TmpD) &&
"Decl isn't NamedDecl?");
2211 if (!S->hasUnrecoverableErrorOccurred()) {
2213 if (
const auto *RD = dyn_cast<RecordDecl>(
D))
2215 if (
VarDecl *VD = dyn_cast<VarDecl>(
D)) {
2221 if (!
D->getDeclName())
continue;
2235 auto ShadowI = ShadowingDecls.find(
D);
2236 if (ShadowI != ShadowingDecls.end()) {
2237 if (
const auto *FD = dyn_cast<FieldDecl>(ShadowI->second)) {
2239 PDiag(diag::warn_ctor_parm_shadows_field)
2240 <<
D << FD << FD->getParent());
2242 ShadowingDecls.erase(ShadowI);
2246 llvm::sort(DeclDiags,
2247 [](
const LocAndDiag &LHS,
const LocAndDiag &RHS) ->
bool {
2252 return LHS.Loc.getRawEncoding() < RHS.Loc.getRawEncoding();
2254 for (
const LocAndDiag &
D : DeclDiags) {
2256 if (
D.PreviousDeclLoc)
2257 Diag(*
D.PreviousDeclLoc, diag::note_previous_declaration);
2263 (S->getEntity() && S->getEntity()->isTransparentContext()) ||
2281 return "ucontext.h";
2283 llvm_unreachable(
"unhandled error kind");
2294 Parent->addDecl(CLinkageDecl);
2301 "consteval builtins should only be available in C++20 mode");
2316 for (
unsigned i = 0, e = FT->getNumParams(); i != e; ++i) {
2319 FT->getParamType(i),
nullptr,
SC_None,
nullptr);
2321 Params.push_back(parm);
2323 New->setParams(Params);
2331 Scope *S,
bool ForRedeclaration,
2338 if (!ForRedeclaration)
2350 Diag(
Loc, diag::warn_implicit_decl_no_jmp_buf)
2357 Diag(
Loc, diag::warn_implicit_decl_requires_sysheader)
2363 if (!ForRedeclaration &&
2367 : diag::ext_implicit_lib_function_decl)
2370 Diag(
Loc, diag::note_include_header_or_declare)
2407 while (Filter.hasNext()) {
2416 if (
auto *OldTD = dyn_cast<TypedefNameDecl>(Old)) {
2418 Decl->getUnderlyingType()))
2423 if (OldTD->getAnonDeclWithTypedefName(
true) &&
2424 Decl->getAnonDeclWithTypedefName())
2436 if (
const TypedefNameDecl *OldTypedef = dyn_cast<TypedefNameDecl>(Old))
2437 OldType = OldTypedef->getUnderlyingType();
2444 int Kind = isa<TypeAliasDecl>(Old) ? 1 : 0;
2445 Diag(New->
getLocation(), diag::err_redefinition_variably_modified_typedef)
2453 if (OldType != NewType &&
2457 int Kind = isa<TypeAliasDecl>(Old) ? 1 : 0;
2459 << Kind << NewType << OldType;
2478 switch (TypeID->getLength()) {
2482 if (!TypeID->isStr(
"id"))
2498 if (!TypeID->isStr(
"Class"))
2505 if (!TypeID->isStr(
"SEL"))
2532 if (
auto *OldTD = dyn_cast<TypedefNameDecl>(Old)) {
2533 auto *OldTag = OldTD->getAnonDeclWithTypedefName(
true);
2536 if (OldTag && NewTag &&
2537 OldTag->getCanonicalDecl() != NewTag->getCanonicalDecl() &&
2542 if (OldTD->isModed())
2544 OldTD->getUnderlyingType());
2553 if (isa<EnumDecl>(NewTag)) {
2555 for (
auto *
D : NewTag->decls()) {
2556 auto *ED = cast<EnumConstantDecl>(
D);
2560 ED->getLexicalDeclContext()->removeDecl(ED);
2610 if (!isa<TypedefNameDecl>(Old))
2642 const OwnershipAttr *OA = dyn_cast<OwnershipAttr>(A);
2643 const AnnotateAttr *Ann = dyn_cast<AnnotateAttr>(A);
2644 for (
const auto *i :
D->
attrs())
2645 if (i->getKind() == A->
getKind()) {
2647 if (Ann->getAnnotation() == cast<AnnotateAttr>(i)->getAnnotation())
2652 if (OA && isa<OwnershipAttr>(i))
2653 return OA->getOwnKind() == cast<OwnershipAttr>(i)->getOwnKind();
2661 if (
VarDecl *VD = dyn_cast<VarDecl>(
D))
2662 return VD->isThisDeclarationADefinition();
2663 if (
TagDecl *TD = dyn_cast<TagDecl>(
D))
2664 return TD->isCompleteDefinition() || TD->isBeingDefined();
2675 AlignedAttr *OldAlignasAttr =
nullptr;
2676 AlignedAttr *OldStrictestAlignAttr =
nullptr;
2677 unsigned OldAlign = 0;
2685 if (I->isAlignmentDependent())
2691 unsigned Align = I->getAlignment(S.
Context);
2692 if (Align > OldAlign) {
2694 OldStrictestAlignAttr = I;
2699 AlignedAttr *NewAlignasAttr =
nullptr;
2700 unsigned NewAlign = 0;
2702 if (I->isAlignmentDependent())
2708 unsigned Align = I->getAlignment(S.
Context);
2709 if (Align > NewAlign)
2713 if (OldAlignasAttr && NewAlignasAttr && OldAlign != NewAlign) {
2721 if (OldAlign == 0 || NewAlign == 0) {
2723 if (
ValueDecl *VD = dyn_cast<ValueDecl>(New))
2734 if (OldAlign != NewAlign) {
2735 S.
Diag(NewAlignasAttr->getLocation(), diag::err_alignas_mismatch)
2738 S.
Diag(OldAlignasAttr->getLocation(), diag::note_previous_declaration);
2753 S.
Diag(OldAlignasAttr->getLocation(), diag::note_alignas_on_declaration)
2757 bool AnyAdded =
false;
2760 if (OldAlign > NewAlign) {
2761 AlignedAttr *Clone = OldStrictestAlignAttr->clone(S.
Context);
2762 Clone->setInherited(
true);
2768 if (OldAlignasAttr && !NewAlignasAttr &&
2769 !(AnyAdded && OldStrictestAlignAttr->isAlignas())) {
2770 AlignedAttr *Clone = OldAlignasAttr->clone(S.
Context);
2771 Clone->setInherited(
true);
2779#define WANT_DECL_MERGE_LOGIC
2780#include "clang/Sema/AttrParsedAttrImpl.inc"
2781#undef WANT_DECL_MERGE_LOGIC
2788 if (!DiagnoseMutualExclusions(S,
D,
Attr))
2799 if (
const auto *AA = dyn_cast<AvailabilityAttr>(
Attr))
2801 D, *AA, AA->getPlatform(), AA->
isImplicit(), AA->getIntroduced(),
2802 AA->getDeprecated(), AA->getObsoleted(), AA->getUnavailable(),
2803 AA->getMessage(), AA->getStrict(), AA->getReplacement(), AMK,
2804 AA->getPriority(), AA->getEnvironment());
2805 else if (
const auto *VA = dyn_cast<VisibilityAttr>(
Attr))
2807 else if (
const auto *VA = dyn_cast<TypeVisibilityAttr>(
Attr))
2809 else if (
const auto *ImportA = dyn_cast<DLLImportAttr>(
Attr))
2811 else if (
const auto *ExportA = dyn_cast<DLLExportAttr>(
Attr))
2813 else if (
const auto *EA = dyn_cast<ErrorAttr>(
Attr))
2815 else if (
const auto *FA = dyn_cast<FormatAttr>(
Attr))
2818 else if (
const auto *SA = dyn_cast<SectionAttr>(
Attr))
2820 else if (
const auto *CSA = dyn_cast<CodeSegAttr>(
Attr))
2822 else if (
const auto *IA = dyn_cast<MSInheritanceAttr>(
Attr))
2824 IA->getInheritanceModel());
2825 else if (
const auto *AA = dyn_cast<AlwaysInlineAttr>(
Attr))
2828 else if (S.
getLangOpts().CUDA && isa<FunctionDecl>(
D) &&
2829 (isa<CUDAHostAttr>(
Attr) || isa<CUDADeviceAttr>(
Attr) ||
2830 isa<CUDAGlobalAttr>(
Attr))) {
2834 }
else if (
const auto *MA = dyn_cast<MinSizeAttr>(
Attr))
2836 else if (
const auto *SNA = dyn_cast<SwiftNameAttr>(
Attr))
2838 else if (
const auto *OA = dyn_cast<OptimizeNoneAttr>(
Attr))
2840 else if (
const auto *InternalLinkageA = dyn_cast<InternalLinkageAttr>(
Attr))
2842 else if (isa<AlignedAttr>(
Attr))
2846 else if ((isa<DeprecatedAttr>(
Attr) || isa<UnavailableAttr>(
Attr)) &&
2851 else if (
const auto *UA = dyn_cast<UuidAttr>(
Attr))
2852 NewAttr = S.
mergeUuidAttr(
D, *UA, UA->getGuid(), UA->getGuidDecl());
2853 else if (
const auto *IMA = dyn_cast<WebAssemblyImportModuleAttr>(
Attr))
2855 else if (
const auto *INA = dyn_cast<WebAssemblyImportNameAttr>(
Attr))
2857 else if (
const auto *TCBA = dyn_cast<EnforceTCBAttr>(
Attr))
2859 else if (
const auto *TCBLA = dyn_cast<EnforceTCBLeafAttr>(
Attr))
2861 else if (
const auto *BTFA = dyn_cast<BTFDeclTagAttr>(
Attr))
2863 else if (
const auto *NT = dyn_cast<HLSLNumThreadsAttr>(
Attr))
2866 else if (
const auto *SA = dyn_cast<HLSLShaderAttr>(
Attr))
2868 else if (isa<SuppressAttr>(
Attr))
2877 if (isa<MSInheritanceAttr>(NewAttr))
2886 if (
const TagDecl *TD = dyn_cast<TagDecl>(
D))
2887 return TD->getDefinition();
2888 if (
const VarDecl *VD = dyn_cast<VarDecl>(
D)) {
2896 if (FD->isDefined(Def,
true))
2903 for (
const auto *Attribute :
D->
attrs())
2904 if (Attribute->getKind() == Kind)
2916 if (!Def || Def == New)
2920 for (
unsigned I = 0,
E = NewAttributes.size(); I !=
E;) {
2921 const Attr *NewAttribute = NewAttributes[I];
2923 if (isa<AliasAttr>(NewAttribute) || isa<IFuncAttr>(NewAttribute)) {
2930 NewAttributes.erase(NewAttributes.begin() + I);
2935 VarDecl *VD = cast<VarDecl>(New);
2936 unsigned Diag = cast<VarDecl>(Def)->isThisDeclarationADefinition() ==
2938 ? diag::err_alias_after_tentative
2939 : diag::err_redefinition;
2941 if (
Diag == diag::err_redefinition)
2951 if (
const VarDecl *VD = dyn_cast<VarDecl>(Def)) {
2964 if (isa<C11NoReturnAttr>(NewAttribute)) {
2968 }
else if (isa<UuidAttr>(NewAttribute)) {
2972 }
else if (
const AlignedAttr *AA = dyn_cast<AlignedAttr>(NewAttribute)) {
2973 if (AA->isAlignas()) {
2984 S.
Diag(NewAttribute->
getLocation(), diag::note_alignas_on_declaration)
2986 NewAttributes.erase(NewAttributes.begin() + I);
2990 }
else if (isa<LoaderUninitializedAttr>(NewAttribute)) {
2996 diag::err_loader_uninitialized_redeclaration);
2998 NewAttributes.erase(NewAttributes.begin() + I);
3002 }
else if (isa<SelectAnyAttr>(NewAttribute) &&
3003 cast<VarDecl>(New)->isInline() &&
3004 !cast<VarDecl>(New)->isInlineSpecified()) {
3011 }
else if (isa<OMPDeclareVariantAttr>(NewAttribute)) {
3019 diag::warn_attribute_precede_definition);
3021 NewAttributes.erase(NewAttributes.begin() + I);
3027 const ConstInitAttr *CIAttr,
3028 bool AttrBeforeInit) {
3035 std::string SuitableSpelling;
3037 SuitableSpelling = std::string(
3039 if (SuitableSpelling.empty() && S.
getLangOpts().CPlusPlus11)
3041 InsertLoc, {tok::l_square, tok::l_square,
3042 S.PP.getIdentifierInfo(
"clang"), tok::coloncolon,
3043 S.PP.getIdentifierInfo(
"require_constant_initialization"),
3044 tok::r_square, tok::r_square}));
3045 if (SuitableSpelling.empty())
3047 InsertLoc, {tok::kw___attribute, tok::l_paren, tok::r_paren,
3048 S.PP.getIdentifierInfo(
"require_constant_initialization"),
3049 tok::r_paren, tok::r_paren}));
3050 if (SuitableSpelling.empty() && S.
getLangOpts().CPlusPlus20)
3051 SuitableSpelling =
"constinit";
3052 if (SuitableSpelling.empty() && S.
getLangOpts().CPlusPlus11)
3053 SuitableSpelling =
"[[clang::require_constant_initialization]]";
3054 if (SuitableSpelling.empty())
3055 SuitableSpelling =
"__attribute__((require_constant_initialization))";
3056 SuitableSpelling +=
" ";
3058 if (AttrBeforeInit) {
3061 assert(CIAttr->isConstinit() &&
"should not diagnose this for attribute");
3064 S.
Diag(CIAttr->getLocation(), diag::note_constinit_specified_here);
3068 S.
Diag(CIAttr->getLocation(),
3069 CIAttr->isConstinit() ? diag::err_constinit_added_too_late
3070 : diag::warn_require_const_init_added_too_late)
3073 << CIAttr->isConstinit()
3081 UsedAttr *NewAttr = OldAttr->clone(
Context);
3082 NewAttr->setInherited(
true);
3086 RetainAttr *NewAttr = OldAttr->clone(
Context);
3087 NewAttr->setInherited(
true);
3097 const auto *OldConstInit = Old->
getAttr<ConstInitAttr>();
3098 const auto *NewConstInit = New->
getAttr<ConstInitAttr>();
3099 if (
bool(OldConstInit) !=
bool(NewConstInit)) {
3100 const auto *OldVD = cast<VarDecl>(Old);
3101 auto *NewVD = cast<VarDecl>(New);
3107 (NewVD->hasInit() || NewVD->isThisDeclarationADefinition()))
3110 if (InitDecl == NewVD) {
3114 if (OldConstInit && OldConstInit->isConstinit())
3117 }
else if (NewConstInit) {
3121 if (InitDecl && InitDecl != NewVD) {
3124 NewVD->dropAttr<ConstInitAttr>();
3132 if (AsmLabelAttr *NewA = New->
getAttr<AsmLabelAttr>()) {
3133 if (AsmLabelAttr *OldA = Old->
getAttr<AsmLabelAttr>()) {
3134 if (!OldA->isEquivalent(NewA)) {
3137 Diag(OldA->getLocation(), diag::note_previous_declaration);
3139 }
else if (Old->
isUsed()) {
3143 << isa<FunctionDecl>(Old) << New->
getAttr<AsmLabelAttr>()->
getRange();
3148 if (
const auto *NewAbiTagAttr = New->
getAttr<AbiTagAttr>()) {
3149 if (
const auto *OldAbiTagAttr = Old->
getAttr<AbiTagAttr>()) {
3150 for (
const auto &NewTag : NewAbiTagAttr->tags()) {
3151 if (!llvm::is_contained(OldAbiTagAttr->tags(), NewTag)) {
3152 Diag(NewAbiTagAttr->getLocation(),
3153 diag::err_new_abi_tag_on_redeclaration)
3155 Diag(OldAbiTagAttr->getLocation(), diag::note_previous_declaration);
3159 Diag(NewAbiTagAttr->getLocation(), diag::err_abi_tag_on_redeclaration);
3165 if (New->
hasAttr<SectionAttr>() && !Old->
hasAttr<SectionAttr>()) {
3166 if (
auto *VD = dyn_cast<VarDecl>(New)) {
3168 Diag(New->
getLocation(), diag::warn_attribute_section_on_redeclaration);
3175 const auto *NewCSA = New->
getAttr<CodeSegAttr>();
3176 if (NewCSA && !Old->
hasAttr<CodeSegAttr>() &&
3177 !NewCSA->isImplicit() && isa<CXXMethodDecl>(New)) {
3195 if (isa<DeprecatedAttr>(I) ||
3196 isa<UnavailableAttr>(I) ||
3197 isa<AvailabilityAttr>(I)) {
3212 if (isa<UsedAttr>(I) || isa<RetainAttr>(I))
3234 const CarriesDependencyAttr *CDA = newDecl->
getAttr<CarriesDependencyAttr>();
3235 if (CDA && !oldDecl->
hasAttr<CarriesDependencyAttr>()) {
3236 S.
Diag(CDA->getLocation(),
3237 diag::err_carries_dependency_missing_on_first_decl) << 1;
3245 diag::note_carries_dependency_missing_first_decl) << 1;
3253 const auto *NDAttr = newDecl->
getAttr<HLSLParamModifierAttr>();
3254 const auto *ODAttr = oldDecl->
getAttr<HLSLParamModifierAttr>();
3259 if (NDAttr && ODAttr &&
3260 NDAttr->getSpellingListIndex() != ODAttr->getSpellingListIndex()) {
3261 S.
Diag(newDecl->
getLocation(), diag::err_hlsl_param_qualifier_mismatch)
3262 << NDAttr << newDecl;
3271 bool foundAny = newDecl->
hasAttrs();
3280 cast<InheritableParamAttr>(I->clone(S.
Context));
3293 auto NoSizeInfo = [&Ctx](
QualType Ty) {
3294 if (Ty->isIncompleteArrayType() || Ty->isPointerType())
3302 if (NoSizeInfo(Old) && NoSizeInfo(New))
3334 if (*Oldnullability != *Newnullability) {
3335 S.
Diag(NewParam->
getLocation(), diag::warn_mismatched_nullability_attr)
3354 const auto *OldParamDT = dyn_cast<DecayedType>(OldParam->
getType());
3355 const auto *NewParamDT = dyn_cast<DecayedType>(NewParam->
getType());
3356 if (OldParamDT && NewParamDT &&
3357 OldParamDT->getPointeeType() == NewParamDT->getPointeeType()) {
3358 QualType OldParamOT = OldParamDT->getOriginalType();
3359 QualType NewParamOT = NewParamDT->getOriginalType();
3362 << NewParam << NewParamOT;
3373struct GNUCompatibleParamWarning {
3383template <
typename T>
3384static std::pair<diag::kind, SourceLocation>
3388 if (Old->isThisDeclarationADefinition())
3389 PrevDiag = diag::note_previous_definition;
3390 else if (Old->isImplicit()) {
3391 PrevDiag = diag::note_previous_implicit_declaration;
3392 if (
const auto *FD = dyn_cast<FunctionDecl>(Old)) {
3393 if (FD->getBuiltinID())
3394 PrevDiag = diag::note_previous_builtin_declaration;
3397 OldLocation = New->getLocation();
3399 PrevDiag = diag::note_previous_declaration;
3400 return std::make_pair(PrevDiag, OldLocation);
3408 return ((FD->
hasAttr<GNUInlineAttr>() || LangOpts.GNUInline) &&
3409 !LangOpts.CPlusPlus &&
3421template <
typename T>
3442template<
typename ExpectedDecl>
3464 !Old->getDeclContext()->getRedeclContext()->Equals(
3465 New->getDeclContext()->getRedeclContext()) &&
3470 S.
Diag(New->getLocation(), diag::err_using_decl_conflict_reverse);
3483 const auto *AttrA = A->
getAttr<PassObjectSizeAttr>();
3484 const auto *AttrB = B->
getAttr<PassObjectSizeAttr>();
3487 return AttrA && AttrB && AttrA->getType() == AttrB->getType() &&
3488 AttrA->isDynamic() == AttrB->isDynamic();
3514 if (NamedDC->Equals(SemaDC))
3517 assert((NamedDC->InEnclosingNamespaceSetOf(SemaDC) ||
3519 "unexpected context for redeclaration");
3530 if (
auto *FD = dyn_cast<FunctionDecl>(NewD))
3531 FixSemaDC(FD->getDescribedFunctionTemplate());
3532 else if (
auto *VD = dyn_cast<VarDecl>(NewD))
3533 FixSemaDC(VD->getDescribedVarTemplate());
3537 bool MergeTypeWithOld,
bool NewDeclIsDefn) {
3544 Diag(Shadow->getTargetDecl()->getLocation(),
3545 diag::note_using_decl_target);
3546 Diag(Shadow->getIntroducer()->getLocation(), diag::note_using_decl)
3555 if (checkUsingShadowRedecl<FunctionTemplateDecl>(*
this, Shadow,
3558 OldD = Old = cast<FunctionTemplateDecl>(Shadow->getTargetDecl())
3561 if (checkUsingShadowRedecl<FunctionDecl>(*
this, Shadow, New))
3563 OldD = Old = cast<FunctionDecl>(Shadow->getTargetDecl());
3591 std::tie(PrevDiag, OldLocation) =
3598 if (!isa<CXXMethodDecl>(New) && !isa<CXXMethodDecl>(Old) &&
3605 Diag(OldLocation, PrevDiag) << Old << Old->
getType();
3608 Diag(OldLocation, PrevDiag) << Old << Old->
getType();
3613 if (
const auto *ILA = New->
getAttr<InternalLinkageAttr>())
3614 if (!Old->
hasAttr<InternalLinkageAttr>()) {
3618 New->
dropAttr<InternalLinkageAttr>();
3621 if (
auto *EA = New->
getAttr<ErrorAttr>()) {
3622 if (!Old->
hasAttr<ErrorAttr>()) {
3623 Diag(EA->getLocation(), diag::err_attribute_missing_on_first_decl) << EA;
3633 bool OldOvl = Old->
hasAttr<OverloadableAttr>();
3644 const Decl *DiagOld = Old;
3646 auto OldIter = llvm::find_if(Old->
redecls(), [](
const Decl *
D) {
3647 const auto *A = D->getAttr<OverloadableAttr>();
3648 return A && !A->isImplicit();
3652 DiagOld = OldIter == Old->
redecls_end() ? nullptr : *OldIter;
3657 diag::note_attribute_overloadable_prev_overload)
3672 Diag(OldLocation, diag::note_previous_declaration);
3691 const FunctionType *OldType = cast<FunctionType>(OldQType);
3692 const FunctionType *NewType = cast<FunctionType>(NewQType);
3695 bool RequiresAdjustment =
false;
3697 if (OldTypeInfo.
getCC() != NewTypeInfo.
getCC()) {
3703 if (!NewCCExplicit) {
3707 RequiresAdjustment =
true;
3719 RequiresAdjustment =
true;
3726 << (!FirstCCExplicit ?
"" :
3730 Diag(
First->getLocation(), diag::note_previous_declaration);
3738 RequiresAdjustment =
true;
3748 Diag(OldLocation, diag::note_previous_declaration);
3753 RequiresAdjustment =
true;
3760 <<
"'ns_returns_retained'";
3761 Diag(OldLocation, diag::note_previous_declaration);
3766 RequiresAdjustment =
true;
3772 AnyX86NoCallerSavedRegistersAttr *
Attr =
3773 New->
getAttr<AnyX86NoCallerSavedRegistersAttr>();
3775 Diag(OldLocation, diag::note_previous_declaration);
3780 RequiresAdjustment =
true;
3783 if (RequiresAdjustment) {
3793 !New->
hasAttr<GNUInlineAttr>() &&
3802 if (New->
hasAttr<GNUInlineAttr>() &&
3813 Diag(OldLocation, PrevDiag) << Old << Old->
getType();
3817 QualType OldQTypeForComparison = OldQType;
3821 if (OldFX != NewFX) {
3823 for (
const auto &Diff : Diffs) {
3824 if (Diff.shouldDiagnoseRedeclaration(*Old, OldFX, *New, NewFX)) {
3826 diag::warn_mismatched_func_effect_redeclaration)
3827 << Diff.effectName();
3838 if (!MergeErrs.empty())
3845 NewFPT->getParamTypes(), EPI);
3853 EPI = OldFPT->getExtProtoInfo();
3856 OldFPT->getReturnType(), OldFPT->getParamTypes(), EPI);
3875 OldDeclaredReturnType)) {
3883 Diag(New->
getLocation(), diag::err_member_def_does_not_match_ret_type)
3888 Diag(OldLocation, PrevDiag) << Old << Old->
getType()
3897 QualType NewReturnType = cast<FunctionType>(NewQType)->getReturnType();
3898 if (OldReturnType != NewReturnType) {
3914 const CXXMethodDecl *OldMethod = dyn_cast<CXXMethodDecl>(Old);
3916 if (OldMethod && NewMethod) {
3923 bool IsClassScopeExplicitSpecialization =
3929 !IsClassScopeExplicitSpecialization) {
3935 Diag(OldLocation, PrevDiag) << Old << Old->
getType();
3945 if (isa<CXXConstructorDecl>(OldMethod))
3946 NewDiag = diag::err_constructor_redeclared;
3947 else if (isa<CXXDestructorDecl>(NewMethod))
3948 NewDiag = diag::err_destructor_redeclared;
3949 else if (isa<CXXConversionDecl>(NewMethod))
3950 NewDiag = diag::err_conv_function_redeclared;
3952 NewDiag = diag::err_member_redeclared;
3956 Diag(New->
getLocation(), diag::err_member_redeclared_in_instantiation)
3959 Diag(OldLocation, PrevDiag) << Old << Old->
getType();
3972 diag::err_definition_of_implicitly_declared_member)
3978 diag::err_definition_of_explicitly_defaulted_member)
4001 if (
const auto *NRA = New->
getAttr<CXX11NoReturnAttr>())
4002 if (!Old->
hasAttr<CXX11NoReturnAttr>()) {
4003 Diag(NRA->getLocation(), diag::err_attribute_missing_on_first_decl)
4012 const CarriesDependencyAttr *CDA = New->
getAttr<CarriesDependencyAttr>();
4013 if (CDA && !Old->
hasAttr<CarriesDependencyAttr>()) {
4014 Diag(CDA->getLocation(),
4015 diag::err_carries_dependency_missing_on_first_decl) << 0;
4017 diag::note_carries_dependency_missing_first_decl) << 0;
4030 OldQTypeForComparison =
QualType(OldTypeForComparison, 0);
4045 Diag(OldLocation, PrevDiag);
4047 Diag(New->
getLocation(), diag::err_different_language_linkage) << New;
4048 Diag(OldLocation, PrevDiag);
4119 bool IsWithoutProtoADef =
false, IsWithProtoADef =
false;
4120 if (WithoutProto == New)
4121 IsWithoutProtoADef = NewDeclIsDefn;
4123 IsWithProtoADef = NewDeclIsDefn;
4125 diag::warn_non_prototype_changes_behavior)
4126 << IsWithoutProtoADef << (WithoutProto->
getNumParams() ? 0 : 1)
4127 << (WithoutProto == Old) << IsWithProtoADef;
4137 !IsWithoutProtoADef)
4147 if (MergeTypeWithOld && isa<FunctionNoProtoType>(NewFuncType) &&
4148 (OldProto = dyn_cast<FunctionProtoType>(OldFuncType))) {
4151 assert(!OldProto->hasExceptionSpec() &&
"Exception spec in C");
4153 OldProto->getParamTypes(),
4154 OldProto->getExtProtoInfo());
4160 for (
const auto &ParamType : OldProto->param_types()) {
4163 ParamType,
nullptr,
SC_None,
nullptr);
4166 Params.push_back(Param);
4169 New->setParams(Params);
4205 NewProto->getReturnType());
4206 bool LooseCompatible = !MergedReturn.
isNull();
4208 LooseCompatible && Idx != End; ++Idx) {
4212 NewProto->getParamType(Idx))) {
4213 ArgTypes.push_back(NewParm->
getType());
4217 GNUCompatibleParamWarning Warn = { OldParm, NewParm,
4218 NewProto->getParamType(Idx) };
4219 Warnings.push_back(Warn);
4220 ArgTypes.push_back(NewParm->
getType());
4222 LooseCompatible =
false;
4225 if (LooseCompatible) {
4226 for (
unsigned Warn = 0; Warn < Warnings.size(); ++Warn) {
4227 Diag(Warnings[Warn].NewParm->getLocation(),
4228 diag::ext_param_promoted_not_compatible_with_prototype)
4229 << Warnings[Warn].PromotedType
4230 << Warnings[Warn].OldParm->getType();
4231 if (Warnings[Warn].OldParm->getLocation().isValid())
4232 Diag(Warnings[Warn].OldParm->getLocation(),
4233 diag::note_previous_declaration);
4236 if (MergeTypeWithOld)
4256 Diag(OldLocation, diag::note_previous_builtin_declaration)
4261 PrevDiag = diag::note_previous_builtin_declaration;
4265 Diag(OldLocation, PrevDiag) << Old << Old->
getType();
4270 Scope *S,
bool MergeTypeWithOld) {
4285 for (
unsigned i = 0, e = New->
getNumParams(); i != e; ++i) {
4299 if (!Merged.isNull() && MergeTypeWithOld)
4322 ni != ne && oi != oe; ++ni, ++oi)
4332 ? diag::err_redefinition_different_type
4333 : diag::err_redeclaration_different_type)
4338 std::tie(PrevDiag, OldLocation)
4340 S.
Diag(OldLocation, PrevDiag) << Old << Old->
getType();
4345 bool MergeTypeWithOld) {
4373 QualType PrevVDTy = PrevVD->getType();
4427 if (MergeTypeWithOld)
4465 if (!shouldLinkPossiblyHiddenDecl(
Previous, New))
4475 OldTemplate = dyn_cast<VarTemplateDecl>(
Previous.getFoundDecl());
4479 dyn_cast<UsingShadowDecl>(
Previous.getRepresentativeDecl()))
4480 if (checkUsingShadowRedecl<VarTemplateDecl>(*
this, Shadow, NewTemplate))
4483 Old = dyn_cast<VarDecl>(
Previous.getFoundDecl());
4486 dyn_cast<UsingShadowDecl>(
Previous.getRepresentativeDecl()))
4487 if (checkUsingShadowRedecl<VarDecl>(*
this, Shadow, New))
4524 if (New->
hasAttr<WeakImportAttr>())
4535 if (
const auto *ILA = New->
getAttr<InternalLinkageAttr>())
4536 if (!Old->
hasAttr<InternalLinkageAttr>()) {
4540 New->
dropAttr<InternalLinkageAttr>();
4545 if (MostRecent != Old) {
4558 std::tie(PrevDiag, OldLocation) =
4568 Diag(OldLocation, PrevDiag);
4572 Diag(OldLocation, PrevDiag);
4591 Diag(OldLocation, PrevDiag);
4599 Diag(OldLocation, PrevDiag);
4605 Diag(OldLocation, PrevDiag);
4621 Diag(OldLocation, PrevDiag);
4631 Diag(Def->getLocation(), diag::note_previous_definition);
4645 Diag(OldLocation, PrevDiag);
4648 Diag(OldLocation, PrevDiag);
4656 Diag(OldLocation, PrevDiag);
4666 diag::warn_deprecated_redundant_constexpr_static_def);
4675 Diag(New->
getLocation(), diag::err_different_language_linkage) << New;
4676 Diag(OldLocation, PrevDiag);
4706 StringRef HdrFilename =
4709 auto noteFromModuleOrInclude = [&](
Module *Mod,
4715 if (IncLoc.isValid()) {
4717 Diag(IncLoc, diag::note_redefinition_modules_same_file)
4723 Diag(IncLoc, diag::note_redefinition_include_same_file)
4724 << HdrFilename.str();
4734 if (FNew == FOld && FNewDecLoc.second == FOldDecLoc.second) {
4742 if (FOld && !HSI.isFileMultipleIncludeGuarded(*FOld))
4757 isa<VarTemplateSpecializationDecl>(New) ||
4793 ? S->getMSCurManglingNumber()
4794 : S->getMSLastManglingNumber();
4801 if (isa<CXXRecordDecl>(Tag->getParent())) {
4804 if (!Tag->getName().empty() || Tag->getTypedefNameForAnonDecl())