50#include "llvm/ADT/SmallString.h"
51#include "llvm/ADT/StringExtras.h"
52#include "llvm/TargetParser/Triple.h"
57#include <unordered_map>
64 Decl *Group[2] = { OwnedType, Ptr };
75 TypeNameValidatorCCC(
bool AllowInvalid,
bool WantClass =
false,
76 bool AllowTemplates =
false,
77 bool AllowNonTemplates =
true)
78 : AllowInvalidDecl(AllowInvalid), WantClassName(WantClass),
79 AllowTemplates(AllowTemplates), AllowNonTemplates(AllowNonTemplates) {
80 WantExpressionKeywords =
false;
81 WantCXXNamedCasts =
false;
82 WantRemainingKeywords =
false;
87 if (!AllowInvalidDecl && ND->isInvalidDecl())
91 return AllowTemplates;
93 bool IsType = isa<TypeDecl>(ND) || isa<ObjCInterfaceDecl>(ND);
97 if (AllowNonTemplates)
102 if (AllowTemplates) {
103 auto *RD = dyn_cast<CXXRecordDecl>(ND);
104 if (!RD || !RD->isInjectedClassName())
106 RD = cast<CXXRecordDecl>(RD->getDeclContext());
107 return RD->getDescribedClassTemplate() ||
108 isa<ClassTemplateSpecializationDecl>(RD);
114 return !WantClassName && candidate.
isKeyword();
117 std::unique_ptr<CorrectionCandidateCallback> clone()
override {
118 return std::make_unique<TypeNameValidatorCCC>(*
this);
122 bool AllowInvalidDecl;
125 bool AllowNonTemplates;
137 case tok::kw___int64:
138 case tok::kw___int128:
140 case tok::kw_unsigned:
148 case tok::kw__Float16:
149 case tok::kw___float128:
150 case tok::kw___ibm128:
151 case tok::kw_wchar_t:
156#define TRANSFORM_TYPE_TRAIT_DEF(_, Trait) case tok::kw___##Trait:
157#include "clang/Basic/TransformTypeTraits.def"
158 case tok::kw___auto_type:
161 case tok::annot_typename:
162 case tok::kw_char16_t:
163 case tok::kw_char32_t:
165 case tok::annot_decltype:
166 case tok::kw_decltype:
169 case tok::kw_char8_t:
180enum class UnqualifiedTypeNameLookupResult {
191static UnqualifiedTypeNameLookupResult
196 return UnqualifiedTypeNameLookupResult::NotFound;
198 UnqualifiedTypeNameLookupResult FoundTypeDecl =
199 UnqualifiedTypeNameLookupResult::NotFound;
202 if (
auto *BaseTT =
Base.getType()->getAs<
TagType>())
203 BaseRD = BaseTT->getAsCXXRecordDecl();
207 if (!TST || !TST->isDependentType())
209 auto *TD = TST->getTemplateName().getAsTemplateDecl();
212 if (
auto *BasePrimaryTemplate =
213 dyn_cast_or_null<CXXRecordDecl>(TD->getTemplatedDecl())) {
215 BaseRD = BasePrimaryTemplate;
216 else if (
auto *CTD = dyn_cast<ClassTemplateDecl>(TD)) {
218 CTD->findPartialSpecialization(
Base.getType()))
226 if (!isa<TypeDecl>(ND))
227 return UnqualifiedTypeNameLookupResult::FoundNonType;
228 FoundTypeDecl = UnqualifiedTypeNameLookupResult::FoundType;
230 if (FoundTypeDecl == UnqualifiedTypeNameLookupResult::NotFound) {
232 case UnqualifiedTypeNameLookupResult::FoundNonType:
233 return UnqualifiedTypeNameLookupResult::FoundNonType;
234 case UnqualifiedTypeNameLookupResult::FoundType:
235 FoundTypeDecl = UnqualifiedTypeNameLookupResult::FoundType;
237 case UnqualifiedTypeNameLookupResult::NotFound:
244 return FoundTypeDecl;
252 UnqualifiedTypeNameLookupResult FoundTypeDecl =
253 UnqualifiedTypeNameLookupResult::NotFound;
255 DC && FoundTypeDecl == UnqualifiedTypeNameLookupResult::NotFound;
259 RD = dyn_cast<CXXRecordDecl>(DC);
263 if (FoundTypeDecl != UnqualifiedTypeNameLookupResult::FoundType)
269 S.
Diag(NameLoc, diag::ext_found_in_dependent_base) << &II;
291 bool WantNontrivialTypeSourceInfo =
true) {
293 case Type::DeducedTemplateSpecialization:
295 case Type::InjectedClassName:
298 case Type::UnresolvedUsing:
303 case Type::ObjCInterface:
304 case Type::ObjCTypeParam:
305 case Type::TemplateTypeParm:
308 llvm_unreachable(
"Unexpected Type Class");
316 if (!WantNontrivialTypeSourceInfo)
320 Builder.pushTypeSpec(T).setNameLoc(NameLoc);
337 bool HasTrailingDot,
ParsedType ObjectTypePtr,
338 bool IsCtorOrDtorName,
339 bool WantNontrivialTypeSourceInfo,
340 bool IsClassTemplateDeductionContext,
344 bool AllowDeducedTemplate = IsClassTemplateDeductionContext &&
346 !isClassName && !HasTrailingDot;
371 !isClassName && !IsCtorOrDtorName)
373 bool IsImplicitTypename = !isClassName && !IsCtorOrDtorName;
374 if (IsImplicitTypename) {
377 Diag(QualifiedLoc, diag::warn_cxx17_compat_implicit_typename);
379 Diag(QualifiedLoc, diag::ext_implicit_typename)
386 if (WantNontrivialTypeSourceInfo)
419 if (ObjectTypePtr &&
Result.empty()) {
443 switch (
Result.getResultKind()) {
447 TypeNameValidatorCCC CCC(
true, isClassName,
448 AllowDeducedTemplate);
453 bool MemberOfUnknownSpecialization;
462 if (Correction && (NNS || NewII != &II) &&
468 Template, MemberOfUnknownSpecialization))) {
470 isClassName, HasTrailingDot, ObjectTypePtr,
472 WantNontrivialTypeSourceInfo,
473 IsClassTemplateDeductionContext);
476 PDiag(diag::err_unknown_type_or_class_name_suggest)
477 <<
Result.getLookupName() << isClassName);
480 *CorrectedII = NewII;
489 Result.suppressDiagnostics();
499 Result.suppressDiagnostics();
505 Res != ResEnd; ++Res) {
507 if (isa<TypeDecl, ObjCInterfaceDecl, UnresolvedUsingIfExistsDecl>(
514 FoundUsingShadow = dyn_cast<UsingShadowDecl>(*Res);
526 Result.suppressDiagnostics();
537 IIDecl =
Result.getFoundDecl();
538 FoundUsingShadow = dyn_cast<UsingShadowDecl>(*
Result.begin());
542 assert(IIDecl &&
"Didn't find decl");
545 if (
TypeDecl *TD = dyn_cast<TypeDecl>(IIDecl)) {
549 auto *LookupRD = dyn_cast_or_null<CXXRecordDecl>(LookupCtx);
550 auto *FoundRD = dyn_cast<CXXRecordDecl>(TD);
551 if (!isClassName && !IsCtorOrDtorName && LookupRD && FoundRD &&
552 FoundRD->isInjectedClassName() &&
554 Diag(NameLoc, diag::err_out_of_line_qualified_id_type_names_constructor)
565 FoundUsingShadow =
nullptr;
566 }
else if (
auto *UD = dyn_cast<UnresolvedUsingIfExistsDecl>(IIDecl)) {
570 }
else if (AllowDeducedTemplate) {
572 assert(!FoundUsingShadow || FoundUsingShadow->
getTargetDecl() == TD);
578 FoundUsingShadow =
nullptr;
584 Result.suppressDiagnostics();
588 if (FoundUsingShadow)
591 return buildNamedType(*
this, SS, T, NameLoc, WantNontrivialTypeSourceInfo);
599 auto *ND = dyn_cast<NamespaceDecl>(DC);
600 if (ND && !ND->isInline() && !ND->isAnonymousNamespace())
602 else if (
auto *RD = dyn_cast<CXXRecordDecl>(DC))
604 RD->getTypeForDecl());
605 else if (isa<TranslationUnitDecl>(DC))
608 llvm_unreachable(
"something isn't in TU scope?");
619 if (
const auto *MD = dyn_cast<CXXMethodDecl>(DC))
620 if (MD->getParent()->hasAnyDependentBases())
628 bool IsTemplateTypeArg) {
629 assert(
getLangOpts().MSVCCompat &&
"shouldn't be called in non-MSVC mode");
632 if (IsTemplateTypeArg &&
getCurScope()->isTemplateParamScope()) {
641 Diag(NameLoc, diag::ext_ms_delayed_template_argument) << &II;
647 RD->getTypeForDecl());
651 Diag(NameLoc, diag::ext_undeclared_unqual_id_with_dependent_base) << &II
687 switch (TD->getTagKind()) {
729 return S->isFunctionPrototypeScope();
739 bool IsTemplateName) {
744 SuggestedType =
nullptr;
748 TypeNameValidatorCCC CCC(
false,
false,
755 bool CanRecover = !IsTemplateName;
756 if (Corrected.isKeyword()) {
759 PDiag(IsTemplateName ? diag::err_no_template_suggest
760 : diag::err_unknown_typename_suggest)
762 II = Corrected.getCorrectionAsIdentifierInfo();
765 if (!SS || !SS->
isSet()) {
767 PDiag(IsTemplateName ? diag::err_no_template_suggest
768 : diag::err_unknown_typename_suggest)
771 std::string CorrectedStr(Corrected.getAsString(
getLangOpts()));
772 bool DroppedSpecifier = Corrected.WillReplaceSpecifier() &&
773 II->
getName().equals(CorrectedStr);
776 ? diag::err_no_member_template_suggest
777 : diag::err_unknown_nested_typename_suggest)
778 << II << DC << DroppedSpecifier << SS->
getRange(),
781 llvm_unreachable(
"could not have corrected a typo here");
788 if (Corrected.getCorrectionSpecifier())
793 getTypeName(*Corrected.getCorrectionAsIdentifierInfo(), IILoc, S,
794 tmpSS.
isSet() ? &tmpSS : SS,
false,
false,
nullptr,
804 Name.setIdentifier(II, IILoc);
807 bool MemberOfUnknownSpecialization;
809 Name,
nullptr,
true, TemplateResult,
820 Diag(IILoc, IsTemplateName ? diag::err_no_template
821 : diag::err_unknown_typename)
824 Diag(IILoc, IsTemplateName ? diag::err_no_member_template
825 : diag::err_typename_nested_not_found)
831 unsigned DiagID = diag::err_typename_missing;
833 DiagID = diag::ext_typename_missing;
840 *SS, *II, IILoc).
get();
843 "Invalid scope specifier has already been diagnosed");
851 NextToken.
is(tok::less);
854 if (isa<TypeDecl>(*I) || isa<ObjCInterfaceDecl>(*I))
857 if (CheckTemplate && isa<TemplateDecl>(*I))
871 StringRef FixItTagName;
872 switch (Tag->getTagKind()) {
874 FixItTagName =
"class ";
878 FixItTagName =
"enum ";
882 FixItTagName =
"struct ";
886 FixItTagName =
"__interface ";
890 FixItTagName =
"union ";
894 StringRef TagName = FixItTagName.drop_back();
895 SemaRef.
Diag(NameLoc, diag::err_use_of_tag_name_without_tag)
896 << Name << TagName << SemaRef.
getLangOpts().CPlusPlus
901 SemaRef.
Diag((*I)->getLocation(), diag::note_decl_hiding_tag_type)
916 const Token &NextToken,
921 assert(NextToken.
isNot(tok::coloncolon) &&
922 "parse nested name specifiers before calling ClassifyName");
962 bool SecondTry =
false;
963 bool IsFilteredTemplateName =
false;
966 switch (
Result.getResultKind()) {
970 if (SS.
isEmpty() && NextToken.
is(tok::l_paren)) {
1016 if (!SecondTry && CCC) {
1021 unsigned UnqualifiedDiag = diag::err_undeclared_var_use_suggest;
1022 unsigned QualifiedDiag = diag::err_no_member_suggest;
1025 NamedDecl *UnderlyingFirstDecl = Corrected.getCorrectionDecl();
1027 UnderlyingFirstDecl && isa<TemplateDecl>(UnderlyingFirstDecl)) {
1028 UnqualifiedDiag = diag::err_no_template_suggest;
1029 QualifiedDiag = diag::err_no_member_template_suggest;
1030 }
else if (UnderlyingFirstDecl &&
1031 (isa<TypeDecl>(UnderlyingFirstDecl) ||
1032 isa<ObjCInterfaceDecl>(UnderlyingFirstDecl) ||
1033 isa<ObjCCompatibleAliasDecl>(UnderlyingFirstDecl))) {
1034 UnqualifiedDiag = diag::err_unknown_typename_suggest;
1035 QualifiedDiag = diag::err_unknown_nested_typename_suggest;
1041 std::string CorrectedStr(Corrected.getAsString(
getLangOpts()));
1042 bool DroppedSpecifier = Corrected.WillReplaceSpecifier() &&
1043 Name->getName().equals(CorrectedStr);
1046 << DroppedSpecifier << SS.
getRange());
1050 Name = Corrected.getCorrectionAsIdentifierInfo();
1053 if (Corrected.isKeyword())
1059 Result.setLookupName(Corrected.getCorrection());
1081 Result.suppressDiagnostics();
1123 if (!
Result.isAmbiguous()) {
1124 IsFilteredTemplateName =
true;
1134 (IsFilteredTemplateName ||
1150 if (!IsFilteredTemplateName)
1153 bool IsFunctionTemplate;
1157 IsFunctionTemplate =
true;
1160 }
else if (!
Result.empty()) {
1164 IsFunctionTemplate = isa<FunctionTemplateDecl>(TD);
1165 IsVarTemplate = isa<VarTemplateDecl>(TD);
1168 dyn_cast<UsingShadowDecl>(*
Result.begin());
1169 assert(!FoundUsingShadow ||
1170 TD == cast<TemplateDecl>(FoundUsingShadow->
getTargetDecl()));
1180 IsFunctionTemplate =
true;
1184 if (IsFunctionTemplate) {
1188 Result.suppressDiagnostics();
1199 if (
const auto *USD = dyn_cast<UsingShadowDecl>(Found))
1215 dyn_cast<ObjCCompatibleAliasDecl>(
FirstDecl))
1216 Class = Alias->getClassInterface();
1222 if (NextToken.
is(tok::period)) {
1225 Result.suppressDiagnostics();
1237 if (
auto *EmptyD = dyn_cast<UnresolvedUsingIfExistsDecl>(
FirstDecl)) {
1250 bool NextIsOp = NextToken.
isOneOf(tok::amp, tok::star);
1251 if ((NextToken.
is(tok::identifier) ||
1253 FirstDecl->getUnderlyingDecl()->isFunctionOrFunctionTemplate())) &&
1265 if (
Result.isSingleResult() && !ADL &&
1270 Result.suppressDiagnostics();
1273 Result.getLookupNameInfo(), ADL,
Result.isOverloadedResult(),
1290 bool IsAddressOfOperand) {
1293 NameInfo, IsAddressOfOperand,
1300 const Token &NextToken) {
1317 auto *ULE = cast<UnresolvedLookupExpr>(E);
1318 if ((*ULE->decls_begin())->isCXXClassMember()) {
1320 SS.
Adopt(ULE->getQualifierLoc());
1325 Result.setNamingClass(ULE->getNamingClass());
1326 for (
auto I = ULE->decls_begin(), E = ULE->decls_end(); I != E; ++I)
1327 Result.addDecl(*I, I.getAccess());
1340 auto *TD = Name.getAsTemplateDecl();
1343 if (isa<ClassTemplateDecl>(TD))
1345 if (isa<FunctionTemplateDecl>(TD))
1347 if (isa<VarTemplateDecl>(TD))
1349 if (isa<TypeAliasTemplateDecl>(TD))
1351 if (isa<TemplateTemplateParmDecl>(TD))
1353 if (isa<ConceptDecl>(TD))
1360 "The next DeclContext should be lexically contained in the current one.");
1366 assert(
CurContext &&
"DeclContext imbalance!");
1369 assert(
CurContext &&
"Popped translation unit!");
1378 CurContext = cast<TagDecl>(D)->getDefinition();
1379 assert(
CurContext &&
"skipping definition of undefined tag");
1410 assert(!S->getEntity() &&
"scope already has entity");
1413 Scope *Ancestor = S->getParent();
1421 if (S->getParent()->isTemplateParamScope()) {
1429 assert(S->getEntity() ==
CurContext &&
"Context imbalance!");
1433 Scope *Ancestor = S->getParent();
1442 assert(S->isTemplateParamScope() &&
1443 "expected to be initializing a template parameter scope");
1467 for (; S && S->isTemplateParamScope(); S = S->getParent(), --ScopeDepth) {
1471 cast<Decl>(DC)->getDescribedTemplateParams()) {
1472 unsigned DCDepth = TPL->getDepth() + 1;
1473 if (DCDepth > ScopeDepth)
1475 if (ScopeDepth == DCDepth)
1480 S->setLookupEntity(SearchDCAfterScope);
1494 "The next DeclContext should be lexically contained in the current one.");
1498 for (
unsigned P = 0, NumParams = FD->
getNumParams();
P < NumParams; ++
P) {
1511 assert(
CurContext &&
"DeclContext imbalance!");
1513 assert(
CurContext &&
"Popped translation unit!");
1542 return ND->
hasAttr<OverloadableAttr>();
1545 return Previous.getFoundDecl()->hasAttr<OverloadableAttr>();
1555 while (S->getEntity() && S->getEntity()->isTransparentContext())
1570 if (isa<FunctionDecl>(D) &&
1571 cast<FunctionDecl>(D)->isFunctionTemplateSpecialization())
1577 for (; I != IEnd; ++I) {
1589 if (isa<LabelDecl>(D) && !cast<LabelDecl>(D)->isGnuLocal()) {
1596 if (!S->isDeclScope(*I))
1610 bool AllowInlineNamespace)
const {
1618 if (ScopeDC->getPrimaryContext() == TargetDC)
1620 }
while ((S = S->getParent()));
1632 bool ConsiderLinkage,
1633 bool AllowInlineNamespace) {
1694 if (NewIsModuleInterface || OldIsModuleInterface) {
1700 << NewIsModuleInterface
1702 << OldIsModuleInterface
1733 if (!IsNewExported && !IsOldExported)
1739 assert(IsNewExported);
1747 Diag(New->
getLocation(), diag::err_redeclaration_non_exported) << New << S;
1783 "New and Old are not the same definition, we should diagnostic it "
1784 "immediately instead of checking it.");
1787 "We shouldn't see unreachable definitions here.");
1835 return OldM == NewM;
1842 return isa<UsingShadowDecl>(D) ||
1843 isa<UnresolvedUsingTypenameDecl>(D) ||
1844 isa<UnresolvedUsingValueDecl>(D);
1872 return CD->isCopyConstructor();
1891 if (
const RecordDecl *RD = dyn_cast<RecordDecl>(DC)){
1892 if (!RD->hasNameForLinkage())
1921 if (
const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
1927 FD->getMemberSpecializationInfo() && !FD->isOutOfLine())
1930 if (
const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(FD)) {
1935 if (FD->isInlined() && !
isMainFileLoc(*
this, FD->getLocation()))
1939 if (FD->doesThisDeclarationHaveABody() &&
1942 }
else if (
const VarDecl *VD = dyn_cast<VarDecl>(D)) {
1952 if (VD->isStaticDataMember() &&
1955 if (VD->isStaticDataMember() &&
1957 VD->getMemberSpecializationInfo() && !VD->isOutOfLine())
1960 if (VD->isInline() && !
isMainFileLoc(*
this, VD->getLocation()))
1969 return mightHaveNonExternalLinkage(D);
1976 if (
const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
1982 if (
const VarDecl *VD = dyn_cast<VarDecl>(D)) {
1997 if (
auto *DD = dyn_cast<DecompositionDecl>(D)) {
2001 bool IsAllPlaceholders =
true;
2002 for (
auto *BD : DD->bindings()) {
2003 if (BD->isReferenced())
2005 IsAllPlaceholders = IsAllPlaceholders && BD->isPlaceholderVar(LangOpts);
2007 if (IsAllPlaceholders)
2018 if (D->
hasAttr<UnusedAttr>() || D->
hasAttr<ObjCPreciseLifetimeAttr>() ||
2022 if (isa<LabelDecl>(D))
2028 if (
const auto *R = dyn_cast<CXXRecordDecl>(D->
getDeclContext()))
2031 WithinFunction || (R->isLocalClass() && !R->isDependentType());
2032 if (!WithinFunction)
2035 if (isa<TypedefNameDecl>(D))
2039 if (!isa<VarDecl>(D) || isa<ParmVarDecl>(D) || isa<ImplicitParamDecl>(D))
2043 if (
const VarDecl *VD = dyn_cast<VarDecl>(D)) {
2046 if (
const auto *Cleanups = dyn_cast_or_null<ExprWithCleanups>(
Init))
2047 Init = Cleanups->getSubExpr();
2049 const auto *Ty = VD->getType().getTypePtr();
2054 if (TT->getDecl()->hasAttr<UnusedAttr>())
2060 if (
const auto *MTE = dyn_cast_or_null<MaterializeTemporaryExpr>(
Init)) {
2061 if (MTE->getExtendingDecl()) {
2062 Ty = VD->getType().getNonReferenceType().getTypePtr();
2063 Init = MTE->getSubExpr()->IgnoreImplicitAsWritten();
2069 if (Ty->isIncompleteType() || Ty->isDependentType())
2074 Ty = Ty->getBaseElementTypeUnsafe();
2077 const TagDecl *Tag = TT->getDecl();
2078 if (Tag->
hasAttr<UnusedAttr>())
2081 if (
const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(Tag)) {
2082 if (!RD->hasTrivialDestructor() && !RD->hasAttr<WarnUnusedAttr>())
2087 dyn_cast<CXXConstructExpr>(
Init);
2090 if (!CD->
isTrivial() && !RD->hasAttr<WarnUnusedAttr>() &&
2091 (VD->getInit()->isValueDependent() || !VD->evaluateValue()))
2097 if (
Init->isTypeDependent()) {
2099 if (!Ctor->isTrivial())
2105 if (isa<CXXUnresolvedConstructExpr>(
Init))
2119 if (isa<LabelDecl>(D)) {
2140 for (
auto *TmpD : D->
decls()) {
2141 if (
const auto *T = dyn_cast<TypedefNameDecl>(TmpD))
2143 else if(
const auto *R = dyn_cast<RecordDecl>(TmpD))
2159 if (
auto *TD = dyn_cast<TypedefNameDecl>(D)) {
2170 if (isa<VarDecl>(D) && cast<VarDecl>(D)->isExceptionVariable())
2171 DiagID = diag::warn_unused_exception_param;
2172 else if (isa<LabelDecl>(D))
2173 DiagID = diag::warn_unused_label;
2175 DiagID = diag::warn_unused_variable;
2194 if (Ty->isReferenceType() || Ty->isDependentType())
2198 const TagDecl *Tag = TT->getDecl();
2199 if (Tag->
hasAttr<UnusedAttr>())
2203 if (
const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(Tag)) {
2204 if (!RD->hasAttr<WarnUnusedAttr>())
2212 if (VD->
hasAttr<BlocksAttr>() && Ty->isObjCObjectPointerType())
2218 if (VD->
hasAttr<ObjCPreciseLifetimeAttr>() && Ty->isObjCObjectPointerType())
2225 assert(iter->getSecond() >= 0 &&
2226 "Found a negative number of references to a VarDecl");
2227 if (iter->getSecond() != 0)
2229 unsigned DiagID = isa<ParmVarDecl>(VD) ? diag::warn_unused_but_set_parameter
2230 : diag::warn_unused_but_set_variable;
2240 bool Diagnose =
false;
2244 Diagnose = L->
getStmt() ==
nullptr;
2253 if (S->decl_empty())
return;
2255 "Scope shouldn't contain decls!");
2262 std::optional<SourceLocation> PreviousDeclLoc;
2267 DeclDiags.push_back(LocAndDiag{Loc, std::nullopt, std::move(PD)});
2272 DeclDiags.push_back(LocAndDiag{Loc, PreviousDeclLoc, std::move(PD)});
2275 for (
auto *TmpD : S->decls()) {
2276 assert(TmpD &&
"This decl didn't get pushed??");
2278 assert(isa<NamedDecl>(TmpD) &&
"Decl isn't NamedDecl?");
2282 if (!S->hasUnrecoverableErrorOccurred()) {
2284 if (
const auto *RD = dyn_cast<RecordDecl>(D))
2286 if (
VarDecl *VD = dyn_cast<VarDecl>(D)) {
2295 if (
LabelDecl *LD = dyn_cast<LabelDecl>(D))
2301 auto ShadowI = ShadowingDecls.find(D);
2302 if (ShadowI != ShadowingDecls.end()) {
2303 if (
const auto *FD = dyn_cast<FieldDecl>(ShadowI->second)) {
2304 addDiagWithPrev(D->
getLocation(), FD->getLocation(),
2305 PDiag(diag::warn_ctor_parm_shadows_field)
2306 << D << FD << FD->getParent());
2308 ShadowingDecls.erase(ShadowI);
2312 llvm::sort(DeclDiags,
2313 [](
const LocAndDiag &LHS,
const LocAndDiag &RHS) ->
bool {
2318 return LHS.Loc.getRawEncoding() < RHS.Loc.getRawEncoding();
2320 for (
const LocAndDiag &D : DeclDiags) {
2322 if (D.PreviousDeclLoc)
2323 Diag(*D.PreviousDeclLoc, diag::note_previous_declaration);
2342 bool DoTypoCorrection) {
2347 if (!IDecl && DoTypoCorrection) {
2391 (S->getEntity() && S->getEntity()->isTransparentContext()) ||
2409 return "ucontext.h";
2411 llvm_unreachable(
"unhandled error kind");
2422 Parent->addDecl(CLinkageDecl);
2437 for (
unsigned i = 0, e = FT->getNumParams(); i != e; ++i) {
2440 FT->getParamType(i),
nullptr,
SC_None,
nullptr);
2442 Params.push_back(parm);
2444 New->setParams(Params);
2456 Scope *S,
bool ForRedeclaration,
2463 if (!ForRedeclaration)
2475 Diag(Loc, diag::warn_implicit_decl_no_jmp_buf)
2482 Diag(Loc, diag::warn_implicit_decl_requires_sysheader)
2488 if (!ForRedeclaration &&
2491 Diag(Loc,
LangOpts.C99 ? diag::ext_implicit_lib_function_decl_c99
2492 : diag::ext_implicit_lib_function_decl)
2495 Diag(Loc, diag::note_include_header_or_declare)
2532 while (Filter.hasNext()) {
2541 if (
auto *OldTD = dyn_cast<TypedefNameDecl>(Old)) {
2543 Decl->getUnderlyingType()))
2548 if (OldTD->getAnonDeclWithTypedefName(
true) &&
2549 Decl->getAnonDeclWithTypedefName())
2562 OldType = OldTypedef->getUnderlyingType();
2569 int Kind = isa<TypeAliasDecl>(Old) ? 1 : 0;
2570 Diag(New->
getLocation(), diag::err_redefinition_variably_modified_typedef)
2578 if (OldType != NewType &&
2582 int Kind = isa<TypeAliasDecl>(Old) ? 1 : 0;
2584 << Kind << NewType << OldType;
2608 switch (TypeID->getLength()) {
2612 if (!TypeID->isStr(
"id"))
2628 if (!TypeID->isStr(
"Class"))
2635 if (!TypeID->isStr(
"SEL"))
2662 if (
auto *OldTD = dyn_cast<TypedefNameDecl>(Old)) {
2663 auto *OldTag = OldTD->getAnonDeclWithTypedefName(
true);
2666 if (OldTag && NewTag &&
2667 OldTag->getCanonicalDecl() != NewTag->getCanonicalDecl() &&
2672 if (OldTD->isModed())
2674 OldTD->getUnderlyingType());
2683 if (isa<EnumDecl>(NewTag)) {
2685 for (
auto *D : NewTag->decls()) {
2686 auto *ED = cast<EnumConstantDecl>(D);
2690 ED->getLexicalDeclContext()->removeDecl(ED);
2740 if (!isa<TypedefNameDecl>(Old))
2772 const OwnershipAttr *OA = dyn_cast<OwnershipAttr>(A);
2773 const AnnotateAttr *Ann = dyn_cast<AnnotateAttr>(A);
2774 for (
const auto *i : D->
attrs())
2775 if (i->getKind() == A->
getKind()) {
2777 if (Ann->getAnnotation() == cast<AnnotateAttr>(i)->getAnnotation())
2782 if (OA && isa<OwnershipAttr>(i))
2783 return OA->getOwnKind() == cast<OwnershipAttr>(i)->getOwnKind();
2791 if (
VarDecl *VD = dyn_cast<VarDecl>(D))
2792 return VD->isThisDeclarationADefinition();
2793 if (
TagDecl *TD = dyn_cast<TagDecl>(D))
2794 return TD->isCompleteDefinition() || TD->isBeingDefined();
2805 AlignedAttr *OldAlignasAttr =
nullptr;
2806 AlignedAttr *OldStrictestAlignAttr =
nullptr;
2807 unsigned OldAlign = 0;
2815 if (I->isAlignmentDependent())
2821 unsigned Align = I->getAlignment(S.
Context);
2822 if (Align > OldAlign) {
2824 OldStrictestAlignAttr = I;
2829 AlignedAttr *NewAlignasAttr =
nullptr;
2830 unsigned NewAlign = 0;
2832 if (I->isAlignmentDependent())
2838 unsigned Align = I->getAlignment(S.
Context);
2839 if (Align > NewAlign)
2843 if (OldAlignasAttr && NewAlignasAttr && OldAlign != NewAlign) {
2851 if (OldAlign == 0 || NewAlign == 0) {
2853 if (
ValueDecl *VD = dyn_cast<ValueDecl>(New))
2864 if (OldAlign != NewAlign) {
2865 S.
Diag(NewAlignasAttr->getLocation(), diag::err_alignas_mismatch)
2868 S.
Diag(OldAlignasAttr->getLocation(), diag::note_previous_declaration);
2883 S.
Diag(OldAlignasAttr->getLocation(), diag::note_alignas_on_declaration)
2887 bool AnyAdded =
false;
2890 if (OldAlign > NewAlign) {
2891 AlignedAttr *Clone = OldStrictestAlignAttr->clone(S.
Context);
2892 Clone->setInherited(
true);
2898 if (OldAlignasAttr && !NewAlignasAttr &&
2899 !(AnyAdded && OldStrictestAlignAttr->isAlignas())) {
2900 AlignedAttr *Clone = OldAlignasAttr->clone(S.
Context);
2901 Clone->setInherited(
true);
2909#define WANT_DECL_MERGE_LOGIC
2910#include "clang/Sema/AttrParsedAttrImpl.inc"
2911#undef WANT_DECL_MERGE_LOGIC
2918 if (!DiagnoseMutualExclusions(S, D,
Attr))
2929 if (
const auto *AA = dyn_cast<AvailabilityAttr>(
Attr))
2931 D, *AA, AA->getPlatform(), AA->
isImplicit(), AA->getIntroduced(),
2932 AA->getDeprecated(), AA->getObsoleted(), AA->getUnavailable(),
2933 AA->getMessage(), AA->getStrict(), AA->getReplacement(), AMK,
2935 else if (
const auto *VA = dyn_cast<VisibilityAttr>(
Attr))
2937 else if (
const auto *VA = dyn_cast<TypeVisibilityAttr>(
Attr))
2939 else if (
const auto *ImportA = dyn_cast<DLLImportAttr>(
Attr))
2941 else if (
const auto *ExportA = dyn_cast<DLLExportAttr>(
Attr))
2943 else if (
const auto *EA = dyn_cast<ErrorAttr>(
Attr))
2945 else if (
const auto *FA = dyn_cast<FormatAttr>(
Attr))
2946 NewAttr = S.
mergeFormatAttr(D, *FA, FA->getType(), FA->getFormatIdx(),
2948 else if (
const auto *SA = dyn_cast<SectionAttr>(
Attr))
2950 else if (
const auto *CSA = dyn_cast<CodeSegAttr>(
Attr))
2952 else if (
const auto *IA = dyn_cast<MSInheritanceAttr>(
Attr))
2954 IA->getInheritanceModel());
2955 else if (
const auto *AA = dyn_cast<AlwaysInlineAttr>(
Attr))
2958 else if (S.
getLangOpts().CUDA && isa<FunctionDecl>(D) &&
2959 (isa<CUDAHostAttr>(
Attr) || isa<CUDADeviceAttr>(
Attr) ||
2960 isa<CUDAGlobalAttr>(
Attr))) {
2964 }
else if (
const auto *MA = dyn_cast<MinSizeAttr>(
Attr))
2966 else if (
const auto *SNA = dyn_cast<SwiftNameAttr>(
Attr))
2968 else if (
const auto *OA = dyn_cast<OptimizeNoneAttr>(
Attr))
2970 else if (
const auto *InternalLinkageA = dyn_cast<InternalLinkageAttr>(
Attr))
2972 else if (isa<AlignedAttr>(
Attr))
2976 else if ((isa<DeprecatedAttr>(
Attr) || isa<UnavailableAttr>(
Attr)) &&
2981 else if (
const auto *UA = dyn_cast<UuidAttr>(
Attr))
2982 NewAttr = S.
mergeUuidAttr(D, *UA, UA->getGuid(), UA->getGuidDecl());
2983 else if (
const auto *IMA = dyn_cast<WebAssemblyImportModuleAttr>(
Attr))
2985 else if (
const auto *INA = dyn_cast<WebAssemblyImportNameAttr>(
Attr))
2987 else if (
const auto *TCBA = dyn_cast<EnforceTCBAttr>(
Attr))
2989 else if (
const auto *TCBLA = dyn_cast<EnforceTCBLeafAttr>(
Attr))
2991 else if (
const auto *BTFA = dyn_cast<BTFDeclTagAttr>(
Attr))
2993 else if (
const auto *NT = dyn_cast<HLSLNumThreadsAttr>(
Attr))
2996 else if (
const auto *SA = dyn_cast<HLSLShaderAttr>(
Attr))
3004 if (isa<MSInheritanceAttr>(NewAttr))
3013 if (
const TagDecl *TD = dyn_cast<TagDecl>(D))
3014 return TD->getDefinition();
3015 if (
const VarDecl *VD = dyn_cast<VarDecl>(D)) {
3021 if (
const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
3023 if (FD->isDefined(Def,
true))
3030 for (
const auto *Attribute : D->
attrs())
3031 if (Attribute->getKind() == Kind)
3043 if (!Def || Def == New)
3047 for (
unsigned I = 0, E = NewAttributes.size(); I != E;) {
3048 const Attr *NewAttribute = NewAttributes[I];
3050 if (isa<AliasAttr>(NewAttribute) || isa<IFuncAttr>(NewAttribute)) {
3057 NewAttributes.erase(NewAttributes.begin() + I);
3062 VarDecl *VD = cast<VarDecl>(New);
3063 unsigned Diag = cast<VarDecl>(Def)->isThisDeclarationADefinition() ==
3065 ? diag::err_alias_after_tentative
3066 : diag::err_redefinition;
3068 if (
Diag == diag::err_redefinition)
3078 if (
const VarDecl *VD = dyn_cast<VarDecl>(Def)) {
3091 if (isa<C11NoReturnAttr>(NewAttribute)) {
3095 }
else if (isa<UuidAttr>(NewAttribute)) {
3099 }
else if (
const AlignedAttr *AA = dyn_cast<AlignedAttr>(NewAttribute)) {
3100 if (AA->isAlignas()) {
3111 S.
Diag(NewAttribute->
getLocation(), diag::note_alignas_on_declaration)
3113 NewAttributes.erase(NewAttributes.begin() + I);
3117 }
else if (isa<LoaderUninitializedAttr>(NewAttribute)) {
3123 diag::err_loader_uninitialized_redeclaration);
3125 NewAttributes.erase(NewAttributes.begin() + I);
3129 }
else if (isa<SelectAnyAttr>(NewAttribute) &&
3130 cast<VarDecl>(New)->isInline() &&
3131 !cast<VarDecl>(New)->isInlineSpecified()) {
3138 }
else if (isa<OMPDeclareVariantAttr>(NewAttribute)) {
3146 diag::warn_attribute_precede_definition);
3148 NewAttributes.erase(NewAttributes.begin() + I);
3154 const ConstInitAttr *CIAttr,
3155 bool AttrBeforeInit) {
3162 std::string SuitableSpelling;
3164 SuitableSpelling = std::string(
3166 if (SuitableSpelling.empty() && S.
getLangOpts().CPlusPlus11)
3168 InsertLoc, {tok::l_square, tok::l_square,
3169 S.PP.getIdentifierInfo(
"clang"), tok::coloncolon,
3170 S.PP.getIdentifierInfo(
"require_constant_initialization"),
3171 tok::r_square, tok::r_square}));
3172 if (SuitableSpelling.empty())
3174 InsertLoc, {tok::kw___attribute, tok::l_paren, tok::r_paren,
3175 S.PP.getIdentifierInfo(
"require_constant_initialization"),
3176 tok::r_paren, tok::r_paren}));
3177 if (SuitableSpelling.empty() && S.
getLangOpts().CPlusPlus20)
3178 SuitableSpelling =
"constinit";
3179 if (SuitableSpelling.empty() && S.
getLangOpts().CPlusPlus11)
3180 SuitableSpelling =
"[[clang::require_constant_initialization]]";
3181 if (SuitableSpelling.empty())
3182 SuitableSpelling =
"__attribute__((require_constant_initialization))";
3183 SuitableSpelling +=
" ";
3185 if (AttrBeforeInit) {
3188 assert(CIAttr->isConstinit() &&
"should not diagnose this for attribute");
3191 S.
Diag(CIAttr->getLocation(), diag::note_constinit_specified_here);
3195 S.
Diag(CIAttr->getLocation(),
3196 CIAttr->isConstinit() ? diag::err_constinit_added_too_late
3197 : diag::warn_require_const_init_added_too_late)
3200 << CIAttr->isConstinit()
3209 UsedAttr *NewAttr = OldAttr->clone(
Context);
3210 NewAttr->setInherited(
true);
3214 RetainAttr *NewAttr = OldAttr->clone(
Context);
3215 NewAttr->setInherited(
true);
3225 const auto *OldConstInit = Old->
getAttr<ConstInitAttr>();
3226 const auto *NewConstInit = New->
getAttr<ConstInitAttr>();
3227 if (
bool(OldConstInit) !=
bool(NewConstInit)) {
3228 const auto *OldVD = cast<VarDecl>(Old);
3229 auto *NewVD = cast<VarDecl>(New);
3235 (NewVD->hasInit() || NewVD->isThisDeclarationADefinition()))
3238 if (InitDecl == NewVD) {
3242 if (OldConstInit && OldConstInit->isConstinit())
3245 }
else if (NewConstInit) {
3249 if (InitDecl && InitDecl != NewVD) {
3252 NewVD->dropAttr<ConstInitAttr>();
3260 if (AsmLabelAttr *NewA = New->
getAttr<AsmLabelAttr>()) {
3261 if (AsmLabelAttr *OldA = Old->
getAttr<AsmLabelAttr>()) {
3262 if (!OldA->isEquivalent(NewA)) {
3265 Diag(OldA->getLocation(), diag::note_previous_declaration);
3267 }
else if (Old->
isUsed()) {
3271 << isa<FunctionDecl>(Old) << New->
getAttr<AsmLabelAttr>()->
getRange();
3276 if (
const auto *NewAbiTagAttr = New->
getAttr<AbiTagAttr>()) {
3277 if (
const auto *OldAbiTagAttr = Old->
getAttr<AbiTagAttr>()) {
3278 for (
const auto &NewTag : NewAbiTagAttr->tags()) {
3279 if (!llvm::is_contained(OldAbiTagAttr->tags(), NewTag)) {
3280 Diag(NewAbiTagAttr->getLocation(),
3281 diag::err_new_abi_tag_on_redeclaration)
3283 Diag(OldAbiTagAttr->getLocation(), diag::note_previous_declaration);
3287 Diag(NewAbiTagAttr->getLocation(), diag::err_abi_tag_on_redeclaration);
3293 if (New->
hasAttr<SectionAttr>() && !Old->
hasAttr<SectionAttr>()) {
3294 if (
auto *VD = dyn_cast<VarDecl>(New)) {
3296 Diag(New->
getLocation(), diag::warn_attribute_section_on_redeclaration);
3303 const auto *NewCSA = New->
getAttr<CodeSegAttr>();
3304 if (NewCSA && !Old->
hasAttr<CodeSegAttr>() &&
3305 !NewCSA->isImplicit() && isa<CXXMethodDecl>(New)) {
3323 if (isa<DeprecatedAttr>(I) ||
3324 isa<UnavailableAttr>(I) ||
3325 isa<AvailabilityAttr>(I)) {
3340 if (isa<UsedAttr>(I) || isa<RetainAttr>(I))
3362 const CarriesDependencyAttr *CDA = newDecl->
getAttr<CarriesDependencyAttr>();
3363 if (CDA && !oldDecl->
hasAttr<CarriesDependencyAttr>()) {
3364 S.
Diag(CDA->getLocation(),
3365 diag::err_carries_dependency_missing_on_first_decl) << 1;
3373 diag::note_carries_dependency_missing_first_decl) << 1;
3381 const auto *NDAttr = newDecl->
getAttr<HLSLParamModifierAttr>();
3382 const auto *ODAttr = oldDecl->
getAttr<HLSLParamModifierAttr>();
3387 if (NDAttr && ODAttr &&
3388 NDAttr->getSpellingListIndex() != ODAttr->getSpellingListIndex()) {
3389 S.
Diag(newDecl->
getLocation(), diag::err_hlsl_param_qualifier_mismatch)
3390 << NDAttr << newDecl;
3399 bool foundAny = newDecl->
hasAttrs();
3408 cast<InheritableParamAttr>(I->clone(S.
Context));
3421 auto NoSizeInfo = [&Ctx](
QualType Ty) {
3422 if (Ty->isIncompleteArrayType() || Ty->isPointerType())
3430 if (NoSizeInfo(Old) && NoSizeInfo(New))
3462 if (*Oldnullability != *Newnullability) {
3463 S.
Diag(NewParam->
getLocation(), diag::warn_mismatched_nullability_attr)
3482 const auto *OldParamDT = dyn_cast<DecayedType>(OldParam->
getType());
3483 const auto *NewParamDT = dyn_cast<DecayedType>(NewParam->
getType());
3484 if (OldParamDT && NewParamDT &&
3485 OldParamDT->getPointeeType() == NewParamDT->getPointeeType()) {
3486 QualType OldParamOT = OldParamDT->getOriginalType();
3487 QualType NewParamOT = NewParamDT->getOriginalType();
3490 << NewParam << NewParamOT;
3501struct GNUCompatibleParamWarning {
3511template <
typename T>
3512static std::pair<diag::kind, SourceLocation>
3516 if (Old->isThisDeclarationADefinition())
3517 PrevDiag = diag::note_previous_definition;
3518 else if (Old->isImplicit()) {
3519 PrevDiag = diag::note_previous_implicit_declaration;
3520 if (
const auto *FD = dyn_cast<FunctionDecl>(Old)) {
3521 if (FD->getBuiltinID())
3522 PrevDiag = diag::note_previous_builtin_declaration;
3525 OldLocation = New->getLocation();
3527 PrevDiag = diag::note_previous_declaration;
3528 return std::make_pair(PrevDiag, OldLocation);
3536 return ((FD->
hasAttr<GNUInlineAttr>() || LangOpts.GNUInline) &&
3537 !LangOpts.CPlusPlus &&
3549template <
typename T>
3563template<
typename T>
static bool isExternC(T *D) {
return D->isExternC(); }
3570template<
typename ExpectedDecl>
3592 !Old->getDeclContext()->getRedeclContext()->Equals(
3593 New->getDeclContext()->getRedeclContext()) &&
3598 S.
Diag(New->getLocation(), diag::err_using_decl_conflict_reverse);
3611 const auto *AttrA = A->
getAttr<PassObjectSizeAttr>();
3612 const auto *AttrB = B->
getAttr<PassObjectSizeAttr>();
3615 return AttrA && AttrB && AttrA->getType() == AttrB->getType() &&
3616 AttrA->isDynamic() == AttrB->isDynamic();
3642 if (NamedDC->Equals(SemaDC))
3645 assert((NamedDC->InEnclosingNamespaceSetOf(SemaDC) ||
3647 "unexpected context for redeclaration");
3658 if (
auto *FD = dyn_cast<FunctionDecl>(NewD))
3659 FixSemaDC(FD->getDescribedFunctionTemplate());
3660 else if (
auto *VD = dyn_cast<VarDecl>(NewD))
3661 FixSemaDC(VD->getDescribedVarTemplate());
3676 bool MergeTypeWithOld,
bool NewDeclIsDefn) {
3683 Diag(Shadow->getTargetDecl()->getLocation(),
3684 diag::note_using_decl_target);
3685 Diag(Shadow->getIntroducer()->getLocation(), diag::note_using_decl)
3694 if (checkUsingShadowRedecl<FunctionTemplateDecl>(*
this, Shadow,
3697 OldD = Old = cast<FunctionTemplateDecl>(Shadow->getTargetDecl())
3700 if (checkUsingShadowRedecl<FunctionDecl>(*
this, Shadow, New))
3702 OldD = Old = cast<FunctionDecl>(Shadow->getTargetDecl());
3730 std::tie(PrevDiag, OldLocation) =
3737 if (!isa<CXXMethodDecl>(New) && !isa<CXXMethodDecl>(Old) &&
3744 Diag(OldLocation, PrevDiag) << Old << Old->
getType();
3747 Diag(OldLocation, PrevDiag) << Old << Old->
getType();
3752 if (
const auto *ILA = New->
getAttr<InternalLinkageAttr>())
3753 if (!Old->
hasAttr<InternalLinkageAttr>()) {
3757 New->
dropAttr<InternalLinkageAttr>();
3760 if (
auto *EA = New->
getAttr<ErrorAttr>()) {
3761 if (!Old->
hasAttr<ErrorAttr>()) {
3762 Diag(EA->getLocation(), diag::err_attribute_missing_on_first_decl) << EA;
3772 bool OldOvl = Old->
hasAttr<OverloadableAttr>();
3783 const Decl *DiagOld = Old;
3785 auto OldIter = llvm::find_if(Old->
redecls(), [](
const Decl *D) {
3786 const auto *A = D->getAttr<OverloadableAttr>();
3787 return A && !A->isImplicit();
3791 DiagOld = OldIter == Old->
redecls_end() ? nullptr : *OldIter;
3796 diag::note_attribute_overloadable_prev_overload)
3812 Diag(OldLocation, diag::note_previous_declaration);
3831 const FunctionType *OldType = cast<FunctionType>(OldQType);
3832 const FunctionType *NewType = cast<FunctionType>(NewQType);
3835 bool RequiresAdjustment =
false;
3837 if (OldTypeInfo.
getCC() != NewTypeInfo.
getCC()) {
3843 if (!NewCCExplicit) {
3847 RequiresAdjustment =
true;
3859 RequiresAdjustment =
true;
3866 << (!FirstCCExplicit ?
"" :
3870 Diag(
First->getLocation(), diag::note_previous_declaration);
3878 RequiresAdjustment =
true;
3888 Diag(OldLocation, diag::note_previous_declaration);
3893 RequiresAdjustment =
true;
3900 <<
"'ns_returns_retained'";
3901 Diag(OldLocation, diag::note_previous_declaration);
3906 RequiresAdjustment =
true;
3912 AnyX86NoCallerSavedRegistersAttr *
Attr =
3913 New->
getAttr<AnyX86NoCallerSavedRegistersAttr>();
3915 Diag(OldLocation, diag::note_previous_declaration);
3920 RequiresAdjustment =
true;
3923 if (RequiresAdjustment) {
3933 !New->
hasAttr<GNUInlineAttr>() &&
3942 if (New->
hasAttr<GNUInlineAttr>() &&
3953 Diag(OldLocation, PrevDiag) << Old << Old->
getType();
3970 OldDeclaredReturnType)) {
3978 Diag(New->
getLocation(), diag::err_member_def_does_not_match_ret_type)
3983 Diag(OldLocation, PrevDiag) << Old << Old->
getType()
3992 QualType NewReturnType = cast<FunctionType>(NewQType)->getReturnType();
3993 if (OldReturnType != NewReturnType) {
4009 const CXXMethodDecl *OldMethod = dyn_cast<CXXMethodDecl>(Old);
4011 if (OldMethod && NewMethod) {
4018 bool IsClassScopeExplicitSpecialization =
4024 !IsClassScopeExplicitSpecialization) {
4030 Diag(OldLocation, PrevDiag) << Old << Old->
getType();
4040 if (isa<CXXConstructorDecl>(OldMethod))
4041 NewDiag = diag::err_constructor_redeclared;
4042 else if (isa<CXXDestructorDecl>(NewMethod))
4043 NewDiag = diag::err_destructor_redeclared;
4044 else if (isa<CXXConversionDecl>(NewMethod))
4045 NewDiag = diag::err_conv_function_redeclared;
4047 NewDiag = diag::err_member_redeclared;
4051 Diag(New->
getLocation(), diag::err_member_redeclared_in_instantiation)
4054 Diag(OldLocation, PrevDiag) << Old << Old->
getType();
4067 diag::err_definition_of_implicitly_declared_member)
4073 diag::err_definition_of_explicitly_defaulted_member)
4096 if (
const auto *NRA = New->
getAttr<CXX11NoReturnAttr>())
4097 if (!Old->
hasAttr<CXX11NoReturnAttr>()) {
4098 Diag(NRA->getLocation(), diag::err_attribute_missing_on_first_decl)
4107 const CarriesDependencyAttr *CDA = New->
getAttr<CarriesDependencyAttr>();
4108 if (CDA && !Old->
hasAttr<CarriesDependencyAttr>()) {
4109 Diag(CDA->getLocation(),
4110 diag::err_carries_dependency_missing_on_first_decl) << 0;
4112 diag::note_carries_dependency_missing_first_decl) << 0;
4121 QualType OldQTypeForComparison = OldQType;
4126 OldQTypeForComparison =
QualType(OldTypeForComparison, 0);
4141 Diag(OldLocation, PrevDiag);
4143 Diag(New->
getLocation(), diag::err_different_language_linkage) << New;
4144 Diag(OldLocation, PrevDiag);
4215 bool IsWithoutProtoADef =
false, IsWithProtoADef =
false;
4216 if (WithoutProto == New)
4217 IsWithoutProtoADef = NewDeclIsDefn;
4219 IsWithProtoADef = NewDeclIsDefn;
4221 diag::warn_non_prototype_changes_behavior)
4222 << IsWithoutProtoADef << (WithoutProto->
getNumParams() ? 0 : 1)
4223 << (WithoutProto == Old) << IsWithProtoADef;
4233 !IsWithoutProtoADef)
4243 if (MergeTypeWithOld && isa<FunctionNoProtoType>(NewFuncType) &&
4244 (OldProto = dyn_cast<FunctionProtoType>(OldFuncType))) {
4247 assert(!OldProto->hasExceptionSpec() &&
"Exception spec in C");
4249 OldProto->getParamTypes(),
4250 OldProto->getExtProtoInfo());
4256 for (
const auto &ParamType : OldProto->param_types()) {
4259 ParamType,
nullptr,
SC_None,
nullptr);
4262 Params.push_back(Param);
4265 New->setParams(Params);
4301 NewProto->getReturnType());
4302 bool LooseCompatible = !MergedReturn.
isNull();
4304 LooseCompatible && Idx != End; ++Idx) {
4308 NewProto->getParamType(Idx))) {
4309 ArgTypes.push_back(NewParm->
getType());
4313 GNUCompatibleParamWarning Warn = { OldParm, NewParm,
4314 NewProto->getParamType(Idx) };
4315 Warnings.push_back(Warn);
4316 ArgTypes.push_back(NewParm->
getType());
4318 LooseCompatible =
false;
4321 if (LooseCompatible) {
4322 for (
unsigned Warn = 0; Warn < Warnings.size(); ++Warn) {
4323 Diag(Warnings[Warn].NewParm->getLocation(),
4324 diag::ext_param_promoted_not_compatible_with_prototype)
4325 << Warnings[Warn].PromotedType
4326 << Warnings[Warn].OldParm->getType();
4327 if (Warnings[Warn].OldParm->getLocation().isValid())
4328 Diag(Warnings[Warn].OldParm->getLocation(),
4329 diag::note_previous_declaration);
4332 if (MergeTypeWithOld)
4352 Diag(OldLocation, diag::note_previous_builtin_declaration)
4357 PrevDiag = diag::note_previous_builtin_declaration;
4361 Diag(OldLocation, PrevDiag) << Old << Old->
getType();
4375 Scope *S,
bool MergeTypeWithOld) {
4390 for (
unsigned i = 0, e = New->
getNumParams(); i != e; ++i) {
4404 if (!Merged.isNull() && MergeTypeWithOld)
4427 ni != ne && oi != oe; ++ni, ++oi)
4437 ? diag::err_redefinition_different_type
4438 : diag::err_redeclaration_different_type)
4443 std::tie(PrevDiag, OldLocation)
4445 S.
Diag(OldLocation, PrevDiag) << Old << Old->
getType();
4457 bool MergeTypeWithOld) {
4485 QualType PrevVDTy = PrevVD->getType();
4539 if (MergeTypeWithOld)
4585 if (!shouldLinkPossiblyHiddenDecl(
Previous, New))
4595 OldTemplate = dyn_cast<VarTemplateDecl>(
Previous.getFoundDecl());
4599 dyn_cast<UsingShadowDecl>(
Previous.getRepresentativeDecl()))
4600 if (checkUsingShadowRedecl<VarTemplateDecl>(*
this, Shadow, NewTemplate))
4603 Old = dyn_cast<VarDecl>(
Previous.getFoundDecl());
4606 dyn_cast<UsingShadowDecl>(
Previous.getRepresentativeDecl()))
4607 if (checkUsingShadowRedecl<VarDecl>(*
this, Shadow, New))
4644 if (New->
hasAttr<WeakImportAttr>() &&
4646 !Old->
hasAttr<WeakImportAttr>()) {
4653 if (
const auto *ILA = New->
getAttr<InternalLinkageAttr>())
4654 if (!Old->
hasAttr<InternalLinkageAttr>()) {
4658 New->
dropAttr<InternalLinkageAttr>();
4663 if (MostRecent != Old) {
4676 std::tie(PrevDiag, OldLocation) =
4686 Diag(OldLocation, PrevDiag);
4690 Diag(OldLocation, PrevDiag);
4709 Diag(OldLocation, PrevDiag);
4717 Diag(OldLocation, PrevDiag);
4723 Diag(OldLocation, PrevDiag);
4739 Diag(OldLocation, PrevDiag);
4749 Diag(Def->getLocation(), diag::note_previous_definition);
4763 Diag(OldLocation, PrevDiag);
4766 Diag(OldLocation, PrevDiag);
4774 Diag(OldLocation, PrevDiag);
4784 diag::warn_deprecated_redundant_constexpr_static_def);
4793 Diag(New->
getLocation(), diag::err_different_language_linkage) << New;
4794 Diag(OldLocation, PrevDiag);
4824 StringRef HdrFilename =
4827 auto noteFromModuleOrInclude = [&](
Module *Mod,
4833 if (IncLoc.isValid()) {
4835 Diag(IncLoc, diag::note_redefinition_modules_same_file)
4841 Diag(IncLoc, diag::note_redefinition_include_same_file)
4842 << HdrFilename.str();
4852 if (FNew == FOld && FNewDecLoc.second == FOldDecLoc.second) {
4860 if (FOld && !HSI.isFileMultipleIncludeGuarded(*FOld))
4877 isa<VarTemplateSpecializationDecl>(New) ||
4915 ? S->getMSCurManglingNumber()
4916 : S->getMSLastManglingNumber();
4923 if (isa<CXXRecordDecl>(Tag->
getParent())) {
4938 Decl *ManglingContextDecl;
4939 std::tie(MCtx, ManglingContextDecl) =
4949struct NonCLikeKind {
4961 explicit operator bool() {
return Kind !=
None; }
4969 return {NonCLikeKind::Invalid, {}};
4976 return {NonCLikeKind::BaseClass,