45 #include "llvm/ADT/SmallString.h" 46 #include "llvm/ADT/Triple.h" 51 using namespace clang;
56 Decl *Group[2] = { OwnedType, Ptr };
67 TypeNameValidatorCCC(
bool AllowInvalid,
bool WantClass =
false,
68 bool AllowTemplates =
false,
69 bool AllowNonTemplates =
true)
70 : AllowInvalidDecl(AllowInvalid), WantClassName(WantClass),
71 AllowTemplates(AllowTemplates), AllowNonTemplates(AllowNonTemplates) {
72 WantExpressionKeywords =
false;
73 WantCXXNamedCasts =
false;
74 WantRemainingKeywords =
false;
79 if (!AllowInvalidDecl && ND->isInvalidDecl())
83 return AllowTemplates;
85 bool IsType = isa<TypeDecl>(ND) || isa<ObjCInterfaceDecl>(ND);
89 if (AllowNonTemplates)
96 if (!RD || !RD->isInjectedClassName())
98 RD = cast<CXXRecordDecl>(RD->getDeclContext());
100 isa<ClassTemplateSpecializationDecl>(RD);
106 return !WantClassName && candidate.
isKeyword();
109 std::unique_ptr<CorrectionCandidateCallback> clone()
override {
110 return llvm::make_unique<TypeNameValidatorCCC>(*this);
114 bool AllowInvalidDecl;
117 bool AllowNonTemplates;
129 case tok::kw___int64:
130 case tok::kw___int128:
132 case tok::kw_unsigned:
139 case tok::kw__Float16:
140 case tok::kw___float128:
141 case tok::kw_wchar_t:
143 case tok::kw___underlying_type:
144 case tok::kw___auto_type:
147 case tok::annot_typename:
148 case tok::kw_char16_t:
149 case tok::kw_char32_t:
151 case tok::annot_decltype:
152 case tok::kw_decltype:
153 return getLangOpts().CPlusPlus;
155 case tok::kw_char8_t:
156 return getLangOpts().Char8;
182 return UnqualifiedTypeNameLookupResult::NotFound;
185 UnqualifiedTypeNameLookupResult::NotFound;
188 if (
auto *BaseTT =
Base.getType()->getAs<
TagType>())
189 BaseRD = BaseTT->getAsCXXRecordDecl();
193 if (!TST || !TST->isDependentType())
195 auto *TD = TST->getTemplateName().getAsTemplateDecl();
198 if (
auto *BasePrimaryTemplate =
199 dyn_cast_or_null<CXXRecordDecl>(TD->getTemplatedDecl())) {
201 BaseRD = BasePrimaryTemplate;
202 else if (
auto *CTD = dyn_cast<ClassTemplateDecl>(TD)) {
204 CTD->findPartialSpecialization(
Base.getType()))
212 if (!isa<TypeDecl>(ND))
213 return UnqualifiedTypeNameLookupResult::FoundNonType;
214 FoundTypeDecl = UnqualifiedTypeNameLookupResult::FoundType;
216 if (FoundTypeDecl == UnqualifiedTypeNameLookupResult::NotFound) {
218 case UnqualifiedTypeNameLookupResult::FoundNonType:
219 return UnqualifiedTypeNameLookupResult::FoundNonType;
220 case UnqualifiedTypeNameLookupResult::FoundType:
221 FoundTypeDecl = UnqualifiedTypeNameLookupResult::FoundType;
223 case UnqualifiedTypeNameLookupResult::NotFound:
230 return FoundTypeDecl;
239 UnqualifiedTypeNameLookupResult::NotFound;
241 DC && FoundTypeDecl == UnqualifiedTypeNameLookupResult::NotFound;
242 DC = DC->getParent()) {
249 if (FoundTypeDecl != UnqualifiedTypeNameLookupResult::FoundType)
255 S.
Diag(NameLoc, diag::ext_found_via_dependent_bases_lookup) << &II;
283 bool isClassName,
bool HasTrailingDot,
285 bool IsCtorOrDtorName,
286 bool WantNontrivialTypeSourceInfo,
287 bool IsClassTemplateDeductionContext,
290 bool AllowDeducedTemplate = IsClassTemplateDeductionContext &&
291 getLangOpts().CPlusPlus17 && !IsCtorOrDtorName &&
292 !isClassName && !HasTrailingDot;
299 LookupCtx = computeDeclContext(ObjectType);
301 LookupCtx = computeDeclContext(*SS,
false);
304 if (isDependentScopeSpecifier(*SS)) {
314 if (!isClassName && !IsCtorOrDtorName)
319 if (WantNontrivialTypeSourceInfo)
320 return ActOnTypenameType(S,
SourceLocation(), *SS, II, NameLoc).get();
332 RequireCompleteDeclContext(*SS, LookupCtx))
346 LookupQualifiedName(Result, LookupCtx);
348 if (ObjectTypePtr && Result.
empty()) {
355 LookupName(Result, S);
359 LookupName(Result, S);
363 if (Result.
empty() && getLangOpts().MSVCCompat && (!SS || SS->
isEmpty())) {
375 TypeNameValidatorCCC CCC(
true, isClassName,
376 AllowDeducedTemplate);
378 S, SS, CCC, CTK_ErrorRecovery);
381 bool MemberOfUnknownSpecialization;
390 if (Correction && (NNS || NewII != &II) &&
395 isTemplateName(S, *NewSSPtr,
false, TemplateName,
nullptr,
false,
396 Template, MemberOfUnknownSpecialization))) {
398 isClassName, HasTrailingDot, ObjectTypePtr,
400 WantNontrivialTypeSourceInfo,
401 IsClassTemplateDeductionContext);
403 diagnoseTypo(Correction,
404 PDiag(diag::err_unknown_type_or_class_name_suggest)
407 SS->MakeTrivial(Context, NNS,
SourceRange(NameLoc));
408 *CorrectedII = NewII;
433 Res != ResEnd; ++Res) {
434 if (isa<TypeDecl>(*Res) || isa<ObjCInterfaceDecl>(*Res) ||
465 assert(IIDecl &&
"Didn't find decl");
468 if (
TypeDecl *TD = dyn_cast<TypeDecl>(IIDecl)) {
472 auto *LookupRD = dyn_cast_or_null<CXXRecordDecl>(LookupCtx);
474 if (!isClassName && !IsCtorOrDtorName && LookupRD && FoundRD &&
475 FoundRD->isInjectedClassName() &&
477 Diag(NameLoc, diag::err_out_of_line_qualified_id_type_names_constructor)
480 DiagnoseUseOfDecl(IIDecl, NameLoc);
483 MarkAnyDeclReferenced(TD->getLocation(), TD,
false);
485 (void)DiagnoseUseOfDecl(IDecl, NameLoc);
488 }
else if (AllowDeducedTemplate) {
503 if (SS && SS->
isNotEmpty() && !IsCtorOrDtorName &&
504 !isa<ObjCInterfaceDecl>(IIDecl)) {
505 if (WantNontrivialTypeSourceInfo) {
510 T = getElaboratedType(
ETK_None, *SS, T);
516 T = getElaboratedType(
ETK_None, *SS, T);
529 if (ND && !ND->isInline() && !ND->isAnonymousNamespace())
531 else if (
auto *RD = dyn_cast<CXXRecordDecl>(DC))
533 RD->getTypeForDecl());
534 else if (isa<TranslationUnitDecl>(DC))
537 llvm_unreachable(
"something isn't in TU scope?");
548 if (
const auto *MD = dyn_cast<CXXMethodDecl>(DC))
549 if (MD->getParent()->hasAnyDependentBases())
557 bool IsTemplateTypeArg) {
558 assert(getLangOpts().MSVCCompat &&
"shouldn't be called in non-MSVC mode");
561 if (IsTemplateTypeArg && getCurScope()->isTemplateParamScope()) {
570 Diag(NameLoc, diag::ext_ms_delayed_template_argument) << &II;
576 RD->getTypeForDecl());
580 Diag(NameLoc, diag::ext_undeclared_unqual_id_with_dependent_base) << &II
611 LookupName(R, S,
false);
615 switch (TD->getTagKind()) {
642 if (CurContext->isRecord()) {
662 bool IsTemplateName) {
667 SuggestedType =
nullptr;
671 TypeNameValidatorCCC CCC(
false,
false,
676 CCC, CTK_ErrorRecovery)) {
678 bool CanRecover = !IsTemplateName;
679 if (Corrected.isKeyword()) {
681 diagnoseTypo(Corrected,
682 PDiag(IsTemplateName ? diag::err_no_template_suggest
683 : diag::err_unknown_typename_suggest)
685 II = Corrected.getCorrectionAsIdentifierInfo();
688 if (!SS || !SS->
isSet()) {
689 diagnoseTypo(Corrected,
690 PDiag(IsTemplateName ? diag::err_no_template_suggest
691 : diag::err_unknown_typename_suggest)
693 }
else if (
DeclContext *DC = computeDeclContext(*SS,
false)) {
694 std::string CorrectedStr(Corrected.getAsString(getLangOpts()));
695 bool DroppedSpecifier = Corrected.WillReplaceSpecifier() &&
696 II->
getName().equals(CorrectedStr);
697 diagnoseTypo(Corrected,
699 ? diag::err_no_member_template_suggest
700 : diag::err_unknown_nested_typename_suggest)
701 << II << DC << DroppedSpecifier << SS->
getRange(),
704 llvm_unreachable(
"could not have corrected a typo here");
711 if (Corrected.getCorrectionSpecifier())
712 tmpSS.
MakeTrivial(Context, Corrected.getCorrectionSpecifier(),
716 getTypeName(*Corrected.getCorrectionAsIdentifierInfo(), IILoc, S,
717 tmpSS.
isSet() ? &tmpSS : SS,
false,
false,
nullptr,
724 if (getLangOpts().CPlusPlus && !IsTemplateName) {
730 bool MemberOfUnknownSpecialization;
731 if (isTemplateName(S, SS ? *SS : EmptySS,
false,
732 Name,
nullptr,
true, TemplateResult,
734 diagnoseMissingTemplateArguments(TemplateResult.
get(), IILoc);
743 Diag(IILoc, IsTemplateName ? diag::err_no_template
744 : diag::err_unknown_typename)
746 else if (
DeclContext *DC = computeDeclContext(*SS,
false))
747 Diag(IILoc, IsTemplateName ? diag::err_no_member_template
748 : diag::err_typename_nested_not_found)
750 else if (isDependentScopeSpecifier(*SS)) {
751 unsigned DiagID = diag::err_typename_missing;
752 if (getLangOpts().MSVCCompat && isMicrosoftMissingTypename(SS, S))
753 DiagID = diag::ext_typename_missing;
760 *SS, *II, IILoc).
get();
763 "Invalid scope specifier has already been diagnosed");
771 NextToken.
is(tok::less);
774 if (isa<TypeDecl>(*I) || isa<ObjCInterfaceDecl>(*I))
777 if (CheckTemplate && isa<TemplateDecl>(*I))
791 StringRef FixItTagName;
792 switch (Tag->getTagKind()) {
794 FixItTagName =
"class ";
798 FixItTagName =
"enum ";
802 FixItTagName =
"struct ";
806 FixItTagName =
"__interface ";
810 FixItTagName =
"union ";
814 StringRef TagName = FixItTagName.drop_back();
815 SemaRef.
Diag(NameLoc, diag::err_use_of_tag_name_without_tag)
816 << Name << TagName << SemaRef.
getLangOpts().CPlusPlus
821 SemaRef.
Diag((*I)->getLocation(), diag::note_decl_hiding_tag_type)
855 if (NextToken.
is(tok::coloncolon)) {
857 BuildCXXNestedNameSpecifier(S, IdInfo,
false, SS,
nullptr,
false);
859 isCurrentClassName(*Name, S, &SS)) {
867 LookupResult Result(*
this, Name, NameLoc, LookupOrdinaryName);
868 LookupParsedName(Result, S, &SS, !CurMethod);
872 if (Result.
empty() && SS.
isEmpty() && getLangOpts().MSVCCompat) {
883 ExprResult E = LookupInObjCMethod(Result, S, Name,
true);
888 bool SecondTry =
false;
889 bool IsFilteredTemplateName =
false;
896 if (!SS.
isSet() && NextToken.
is(tok::l_paren)) {
899 if (getLangOpts().CPlusPlus)
900 return BuildDeclarationNameExpr(SS, Result,
true);
914 if (
NamedDecl *D = ImplicitlyDefineFunction(NameLoc, *Name, S)) {
917 return BuildDeclarationNameExpr(SS, Result,
false);
928 return NameClassification::UndeclaredTemplate(Template);
934 if (!getLangOpts().
CPlusPlus && !SecondTry &&
941 if (!SecondTry && CCC) {
945 &SS, *CCC, CTK_ErrorRecovery)) {
946 unsigned UnqualifiedDiag = diag::err_undeclared_var_use_suggest;
947 unsigned QualifiedDiag = diag::err_no_member_suggest;
949 NamedDecl *FirstDecl = Corrected.getFoundDecl();
950 NamedDecl *UnderlyingFirstDecl = Corrected.getCorrectionDecl();
951 if (getLangOpts().
CPlusPlus && NextToken.
is(tok::less) &&
952 UnderlyingFirstDecl && isa<TemplateDecl>(UnderlyingFirstDecl)) {
953 UnqualifiedDiag = diag::err_no_template_suggest;
954 QualifiedDiag = diag::err_no_member_template_suggest;
955 }
else if (UnderlyingFirstDecl &&
956 (isa<TypeDecl>(UnderlyingFirstDecl) ||
957 isa<ObjCInterfaceDecl>(UnderlyingFirstDecl) ||
958 isa<ObjCCompatibleAliasDecl>(UnderlyingFirstDecl))) {
959 UnqualifiedDiag = diag::err_unknown_typename_suggest;
960 QualifiedDiag = diag::err_unknown_nested_typename_suggest;
964 diagnoseTypo(Corrected, PDiag(UnqualifiedDiag) << Name);
966 std::string CorrectedStr(Corrected.getAsString(getLangOpts()));
967 bool DroppedSpecifier = Corrected.WillReplaceSpecifier() &&
968 Name->
getName().equals(CorrectedStr);
969 diagnoseTypo(Corrected, PDiag(QualifiedDiag)
970 << Name << computeDeclContext(SS,
false)
971 << DroppedSpecifier << SS.getRange());
975 Name = Corrected.getCorrectionAsIdentifierInfo();
978 if (Corrected.isKeyword())
994 ExprResult E(LookupInObjCMethod(Result, S, Ivar->getIdentifier()));
1022 NameInfo, IsAddressOfOperand,
1032 if (getLangOpts().
CPlusPlus && NextToken.
is(tok::less) &&
1033 hasAnyAcceptableTemplateNames(Result,
true,
1046 FilterAcceptableTemplateNames(Result);
1048 IsFilteredTemplateName =
true;
1057 if (getLangOpts().
CPlusPlus && NextToken.
is(tok::less) &&
1058 (IsFilteredTemplateName ||
1059 hasAnyAcceptableTemplateNames(
1063 getLangOpts().CPlusPlus2a))) {
1074 if (!IsFilteredTemplateName)
1075 FilterAcceptableTemplateNames(Result);
1077 bool IsFunctionTemplate;
1080 if (Result.
end() - Result.
begin() > 1) {
1081 IsFunctionTemplate =
true;
1084 }
else if (!Result.
empty()) {
1085 auto *TD = cast<TemplateDecl>(getAsTemplateNameDecl(
1086 *Result.
begin(),
true,
1088 IsFunctionTemplate = isa<FunctionTemplateDecl>(TD);
1089 IsVarTemplate = isa<VarTemplateDecl>(TD);
1100 IsFunctionTemplate =
true;
1104 if (IsFunctionTemplate) {
1110 return NameClassification::FunctionTemplate(Template);
1113 return IsVarTemplate ? NameClassification::VarTemplate(Template)
1114 : NameClassification::TypeTemplate(Template);
1119 DiagnoseUseOfDecl(
Type, NameLoc);
1120 MarkAnyDeclReferenced(
Type->getLocation(),
Type,
false);
1131 dyn_cast<ObjCCompatibleAliasDecl>(FirstDecl))
1132 Class = Alias->getClassInterface();
1136 DiagnoseUseOfDecl(Class, NameLoc);
1138 if (NextToken.
is(tok::period)) {
1150 if (isa<TemplateDecl>(FirstDecl) && !isa<FunctionTemplateDecl>(FirstDecl) &&
1151 !isa<VarTemplateDecl>(FirstDecl))
1152 return NameClassification::TypeTemplate(
1157 bool NextIsOp = NextToken.
isOneOf(tok::amp, tok::star);
1158 if ((NextToken.
is(tok::identifier) ||
1163 DiagnoseUseOfDecl(Type, NameLoc);
1171 return BuildPossibleImplicitMemberExpr(SS,
SourceLocation(), Result,
1174 bool ADL = UseArgumentDependentLookup(SS, Result, NextToken.
is(tok::l_paren));
1175 return BuildDeclarationNameExpr(SS, Result, ADL);
1182 return TemplateNameKindForDiagnostics::DependentTemplate;
1183 if (isa<ClassTemplateDecl>(TD))
1184 return TemplateNameKindForDiagnostics::ClassTemplate;
1185 if (isa<FunctionTemplateDecl>(TD))
1186 return TemplateNameKindForDiagnostics::FunctionTemplate;
1187 if (isa<VarTemplateDecl>(TD))
1188 return TemplateNameKindForDiagnostics::VarTemplate;
1189 if (isa<TypeAliasTemplateDecl>(TD))
1190 return TemplateNameKindForDiagnostics::AliasTemplate;
1191 if (isa<TemplateTemplateParmDecl>(TD))
1192 return TemplateNameKindForDiagnostics::TemplateTemplateParam;
1193 if (isa<ConceptDecl>(TD))
1194 return TemplateNameKindForDiagnostics::Concept;
1195 return TemplateNameKindForDiagnostics::DependentTemplate;
1220 if (!isa<CXXRecordDecl>(DC))
1238 assert(getContainingDC(DC) == CurContext &&
1239 "The next DeclContext should be lexically contained in the current one.");
1245 assert(CurContext &&
"DeclContext imbalance!");
1247 CurContext = getContainingDC(CurContext);
1248 assert(CurContext &&
"Popped translation unit!");
1258 assert(CurContext &&
"skipping definition of undefined tag");
1261 S->
setEntity(CurContext->getLookupParent());
1266 CurContext =
static_cast<decltype(CurContext)
>(Context);
1289 assert(!S->
getEntity() &&
"scope already has entity");
1293 while (!Ancestor->getEntity()) Ancestor = Ancestor->
getParent();
1294 assert(Ancestor->getEntity() == CurContext &&
"ancestor context mismatch");
1302 assert(S->
getEntity() == CurContext &&
"Context imbalance!");
1307 while (!Ancestor->getEntity()) Ancestor = Ancestor->
getParent();
1324 "The next DeclContext should be lexically contained in the current one.");
1328 for (
unsigned P = 0, NumParams = FD->
getNumParams();
P < NumParams; ++
P) {
1333 IdResolver.AddDecl(Param);
1341 assert(CurContext &&
"DeclContext imbalance!");
1342 CurContext = CurContext->getLexicalParent();
1343 assert(CurContext &&
"Popped translation unit!");
1366 New->
hasAttr<OverloadableAttr>());
1381 CurContext->addDecl(D);
1392 if (isa<FunctionDecl>(D) &&
1393 cast<FunctionDecl>(D)->isFunctionTemplateSpecialization())
1398 IEnd = IdResolver.end();
1399 for (; I != IEnd; ++I) {
1402 IdResolver.RemoveDecl(*I);
1411 if (isa<LabelDecl>(D) && !cast<LabelDecl>(D)->isGnuLocal()) {
1415 for (I = IdResolver.begin(D->
getDeclName()); I != IEnd; ++I) {
1417 if (IDC == CurContext) {
1420 }
else if (IDC->
Encloses(CurContext))
1424 IdResolver.InsertDeclAfter(I, D);
1426 IdResolver.AddDecl(D);
1431 bool AllowInlineNamespace) {
1432 return IdResolver.isDeclInScope(D, Ctx, S, AllowInlineNamespace);
1439 if (ScopeDC->getPrimaryContext() == TargetDC)
1453 bool ConsiderLinkage,
1454 bool AllowInlineNamespace) {
1459 if (isDeclInScope(D, Ctx, S, AllowInlineNamespace))
1481 makeMergedDefinitionVisible(New);
1498 if (NewIsModuleInterface || OldIsModuleInterface) {
1504 << NewIsModuleInterface
1506 << OldIsModuleInterface
1517 return isa<UsingShadowDecl>(D) ||
1518 isa<UnresolvedUsingTypenameDecl>(D) ||
1519 isa<UnresolvedUsingValueDecl>(D);
1546 return CD->isCopyConstructor();
1562 bool Sema::mightHaveNonExternalLinkage(
const DeclaratorDecl *D) {
1565 if (
const RecordDecl *RD = dyn_cast<RecordDecl>(DC)){
1566 if (!RD->hasNameForLinkage())
1595 if (
const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
1601 FD->getMemberSpecializationInfo() && !FD->isOutOfLine())
1604 if (
const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(FD)) {
1609 if (FD->isInlined() && !
isMainFileLoc(*
this, FD->getLocation()))
1613 if (FD->doesThisDeclarationHaveABody() &&
1616 }
else if (
const VarDecl *VD = dyn_cast<VarDecl>(D)) {
1626 if (VD->isStaticDataMember() &&
1629 if (VD->isStaticDataMember() &&
1631 VD->getMemberSpecializationInfo() && !VD->isOutOfLine())
1634 if (VD->isInline() && !
isMainFileLoc(*
this, VD->getLocation()))
1643 return mightHaveNonExternalLinkage(D);
1650 if (
const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
1652 if (FD != First && ShouldWarnIfUnusedFileScopedDecl(First))
1656 if (
const VarDecl *VD = dyn_cast<VarDecl>(D)) {
1658 if (VD != First && ShouldWarnIfUnusedFileScopedDecl(First))
1662 if (ShouldWarnIfUnusedFileScopedDecl(D))
1663 UnusedFileScopedDecls.push_back(D);
1670 bool Referenced =
false;
1671 if (
auto *DD = dyn_cast<DecompositionDecl>(D)) {
1675 for (
auto *BD : DD->bindings()) {
1676 if (BD->isReferenced()) {
1687 if (Referenced || D->
hasAttr<UnusedAttr>() ||
1688 D->
hasAttr<ObjCPreciseLifetimeAttr>())
1691 if (isa<LabelDecl>(D))
1697 if (
const auto *R = dyn_cast<CXXRecordDecl>(D->
getDeclContext()))
1700 WithinFunction || (R->isLocalClass() && !R->isDependentType());
1701 if (!WithinFunction)
1704 if (isa<TypedefNameDecl>(D))
1708 if (!isa<VarDecl>(D) || isa<ParmVarDecl>(D) || isa<ImplicitParamDecl>(D))
1712 if (
const VarDecl *VD = dyn_cast<VarDecl>(D)) {
1715 const auto *Ty = VD->getType().getTypePtr();
1719 if (TT->getDecl()->hasAttr<UnusedAttr>())
1725 if (Ty->isIncompleteType() || Ty->isDependentType())
1730 Ty = Ty->getBaseElementTypeUnsafe();
1733 const TagDecl *Tag = TT->getDecl();
1734 if (Tag->
hasAttr<UnusedAttr>())
1737 if (
const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(Tag)) {
1738 if (!RD->hasTrivialDestructor() && !RD->hasAttr<WarnUnusedAttr>())
1741 if (
const Expr *Init = VD->getInit()) {
1743 dyn_cast<ExprWithCleanups>(Init))
1744 Init = Cleanups->getSubExpr();
1749 if (!CD->
isTrivial() && !RD->hasAttr<WarnUnusedAttr>() &&
1750 (VD->getInit()->isValueDependent() || !VD->evaluateValue()))
1765 if (isa<LabelDecl>(D)) {
1780 for (
auto *TmpD : D->
decls()) {
1781 if (
const auto *T = dyn_cast<TypedefNameDecl>(TmpD))
1782 DiagnoseUnusedDecl(T);
1783 else if(
const auto *R = dyn_cast<RecordDecl>(TmpD))
1784 DiagnoseUnusedNestedTypedefs(R);
1794 if (
auto *TD = dyn_cast<TypedefNameDecl>(D)) {
1797 UnusedLocalTypedefNameCandidates.insert(TD);
1805 if (isa<VarDecl>(D) && cast<VarDecl>(D)->isExceptionVariable())
1806 DiagID = diag::warn_unused_exception_param;
1807 else if (isa<LabelDecl>(D))
1808 DiagID = diag::warn_unused_label;
1810 DiagID = diag::warn_unused_variable;
1820 bool Diagnose =
false;
1824 Diagnose = L->
getStmt() ==
nullptr;
1834 "Scope shouldn't contain decls!");
1836 for (
auto *TmpD : S->
decls()) {
1837 assert(TmpD &&
"This decl didn't get pushed??");
1839 assert(isa<NamedDecl>(TmpD) &&
"Decl isn't NamedDecl?");
1844 DiagnoseUnusedDecl(D);
1845 if (
const auto *RD = dyn_cast<RecordDecl>(D))
1846 DiagnoseUnusedNestedTypedefs(RD);
1852 if (
LabelDecl *LD = dyn_cast<LabelDecl>(D))
1857 IdResolver.RemoveDecl(D);
1858 auto ShadowI = ShadowingDecls.find(D);
1859 if (ShadowI != ShadowingDecls.end()) {
1860 if (
const auto *FD = dyn_cast<FieldDecl>(ShadowI->second)) {
1862 << D << FD << FD->getParent();
1863 Diag(FD->getLocation(), diag::note_previous_declaration);
1865 ShadowingDecls.erase(ShadowI);
1885 bool DoTypoCorrection) {
1888 NamedDecl *IDecl = LookupSingleName(TUScope, Id, IdLoc, LookupOrdinaryName);
1890 if (!IDecl && DoTypoCorrection) {
1896 TUScope,
nullptr, CCC, CTK_ErrorRecovery)) {
1897 diagnoseTypo(C, PDiag(diag::err_undef_interface_suggest) << Id);
1946 if (!II->
isStr(
"objc_msgSendSuper"))
1970 return "ucontext.h";
1972 llvm_unreachable(
"unhandled error kind");
1980 Scope *S,
bool ForRedeclaration,
1987 if (!ForRedeclaration)
1998 Diag(Loc, diag::warn_implicit_decl_no_jmp_buf)
2005 Diag(Loc, diag::warn_implicit_decl_requires_sysheader)
2011 if (!ForRedeclaration &&
2014 Diag(Loc, diag::ext_implicit_lib_function_decl)
2017 !Diags.isIgnored(diag::ext_implicit_lib_function_decl, Loc))
2018 Diag(Loc, diag::note_include_header_or_declare)
2032 Parent->
addDecl(CLinkageDecl);
2033 Parent = CLinkageDecl;
2038 Loc, Loc, II, R,
nullptr,
2048 for (
unsigned i = 0, e = FT->getNumParams();
i != e; ++
i) {
2051 nullptr, FT->getParamType(
i),
nullptr,
2054 Params.push_back(parm);
2056 New->setParams(Params);
2059 AddKnownFunctionAttributes(New);
2060 RegisterLocallyScopedExternCDecl(New, S);
2068 PushOnScopeChains(New, TUScope);
2069 CurContext = SavedContext;
2085 if (Previous.
empty())
2098 if (
auto *OldTD = dyn_cast<TypedefNameDecl>(Old)) {
2105 if (OldTD->getAnonDeclWithTypedefName(
true) &&
2119 OldType = OldTypedef->getUnderlyingType();
2126 int Kind = isa<TypeAliasDecl>(Old) ? 1 : 0;
2127 Diag(New->
getLocation(), diag::err_redefinition_variably_modified_typedef)
2135 if (OldType != NewType &&
2139 int Kind = isa<TypeAliasDecl>(Old) ? 1 : 0;
2141 << Kind << NewType << OldType;
2163 if (getLangOpts().ObjC) {
2169 if (!TypeID->
isStr(
"id"))
2185 if (!TypeID->
isStr(
"Class"))
2192 if (!TypeID->
isStr(
"SEL"))
2219 if (
auto *OldTD = dyn_cast<TypedefNameDecl>(Old)) {
2220 auto *OldTag = OldTD->getAnonDeclWithTypedefName(
true);
2223 if (OldTag && NewTag &&
2224 OldTag->getCanonicalDecl() != NewTag->getCanonicalDecl() &&
2225 !hasVisibleDefinition(OldTag, &Hidden)) {
2229 if (OldTD->isModed())
2231 OldTD->getUnderlyingType());
2236 makeMergedDefinitionVisible(Hidden);
2240 if (isa<EnumDecl>(NewTag)) {
2241 Scope *EnumScope = getNonFieldDeclScope(S);
2242 for (
auto *D : NewTag->decls()) {
2243 auto *ED = cast<EnumConstantDecl>(D);
2246 IdResolver.RemoveDecl(ED);
2247 ED->getLexicalDeclContext()->removeDecl(ED);
2255 if (isIncompatibleTypedef(Old, New))
2262 mergeDeclAttributes(New, Old);
2265 if (getLangOpts().MicrosoftExt)
2273 if (!isa<CXXRecordDecl>(CurContext))
2297 if (!isa<TypedefNameDecl>(Old))
2307 if (getLangOpts().Modules || getLangOpts().
C11)
2314 if (getDiagnostics().getSuppressSystemWarnings() &&
2329 const OwnershipAttr *OA = dyn_cast<OwnershipAttr>(A);
2330 const AnnotateAttr *Ann = dyn_cast<AnnotateAttr>(A);
2331 for (
const auto *
i : D->
attrs())
2332 if (
i->getKind() == A->
getKind()) {
2334 if (Ann->getAnnotation() == cast<AnnotateAttr>(
i)->getAnnotation())
2339 if (OA && isa<OwnershipAttr>(
i))
2340 return OA->getOwnKind() == cast<OwnershipAttr>(
i)->getOwnKind();
2348 if (
VarDecl *VD = dyn_cast<VarDecl>(D))
2349 return VD->isThisDeclarationADefinition();
2350 if (
TagDecl *TD = dyn_cast<TagDecl>(D))
2351 return TD->isCompleteDefinition() || TD->isBeingDefined();
2362 AlignedAttr *OldAlignasAttr =
nullptr;
2363 AlignedAttr *OldStrictestAlignAttr =
nullptr;
2364 unsigned OldAlign = 0;
2372 if (I->isAlignmentDependent())
2378 unsigned Align = I->getAlignment(S.
Context);
2379 if (Align > OldAlign) {
2381 OldStrictestAlignAttr = I;
2386 AlignedAttr *NewAlignasAttr =
nullptr;
2387 unsigned NewAlign = 0;
2389 if (I->isAlignmentDependent())
2395 unsigned Align = I->getAlignment(S.
Context);
2396 if (Align > NewAlign)
2400 if (OldAlignasAttr && NewAlignasAttr && OldAlign != NewAlign) {
2408 if (OldAlign == 0 || NewAlign == 0) {
2410 if (
ValueDecl *VD = dyn_cast<ValueDecl>(New))
2421 if (OldAlign != NewAlign) {
2422 S.
Diag(NewAlignasAttr->getLocation(), diag::err_alignas_mismatch)
2425 S.
Diag(OldAlignasAttr->getLocation(), diag::note_previous_declaration);
2440 S.
Diag(OldAlignasAttr->getLocation(), diag::note_alignas_on_declaration)
2444 bool AnyAdded =
false;
2447 if (OldAlign > NewAlign) {
2448 AlignedAttr *Clone = OldStrictestAlignAttr->clone(S.
Context);
2449 Clone->setInherited(
true);
2455 if (OldAlignasAttr && !NewAlignasAttr &&
2456 !(AnyAdded && OldStrictestAlignAttr->isAlignas())) {
2457 AlignedAttr *Clone = OldAlignasAttr->clone(S.
Context);
2458 Clone->setInherited(
true);
2478 if (
const auto *AA = dyn_cast<AvailabilityAttr>(Attr))
2480 D, AA->getRange(), AA->getPlatform(), AA->
isImplicit(),
2481 AA->getIntroduced(), AA->getDeprecated(), AA->getObsoleted(),
2482 AA->getUnavailable(), AA->getMessage(), AA->getStrict(),
2483 AA->getReplacement(), AMK, AA->getPriority(), AttrSpellingListIndex);
2484 else if (
const auto *VA = dyn_cast<VisibilityAttr>(Attr))
2486 AttrSpellingListIndex);
2487 else if (
const auto *VA = dyn_cast<TypeVisibilityAttr>(Attr))
2489 AttrSpellingListIndex);
2490 else if (
const auto *ImportA = dyn_cast<DLLImportAttr>(Attr))
2492 AttrSpellingListIndex);
2493 else if (
const auto *ExportA = dyn_cast<DLLExportAttr>(Attr))
2495 AttrSpellingListIndex);
2496 else if (
const auto *FA = dyn_cast<FormatAttr>(Attr))
2498 FA->getFormatIdx(), FA->getFirstArg(),
2499 AttrSpellingListIndex);
2500 else if (
const auto *SA = dyn_cast<SectionAttr>(Attr))
2502 AttrSpellingListIndex);
2503 else if (
const auto *CSA = dyn_cast<CodeSegAttr>(Attr))
2505 AttrSpellingListIndex);
2506 else if (
const auto *IA = dyn_cast<MSInheritanceAttr>(Attr))
2508 AttrSpellingListIndex,
2509 IA->getSemanticSpelling());
2510 else if (
const auto *AA = dyn_cast<AlwaysInlineAttr>(Attr))
2513 AttrSpellingListIndex);
2514 else if (S.
getLangOpts().CUDA && isa<FunctionDecl>(D) &&
2515 (isa<CUDAHostAttr>(Attr) || isa<CUDADeviceAttr>(Attr) ||
2516 isa<CUDAGlobalAttr>(Attr))) {
2520 }
else if (
const auto *MA = dyn_cast<MinSizeAttr>(Attr))
2522 else if (
const auto *OA = dyn_cast<OptimizeNoneAttr>(Attr))
2524 else if (
const auto *InternalLinkageA = dyn_cast<InternalLinkageAttr>(Attr))
2526 else if (
const auto *CommonA = dyn_cast<CommonAttr>(Attr))
2528 else if (isa<AlignedAttr>(Attr))
2532 else if ((isa<DeprecatedAttr>(Attr) || isa<UnavailableAttr>(Attr)) &&
2536 else if (
const auto *UA = dyn_cast<UuidAttr>(Attr))
2537 NewAttr = S.
mergeUuidAttr(D, UA->getRange(), AttrSpellingListIndex,
2539 else if (
const auto *SLHA = dyn_cast<SpeculativeLoadHardeningAttr>(Attr))
2541 else if (
const auto *SLHA = dyn_cast<NoSpeculativeLoadHardeningAttr>(Attr))
2544 NewAttr = cast<InheritableAttr>(Attr->
clone(S.
Context));
2549 if (isa<MSInheritanceAttr>(NewAttr))
2558 if (
const TagDecl *TD = dyn_cast<TagDecl>(D))
2559 return TD->getDefinition();
2560 if (
const VarDecl *VD = dyn_cast<VarDecl>(D)) {
2566 if (
const FunctionDecl *FD = dyn_cast<FunctionDecl>(D))
2572 for (
const auto *Attribute : D->
attrs())
2573 if (Attribute->getKind() ==
Kind)
2585 if (!Def || Def == New)
2589 for (
unsigned I = 0, E = NewAttributes.size(); I != E;) {
2590 const Attr *NewAttribute = NewAttributes[I];
2592 if (isa<AliasAttr>(NewAttribute) || isa<IFuncAttr>(NewAttribute)) {
2599 NewAttributes.erase(NewAttributes.begin() + I);
2604 VarDecl *VD = cast<VarDecl>(New);
2605 unsigned Diag = cast<VarDecl>(Def)->isThisDeclarationADefinition() ==
2607 ? diag::err_alias_after_tentative
2608 : diag::err_redefinition;
2610 if (Diag == diag::err_redefinition)
2620 if (
const VarDecl *VD = dyn_cast<VarDecl>(Def)) {
2633 if (isa<C11NoReturnAttr>(NewAttribute)) {
2637 }
else if (
const AlignedAttr *AA = dyn_cast<AlignedAttr>(NewAttribute)) {
2638 if (AA->isAlignas()) {
2649 S.
Diag(NewAttribute->
getLocation(), diag::note_alignas_on_declaration)
2651 NewAttributes.erase(NewAttributes.begin() + I);
2658 diag::warn_attribute_precede_definition);
2660 NewAttributes.erase(NewAttributes.begin() + I);
2669 UsedAttr *NewAttr = OldAttr->clone(Context);
2670 NewAttr->setInherited(
true);
2680 if (AsmLabelAttr *NewA = New->
getAttr<AsmLabelAttr>()) {
2681 if (AsmLabelAttr *OldA = Old->
getAttr<AsmLabelAttr>()) {
2682 if (OldA->getLabel() != NewA->getLabel()) {
2685 Diag(OldA->getLocation(), diag::note_previous_declaration);
2687 }
else if (Old->
isUsed()) {
2691 << isa<FunctionDecl>(Old) << New->
getAttr<AsmLabelAttr>()->getRange();
2696 if (
const auto *NewAbiTagAttr = New->
getAttr<AbiTagAttr>()) {
2697 if (
const auto *OldAbiTagAttr = Old->
getAttr<AbiTagAttr>()) {
2698 for (
const auto &NewTag : NewAbiTagAttr->tags()) {
2699 if (std::find(OldAbiTagAttr->tags_begin(), OldAbiTagAttr->tags_end(),
2700 NewTag) == OldAbiTagAttr->tags_end()) {
2701 Diag(NewAbiTagAttr->getLocation(),
2702 diag::err_new_abi_tag_on_redeclaration)
2704 Diag(OldAbiTagAttr->getLocation(), diag::note_previous_declaration);
2708 Diag(NewAbiTagAttr->getLocation(), diag::err_abi_tag_on_redeclaration);
2714 if (New->
hasAttr<SectionAttr>() && !Old->
hasAttr<SectionAttr>()) {
2715 if (
auto *VD = dyn_cast<VarDecl>(New)) {
2717 Diag(New->
getLocation(), diag::warn_attribute_section_on_redeclaration);
2724 const auto *NewCSA = New->
getAttr<CodeSegAttr>();
2725 if (NewCSA && !Old->
hasAttr<CodeSegAttr>() &&
2726 !NewCSA->isImplicit() && isa<CXXMethodDecl>(New)) {
2744 if (isa<DeprecatedAttr>(I) ||
2745 isa<UnavailableAttr>(I) ||
2746 isa<AvailabilityAttr>(I)) {
2751 case AMK_Redeclaration:
2753 case AMK_ProtocolImplementation:
2760 if (isa<UsedAttr>(I))
2782 const CarriesDependencyAttr *CDA = newDecl->
getAttr<CarriesDependencyAttr>();
2783 if (CDA && !oldDecl->
hasAttr<CarriesDependencyAttr>()) {
2784 S.
Diag(CDA->getLocation(),
2785 diag::err_carries_dependency_missing_on_first_decl) << 1;
2793 diag::note_carries_dependency_missing_first_decl) << 1;
2799 bool foundAny = newDecl->
hasAttrs();
2808 cast<InheritableParamAttr>(I->clone(S.
Context));
2823 if (*Oldnullability != *Newnullability) {
2824 S.
Diag(NewParam->
getLocation(), diag::warn_mismatched_nullability_attr)
2849 struct GNUCompatibleParamWarning {
2860 if (Ctor->isDefaultConstructor())
2863 if (Ctor->isCopyConstructor())
2866 if (Ctor->isMoveConstructor())
2868 }
else if (isa<CXXDestructorDecl>(MD)) {
2881 template <
typename T>
2882 static std::pair<diag::kind, SourceLocation>
2886 if (Old->isThisDeclarationADefinition())
2887 PrevDiag = diag::note_previous_definition;
2888 else if (Old->isImplicit()) {
2889 PrevDiag = diag::note_previous_implicit_declaration;
2891 OldLocation = New->getLocation();
2893 PrevDiag = diag::note_previous_declaration;
2894 return std::make_pair(PrevDiag, OldLocation);
2902 return ((FD->
hasAttr<GNUInlineAttr>() || LangOpts.GNUInline) &&
2903 !LangOpts.CPlusPlus &&
2915 template <
typename T>
2929 template<
typename T>
static bool isExternC(T *D) {
return D->isExternC(); }
2935 template<
typename ExpectedDecl>
2957 !Old->getDeclContext()->getRedeclContext()->Equals(
2958 New->getDeclContext()->getRedeclContext()) &&
2963 S.
Diag(New->getLocation(), diag::err_using_decl_conflict_reverse);
2976 const auto *AttrA = A->
getAttr<PassObjectSizeAttr>();
2977 const auto *AttrB = B->
getAttr<PassObjectSizeAttr>();
2980 return AttrA && AttrB && AttrA->getType() == AttrB->getType() &&
2981 AttrA->isDynamic() == AttrB->isDynamic();
2984 return std::equal(A->param_begin(), A->param_end(), B->
param_begin(), AttrEq);
3007 if (NamedDC->Equals(SemaDC))
3010 assert((NamedDC->InEnclosingNamespaceSetOf(SemaDC) ||
3012 "unexpected context for redeclaration");
3023 if (
auto *FD = dyn_cast<FunctionDecl>(NewD))
3024 FixSemaDC(FD->getDescribedFunctionTemplate());
3025 else if (
auto *VD = dyn_cast<VarDecl>(NewD))
3026 FixSemaDC(VD->getDescribedVarTemplate());
3041 Scope *S,
bool MergeTypeWithOld) {
3048 Diag(Shadow->getTargetDecl()->getLocation(),
3049 diag::note_using_decl_target);
3050 Diag(Shadow->getUsingDecl()->getLocation(),
3051 diag::note_using_decl) << 0;
3056 if (checkUsingShadowRedecl<FunctionDecl>(*
this, Shadow, New))
3058 OldD = Old = cast<FunctionDecl>(Shadow->getTargetDecl());
3072 if (!getASTContext().canBuiltinBeRedeclared(Old)) {
3081 std::tie(PrevDiag, OldLocation) =
3088 if (!isa<CXXMethodDecl>(New) && !isa<CXXMethodDecl>(Old) &&
3093 if (getLangOpts().MicrosoftExt) {
3095 Diag(OldLocation, PrevDiag);
3098 Diag(OldLocation, PrevDiag);
3103 if (New->
hasAttr<InternalLinkageAttr>() &&
3104 !Old->
hasAttr<InternalLinkageAttr>()) {
3108 New->
dropAttr<InternalLinkageAttr>();
3111 if (CheckRedeclarationModuleOwnership(New, Old))
3114 if (!getLangOpts().CPlusPlus) {
3115 bool OldOvl = Old->
hasAttr<OverloadableAttr>();
3126 const Decl *DiagOld = Old;
3128 auto OldIter = llvm::find_if(Old->
redecls(), [](
const Decl *D) {
3129 const auto *A = D->
getAttr<OverloadableAttr>();
3130 return A && !A->isImplicit();
3134 DiagOld = OldIter == Old->
redecls_end() ? nullptr : *OldIter;
3138 Diag(DiagOld->getLocation(),
3139 diag::note_attribute_overloadable_prev_overload)
3143 New->
addAttr(OverloadableAttr::CreateImplicit(Context));
3164 const FunctionType *OldType = cast<FunctionType>(OldQType);
3165 const FunctionType *NewType = cast<FunctionType>(NewQType);
3168 bool RequiresAdjustment =
false;
3170 if (OldTypeInfo.getCC() != NewTypeInfo.
getCC()) {
3175 bool NewCCExplicit = getCallingConvAttributedType(New->
getType());
3176 if (!NewCCExplicit) {
3180 RequiresAdjustment =
true;
3187 << (
int)CallingConventionIgnoredReason::BuiltinFunction;
3189 RequiresAdjustment =
true;
3192 bool FirstCCExplicit = getCallingConvAttributedType(First->
getType());
3196 << (!FirstCCExplicit ?
"" :
3206 if (OldTypeInfo.getNoReturn() && !NewTypeInfo.
getNoReturn()) {
3208 RequiresAdjustment =
true;
3212 if (OldTypeInfo.getHasRegParm() != NewTypeInfo.
getHasRegParm() ||
3213 OldTypeInfo.getRegParm() != NewTypeInfo.
getRegParm()) {
3216 << NewType->getRegParmType()
3218 Diag(OldLocation, diag::note_previous_declaration);
3222 NewTypeInfo = NewTypeInfo.
withRegParm(OldTypeInfo.getRegParm());
3223 RequiresAdjustment =
true;
3230 <<
"'ns_returns_retained'";
3231 Diag(OldLocation, diag::note_previous_declaration);
3236 RequiresAdjustment =
true;
3239 if (OldTypeInfo.getNoCallerSavedRegs() !=
3242 AnyX86NoCallerSavedRegistersAttr *
Attr =
3243 New->
getAttr<AnyX86NoCallerSavedRegistersAttr>();
3244 Diag(New->
getLocation(), diag::err_function_attribute_mismatch) << Attr;
3245 Diag(OldLocation, diag::note_previous_declaration);
3250 RequiresAdjustment =
true;
3253 if (RequiresAdjustment) {
3263 !New->
hasAttr<GNUInlineAttr>() &&
3264 !getLangOpts().GNUInline &&
3272 if (New->
hasAttr<GNUInlineAttr>() &&
3283 Diag(OldLocation, PrevDiag) << Old << Old->
getType();
3298 if (CheckEquivalentExceptionSpec(Old, New))
3310 if (!Context.
hasSameType(OldDeclaredReturnType, NewDeclaredReturnType) &&
3311 canFullyTypeCheckRedeclaration(New, Old, NewDeclaredReturnType,
3312 OldDeclaredReturnType)) {
3320 Diag(New->
getLocation(), diag::err_member_def_does_not_match_ret_type)
3325 Diag(OldLocation, PrevDiag) << Old << Old->
getType()
3334 QualType NewReturnType = cast<FunctionType>(NewQType)->getReturnType();
3335 if (OldReturnType != NewReturnType) {
3345 SubstAutoType(NewQType,
3353 if (OldMethod && NewMethod) {
3360 bool IsClassScopeExplicitSpecialization =
3362 NewMethod->isFunctionTemplateSpecialization();
3363 bool isFriend = NewMethod->getFriendObjectKind();
3365 if (!isFriend && NewMethod->getLexicalDeclContext()->isRecord() &&
3366 !IsClassScopeExplicitSpecialization) {
3370 if (OldMethod->
isStatic() != NewMethod->isStatic()) {
3372 Diag(OldLocation, PrevDiag) << Old << Old->
getType();
3380 if (!inTemplateInstantiation()) {
3382 if (isa<CXXConstructorDecl>(OldMethod))
3383 NewDiag = diag::err_constructor_redeclared;
3384 else if (isa<CXXDestructorDecl>(NewMethod))
3385 NewDiag = diag::err_destructor_redeclared;
3386 else if (isa<CXXConversionDecl>(NewMethod))
3387 NewDiag = diag::err_conv_function_redeclared;
3389 NewDiag = diag::err_member_redeclared;
3393 Diag(New->
getLocation(), diag::err_member_redeclared_in_instantiation)
3396 Diag(OldLocation, PrevDiag) << Old << Old->
getType();
3406 NewMethod->setImplicit();
3408 Diag(NewMethod->getLocation(),
3409 diag::err_definition_of_implicitly_declared_member)
3410 << New << getSpecialMember(OldMethod);
3414 Diag(NewMethod->getLocation(),
3415 diag::err_definition_of_explicitly_defaulted_member)
3416 << getSpecialMember(OldMethod);
3425 const CXX11NoReturnAttr *NRA = New->
getAttr<CXX11NoReturnAttr>();
3426 if (NRA && !Old->
hasAttr<CXX11NoReturnAttr>()) {
3427 Diag(NRA->getLocation(), diag::err_noreturn_missing_on_first_decl);
3429 diag::note_noreturn_missing_first_decl);
3436 const CarriesDependencyAttr *CDA = New->
getAttr<CarriesDependencyAttr>();
3437 if (CDA && !Old->
hasAttr<CarriesDependencyAttr>()) {
3438 Diag(CDA->getLocation(),
3439 diag::err_carries_dependency_missing_on_first_decl) << 0;
3441 diag::note_carries_dependency_missing_first_decl) << 0;
3450 QualType OldQTypeForComparison = OldQType;
3451 if (!OldTypeInfo.getNoReturn() && NewTypeInfo.
getNoReturn()) {
3455 OldQTypeForComparison =
QualType(OldTypeForComparison, 0);
3456 assert(OldQTypeForComparison.isCanonical());
3470 Diag(OldLocation, PrevDiag);
3472 Diag(New->
getLocation(), diag::err_different_language_linkage) << New;
3473 Diag(OldLocation, PrevDiag);
3478 if (OldQTypeForComparison == NewQType)
3479 return MergeCompatibleFunctionDecls(New, Old, S, MergeTypeWithOld);
3484 if (!canFullyTypeCheckRedeclaration(New, Old, NewQType, OldQType))
3497 if (MergeTypeWithOld && isa<FunctionNoProtoType>(NewFuncType) &&
3501 assert(!OldProto->hasExceptionSpec() &&
"Exception spec in C");
3505 OldProto->getExtProtoInfo());
3511 for (
const auto &ParamType : OldProto->param_types()) {
3518 Params.push_back(Param);
3521 New->setParams(Params);
3524 return MergeCompatibleFunctionDecls(New, Old, S, MergeTypeWithOld);
3551 NewProto->getReturnType());
3552 bool LooseCompatible = !MergedReturn.
isNull();
3554 LooseCompatible && Idx !=
End; ++Idx) {
3558 NewProto->getParamType(Idx))) {
3559 ArgTypes.push_back(NewParm->
getType());
3563 GNUCompatibleParamWarning Warn = { OldParm, NewParm,
3564 NewProto->getParamType(Idx) };
3565 Warnings.push_back(Warn);
3566 ArgTypes.push_back(NewParm->
getType());
3568 LooseCompatible =
false;
3571 if (LooseCompatible) {
3572 for (
unsigned Warn = 0; Warn < Warnings.size(); ++Warn) {
3573 Diag(Warnings[Warn].NewParm->getLocation(),
3574 diag::ext_param_promoted_not_compatible_with_prototype)
3575 << Warnings[Warn].PromotedType
3576 << Warnings[Warn].OldParm->getType();
3577 if (Warnings[Warn].OldParm->getLocation().isValid())
3578 Diag(Warnings[Warn].OldParm->getLocation(),
3579 diag::note_previous_declaration);
3582 if (MergeTypeWithOld)
3585 return MergeCompatibleFunctionDecls(New, Old, S, MergeTypeWithOld);
3602 Diag(OldLocation, diag::note_previous_builtin_declaration)
3619 PrevDiag = diag::note_previous_builtin_declaration;
3623 Diag(OldLocation, PrevDiag) << Old << Old->
getType();
3637 Scope *S,
bool MergeTypeWithOld) {
3639 mergeDeclAttributes(New, Old);
3660 return MergeCXXFunctionDecl(New, Old, S);
3666 if (!Merged.
isNull() && MergeTypeWithOld)
3677 ? AMK_ProtocolImplementation
3678 : isa<ObjCImplDecl>(newMethod->
getDeclContext()) ? AMK_Redeclaration
3681 mergeDeclAttributes(newMethod, oldMethod, MergeKind);
3688 ni != ne && oi != oe; ++ni, ++oi)
3691 CheckObjCMethodOverride(newMethod, oldMethod);
3698 ? diag::err_redefinition_different_type
3699 : diag::err_redeclaration_different_type)
3704 std::tie(PrevDiag, OldLocation)
3706 S.
Diag(OldLocation, PrevDiag);
3718 bool MergeTypeWithOld) {
3723 if (getLangOpts().CPlusPlus) {
3729 return MergeVarDeclExceptionSpecs(New, Old);
3800 if (MergeTypeWithOld)
3846 if (!shouldLinkPossiblyHiddenDecl(Previous, New))
3861 if (checkUsingShadowRedecl<VarTemplateDecl>(*
this, Shadow, NewTemplate))
3868 if (checkUsingShadowRedecl<VarDecl>(*
this, Shadow, New))
3884 true, TPL_TemplateMatch))
3898 mergeDeclAttributes(New, Old);
3901 if (New->
hasAttr<WeakImportAttr>() &&
3903 !Old->
hasAttr<WeakImportAttr>()) {
3910 if (New->
hasAttr<InternalLinkageAttr>() &&
3911 !Old->
hasAttr<InternalLinkageAttr>()) {
3915 New->
dropAttr<InternalLinkageAttr>();
3920 if (MostRecent != Old) {
3921 MergeVarDeclTypes(New, MostRecent,
3933 std::tie(PrevDiag, OldLocation) =
3940 if (getLangOpts().MicrosoftExt) {
3943 Diag(OldLocation, PrevDiag);
3947 Diag(OldLocation, PrevDiag);
3966 Diag(OldLocation, PrevDiag);
3974 Diag(OldLocation, PrevDiag);
3980 Diag(OldLocation, PrevDiag);
3984 if (CheckRedeclarationModuleOwnership(New, Old))
3996 Diag(OldLocation, PrevDiag);
4006 Diag(Def->getLocation(), diag::note_previous_definition);
4020 Diag(OldLocation, PrevDiag);
4023 Diag(OldLocation, PrevDiag);
4031 Diag(OldLocation, PrevDiag);
4042 diag::warn_deprecated_redundant_constexpr_static_def);
4044 if (checkVarDeclRedefinition(Def, New))
4050 Diag(New->
getLocation(), diag::err_different_language_linkage) << New;
4051 Diag(OldLocation, PrevDiag);
4081 auto &HSI = PP.getHeaderSearchInfo();
4082 StringRef HdrFilename =
4085 auto noteFromModuleOrInclude = [&](
Module *Mod,
4091 if (IncLoc.isValid()) {
4093 Diag(IncLoc, diag::note_redefinition_modules_same_file)
4099 Diag(IncLoc, diag::note_redefinition_include_same_file)
4100 << HdrFilename.str();
4110 bool EmittedDiag =
false;
4111 if (FNew == FOld && FNewDecLoc.second == FOldDecLoc.second) {
4114 EmittedDiag = noteFromModuleOrInclude(Old->
getOwningModule(), OldIncLoc);
4115 EmittedDiag |= noteFromModuleOrInclude(getCurrentModule(), NewIncLoc);
4118 if (FOld && !HSI.isFileMultipleIncludeGuarded(FOld))
4133 if (!hasVisibleDefinition(Old) &&
4145 makeMergedDefinitionVisible(OldTD);
4146 makeMergedDefinitionVisible(Old);
4181 if (isa<CXXRecordDecl>(Tag->
getParent())) {
4195 Decl *ManglingContextDecl;
4199 Tag, MCtx->getManglingNumber(
4219 if (getLangOpts().CPlusPlus)
4234 tagLoc = getLocForEndOfToken(tagLoc);
4237 textToInsert +=
' ';
4239 Diag(tagLoc, diag::note_typedef_changes_linkage)
4261 llvm_unreachable(
"unexpected type specifier");
4271 bool IsExplicitInstantiation,
4273 Decl *TagD =
nullptr;
4288 if (isa<TagDecl>(TagD))
4289 Tag = cast<TagDecl>(TagD);
4291 Tag = CTD->getTemplatedDecl();
4295 handleTagNumbering(Tag, S);
4306 diag::err_typecheck_invalid_restrict_not_pointer_noarg)
4312 << getLangOpts().CPlusPlus17;
4330 DiagnoseFunctionSpecifiers(DS);
4337 return ActOnFriendTypeDecl(S, DS, TemplateParams);
4341 bool IsExplicitSpecialization =
4342 !TemplateParams.empty() && TemplateParams.back()->size() == 0;
4344 !IsExplicitInstantiation && !IsExplicitSpecialization &&
4345 !isa<ClassTemplatePartialSpecializationDecl>(Tag)) {
4354 Diag(SS.
getBeginLoc(), diag::err_standalone_class_nested_name_specifier)
4360 bool DeclaresAnything =
true;
4363 if (
RecordDecl *Record = dyn_cast_or_null<RecordDecl>(Tag)) {
4364 if (!Record->getDeclName() && Record->isCompleteDefinition() &&
4366 if (getLangOpts().CPlusPlus ||
4367 Record->getDeclContext()->isRecord()) {
4375 if (CurContext->isFunctionOrMethod())
4376 AnonRecord = Record;
4377 return BuildAnonymousStructOrUnion(S, DS, AS, Record,
4381 DeclaresAnything =
false;
4391 if (!getLangOpts().CPlusPlus && CurContext->isRecord() &&
4407 Record = RT->getDecl();
4409 Record = UT->getDecl();
4411 if (Record && getLangOpts().MicrosoftExt) {
4414 return BuildMicrosoftCAnonymousStruct(S, DS, Record);
4417 DeclaresAnything =
false;
4426 if (getLangOpts().CPlusPlus &&
4428 if (
EnumDecl *Enum = dyn_cast_or_null<EnumDecl>(Tag))
4429 if (Enum->enumerator_begin() == Enum->enumerator_end() &&
4430 !Enum->getIdentifier() && !Enum->isInvalidDecl())
4431 DeclaresAnything =
false;
4439 DeclaresAnything =
false;
4448 ActOnDocumentableDecl(TagD);
4458 if (!DeclaresAnything) {
4473 unsigned DiagID = diag::warn_standalone_specifier;
4475 DiagID = diag::ext_standalone_specifier;
4516 Diag(AL.getLoc(), diag::warn_declspec_attribute_ignored)
4540 assert(PrevDecl &&
"Expected a non-null Decl");
4545 SemaRef.
Diag(NameLoc, diag::err_anonymous_record_member_redecl)
4547 SemaRef.
Diag(PrevDecl->
getLocation(), diag::note_previous_declaration);
4572 bool Invalid =
false;
4575 for (
auto *D : AnonRecord->
decls()) {
4576 if ((isa<FieldDecl>(D) || isa<IndirectFieldDecl>(D)) &&
4577 cast<NamedDecl>(D)->getDeclName()) {
4593 unsigned OldChainingSize = Chaining.size();
4595 Chaining.append(IF->chain_begin(), IF->chain_end());
4597 Chaining.push_back(VD);
4599 assert(Chaining.size() >= 2);
4602 for (
unsigned i = 0;
i < Chaining.size();
i++)
4603 NamedChain[
i] = Chaining[
i];
4607 VD->
getType(), {NamedChain, Chaining.size()});
4619 Chaining.resize(OldChainingSize);
4634 "Parser allowed 'typedef' as storage class VarDecl.");
4635 switch (StorageClassSpec) {
4649 llvm_unreachable(
"unknown storage class specifier");
4655 for (
const auto *I : Record->
decls()) {
4656 const auto *FD = dyn_cast<
FieldDecl>(I);
4657 if (
const auto *IFD = dyn_cast<IndirectFieldDecl>(I))
4658 FD = IFD->getAnonField();
4659 if (FD && FD->hasInClassInitializer())
4663 llvm_unreachable(
"couldn't find in-class initializer");
4671 S.
Diag(DefaultInitLoc, diag::err_multiple_mem_union_initialization);
4694 if (Record->
isUnion() && !getLangOpts().CPlusPlus && !getLangOpts().C11)
4696 else if (!Record->
isUnion() && getLangOpts().CPlusPlus)
4698 else if (!Record->
isUnion() && !getLangOpts().C11)
4703 bool Invalid =
false;
4704 if (getLangOpts().CPlusPlus) {
4705 const char *PrevSpec =
nullptr;
4716 !cast<NamespaceDecl>(OwnerScope)->isAnonymousNamespace()))) {
4722 PrevSpec, DiagID, Policy);
4728 isa<RecordDecl>(Owner)) {
4730 diag::err_anonymous_union_with_storage_spec)
4744 << Record->
isUnion() <<
"const" 4748 diag::ext_anonymous_struct_union_qualified)
4749 << Record->
isUnion() <<
"volatile" 4753 diag::ext_anonymous_struct_union_qualified)
4754 << Record->
isUnion() <<
"restrict" 4758 diag::ext_anonymous_struct_union_qualified)
4759 << Record->
isUnion() <<
"_Atomic" 4763 diag::ext_anonymous_struct_union_qualified)
4764 << Record->
isUnion() <<
"__unaligned" 4774 for (
auto *Mem : Record->
decls()) {
4775 if (
auto *FD = dyn_cast<FieldDecl>(Mem)) {
4779 assert(FD->getAccess() !=
AS_none);
4781 Diag(FD->getLocation(), diag::err_anonymous_record_nonpublic_member)
4791 if (CheckNontrivialField(FD))
4793 }
else if (Mem->isImplicit()) {
4795 }
else if (isa<TagDecl>(Mem) && Mem->getDeclContext() != Record) {
4800 }
else if (
auto *MemRecord = dyn_cast<RecordDecl>(Mem)) {
4801 if (!MemRecord->isAnonymousStructOrUnion() &&
4802 MemRecord->getDeclName()) {
4804 if (getLangOpts().MicrosoftExt)
4805 Diag(MemRecord->getLocation(), diag::ext_anonymous_record_with_type)
4809 Diag(MemRecord->getLocation(), diag::err_anonymous_record_with_type)
4817 Diag(MemRecord->getLocation(),
4818 diag::ext_anonymous_record_with_anonymous_type)
4821 }
else if (isa<AccessSpecDecl>(Mem)) {
4823 }
else if (isa<StaticAssertDecl>(Mem)) {
4828 unsigned DK = diag::err_anonymous_record_bad_member;
4829 if (isa<TypeDecl>(Mem))
4830 DK = diag::err_anonymous_record_with_type;
4831 else if (isa<FunctionDecl>(Mem))
4832 DK = diag::err_anonymous_record_with_function;
4833 else if (isa<VarDecl>(Mem))
4834 DK = diag::err_anonymous_record_with_static;
4837 if (getLangOpts().MicrosoftExt &&
4838 DK == diag::err_anonymous_record_with_type)
4839 Diag(Mem->getLocation(), diag::ext_anonymous_record_with_type)
4842 Diag(Mem->getLocation(), DK) << Record->
isUnion();
4851 if (cast<CXXRecordDecl>(Record)->hasInClassInitializer() &&
4854 cast<CXXRecordDecl>(Record));
4859 << getLangOpts().CPlusPlus;
4872 if (getLangOpts().CPlusPlus && Record->
field_empty())
4878 assert(TInfo &&
"couldn't build declarator info for anonymous struct/union");
4882 if (
RecordDecl *OwningClass = dyn_cast<RecordDecl>(Owner)) {
4890 FieldCollector->Add(cast<FieldDecl>(Anon));
4910 ActOnUninitializedDecl(Anon);
4926 Chain.push_back(Anon);
4931 if (
VarDecl *NewVD = dyn_cast<VarDecl>(Anon)) {
4932 if (getLangOpts().
CPlusPlus && NewVD->isStaticLocal()) {
4933 Decl *ManglingContextDecl;
4935 NewVD->getDeclContext(), ManglingContextDecl)) {
4937 NewVD, MCtx->getManglingNumber(
4965 assert(Record &&
"expected a record!");
4970 assert(TInfo &&
"couldn't build declarator info for anonymous struct");
4972 auto *ParentDecl = cast<RecordDecl>(CurContext);
4978 nullptr, RecTy, TInfo,
4984 CurContext->addDecl(Anon);
4990 Chain.push_back(Anon);
4993 if (RequireCompleteType(Anon->
getLocation(), RecTy,
4994 diag::err_field_incomplete) ||
4998 ParentDecl->setInvalidDecl();
5007 return GetNameFromUnqualifiedId(D.
getName());
5036 if (!Template || !isa<ClassTemplateDecl>(Template)) {
5038 diag::err_deduction_guide_name_not_class_template)
5039 << (int)getTemplateNameKindForDiagnostics(TN) << TN;
5041 Diag(Template->getLocation(), diag::note_template_decl_here);
5128 llvm_unreachable(
"Unknown name kind");
5156 for (
unsigned Idx = 0; Idx < Declaration->
param_size(); ++Idx) {
5170 (DeclTyName && DeclTyName == DefTyName))
5171 Params.push_back(Idx);
5212 if (!TSI)
return true;
5257 if (OriginalLexicalContext && OriginalLexicalContext->isObjCContainer() &&
5261 if (getLangOpts().OpenCL)
5262 setCurrentOpenCLExtensionForDecl(Dcl);
5280 Record = dyn_cast<CXXRecordDecl>(Record->
getParent());
5282 Diag(NameInfo.
getLoc(), diag::err_member_name_of_class) << Name;
5309 while (isa<LinkageSpecDecl>(Cur) || isa<CapturedDecl>(Cur))
5323 Diag(Loc, LangOpts.MicrosoftExt ? diag::warn_member_extra_qualification
5324 : diag::err_member_extra_qualification)
5328 Diag(Loc, diag::warn_namespace_member_extra_qualification) << Name;
5336 if (!Cur->
Encloses(DC) && !IsTemplateId) {
5338 Diag(Loc, diag::err_member_qualification)
5340 else if (isa<TranslationUnitDecl>(DC))
5341 Diag(Loc, diag::err_invalid_declarator_global_scope)
5343 else if (isa<FunctionDecl>(Cur))
5344 Diag(Loc, diag::err_invalid_declarator_in_function)
5346 else if (isa<BlockDecl>(Cur))
5347 Diag(Loc, diag::err_invalid_declarator_in_block)
5350 Diag(Loc, diag::err_invalid_declarator_scope)
5351 << Name << cast<NamedDecl>(Cur) << cast<NamedDecl>(DC) << SS.
getRange();
5358 Diag(Loc, diag::err_member_qualification)
5378 while (SpecLoc.getPrefix())
5380 if (dyn_cast_or_null<DecltypeType>(
5381 SpecLoc.getNestedNameSpecifier()->getAsType()))
5382 Diag(Loc, diag::err_decltype_in_declarator)
5383 << SpecLoc.getTypeLoc().getSourceRange();
5397 return ActOnDecompositionDeclarator(S, D, TemplateParamLists);
5403 }
else if (DiagnoseUnexpandedParameterPack(NameInfo, UPPC_DeclarationType))
5417 UPPC_DeclarationQualifier))
5422 if (!DC || isa<EnumDecl>(DC)) {
5428 diag::err_template_qualified_declarator_no_match)
5435 if (!IsDependentContext &&
5440 if (isa<CXXRecordDecl>(DC) && !cast<CXXRecordDecl>(DC)->
hasDefinition()) {
5442 diag::err_member_def_undefined_record)
5447 if (diagnoseQualifiedDeclaration(
5459 if (EnteringContext && IsDependentContext &&
5460 TemplateParamLists.size() != 0) {
5471 UPPC_DeclarationType))
5475 forRedeclarationInCurContext());
5479 bool IsLinkageLookup =
false;
5480 bool CreateBuiltins =
false;
5491 else if (CurContext->isFunctionOrMethod() &&
5494 IsLinkageLookup =
true;
5496 CurContext->getEnclosingNamespaceContext()->isTranslationUnit();
5497 }
else if (CurContext->getRedeclContext()->isTranslationUnit() &&
5499 CreateBuiltins =
true;
5501 if (IsLinkageLookup) {
5502 Previous.
clear(LookupRedeclarationWithLinkage);
5506 LookupName(Previous, S, CreateBuiltins);
5508 LookupQualifiedName(Previous, DC);
5550 if (!R->
isFunctionType() && DiagnoseClassNameShadow(DC, NameInfo))
5566 CheckExtraCXXDefaultArguments(D);
5570 bool AddToScope =
true;
5572 if (TemplateParamLists.size()) {
5577 New = ActOnTypedefDeclarator(S, D, DC, TInfo, Previous);
5579 New = ActOnFunctionDeclarator(S, D, DC, TInfo, Previous,
5583 New = ActOnVariableDeclarator(S, D, DC, TInfo, Previous, TemplateParamLists,
5593 PushOnScopeChains(New, S);
5595 if (isInOpenMPDeclareTargetContext())
5596 checkDeclIsAllowedInOpenMPTarget(
nullptr, New);
5606 bool &SizeIsNegative,
5607 llvm::APSInt &Oversized) {
5612 SizeIsNegative =
false;
5621 if (
const PointerType* PTy = dyn_cast<PointerType>(Ty)) {
5626 if (FixedType.
isNull())
return FixedType;
5628 return Qs.
apply(Context, FixedType);
5630 if (
const ParenType* PTy = dyn_cast<ParenType>(Ty)) {
5631 QualType Inner = PTy->getInnerType();
5635 if (FixedType.
isNull())
return FixedType;
5637 return Qs.
apply(Context, FixedType);
5655 if (Res.isSigned() && Res.isNegative()) {
5656 SizeIsNegative =
true;
5661 unsigned ActiveSizeBits
5695 TypeLoc DstElemTL = DstATL.getElementLoc();
5708 bool &SizeIsNegative,
5709 llvm::APSInt &Oversized) {
5712 SizeIsNegative, Oversized);
5739 return Result.empty() ? nullptr : *Result.begin();
5749 diag::err_virtual_non_function);
5753 diag::err_explicit_non_function);
5757 diag::err_noreturn_non_function);
5777 << getLangOpts().CPlusPlus17;
5785 diag::err_deduction_guide_invalid_specifier)
5794 if (!NewTD)
return nullptr;
5797 ProcessDeclAttributes(S, NewTD, D);
5799 CheckTypedefForVariablyModifiedType(S, NewTD);
5802 NamedDecl *ND = ActOnTypedefNameDecl(S, DC, NewTD, Previous, Redeclaration);
5816 setFunctionHasBranchProtectedScope();
5819 bool SizeIsNegative;
5820 llvm::APSInt Oversized;
5833 else if (Oversized.getBoolValue())
5835 << Oversized.toString(10);
5852 NamedDecl *ShadowedDecl = getShadowedDeclaration(NewTD, Previous);
5856 FilterLookupForScope(Previous, DC, S,
false,
5859 if (!Previous.
empty()) {
5860 Redeclaration =
true;
5861 MergeTypedefNameDecl(S, NewTD, Previous);
5864 if (ShadowedDecl && !Redeclaration)
5865 CheckShadow(NewTD, ShadowedDecl, Previous);
5871 if (II->isStr(
"FILE"))
5873 else if (II->isStr(
"jmp_buf"))
5875 else if (II->isStr(
"sigjmp_buf"))
5877 else if (II->isStr(
"ucontext_t"))
5935 if (!OuterContext->
Equals(PrevOuterContext))
5944 if (!SS.
isSet())
return;
5953 unsigned kind = -1U;
5954 if (
VarDecl *var = dyn_cast<VarDecl>(decl)) {
5955 if (var->hasAttr<BlocksAttr>())
5957 else if (!var->hasLocalStorage())
5959 }
else if (isa<ObjCIvarDecl>(decl)) {
5961 }
else if (isa<FieldDecl>(decl)) {
5979 if (
VarDecl *var = dyn_cast<VarDecl>(decl)) {
5982 var->getTLSKind()) {
5983 Diag(var->getLocation(), diag::err_arc_thread_ownership)
6004 if (WeakRefAttr *
Attr = ND.
getAttr<WeakRefAttr>()) {
6012 if (
auto *VD = dyn_cast<VarDecl>(&ND)) {
6013 if (VD->hasInit()) {
6014 if (
const auto *
Attr = VD->getAttr<AliasAttr>()) {
6015 assert(VD->isThisDeclarationADefinition() &&
6016 !VD->isExternallyVisible() &&
"Broken AliasAttr handled late!");
6018 VD->dropAttr<AliasAttr>();
6025 if (SelectAnyAttr *
Attr = ND.
getAttr<SelectAnyAttr>()) {
6028 diag::err_attribute_selectany_non_extern_data);
6034 auto *VD = dyn_cast<
VarDecl>(&ND);
6035 bool IsAnonymousNS =
false;
6039 while (NS && !IsAnonymousNS) {
6048 bool AnonNSInMicrosoftMode = IsAnonymousNS && IsMicrosoft;
6050 (!AnonNSInMicrosoftMode &&
6060 if (
auto *MD = dyn_cast<CXXMethodDecl>(&ND))
6061 if (MD->isVirtual()) {
6063 diag::err_invalid_attribute_on_virtual_function)
6069 if (
const auto *FD = dyn_cast<FunctionDecl>(&ND)) {
6074 for (
TypeLoc TL = FD->getTypeSourceInfo()->getTypeLoc();
6080 if (
const auto *A = ATL.
getAttrAs<LifetimeBoundAttr>()) {
6082 if (!MD || MD->isStatic()) {
6083 S.
Diag(A->getLocation(), diag::err_lifetimebound_no_object_param)
6084 << !MD << A->getRange();
6085 }
else if (isa<CXXConstructorDecl>(MD) || isa<CXXDestructorDecl>(MD)) {
6086 S.
Diag(A->getLocation(), diag::err_lifetimebound_ctor_dtor)
6087 << isa<CXXDestructorDecl>(MD) << A->getRange();
6096 bool IsSpecialization,
6097 bool IsDefinition) {
6101 bool IsTemplate =
false;
6102 if (
TemplateDecl *OldTD = dyn_cast<TemplateDecl>(OldDecl)) {
6103 OldDecl = OldTD->getTemplatedDecl();
6105 if (!IsSpecialization)
6106 IsDefinition =
false;
6108 if (
TemplateDecl *NewTD = dyn_cast<TemplateDecl>(NewDecl)) {
6109 NewDecl = NewTD->getTemplatedDecl();
6113 if (!OldDecl || !NewDecl)
6116 const DLLImportAttr *OldImportAttr = OldDecl->
getAttr<DLLImportAttr>();
6117 const DLLExportAttr *OldExportAttr = OldDecl->
getAttr<DLLExportAttr>();
6118 const DLLImportAttr *NewImportAttr = NewDecl->
getAttr<DLLImportAttr>();
6119 const DLLExportAttr *NewExportAttr = NewDecl->
getAttr<DLLExportAttr>();
6123 bool HasNewAttr = (NewImportAttr && !NewImportAttr->isInherited()) ||
6124 (NewExportAttr && !NewExportAttr->isInherited());
6130 bool AddsAttr = !(OldImportAttr || OldExportAttr) && HasNewAttr;
6132 if (AddsAttr && !IsSpecialization && !OldDecl->
isImplicit()) {
6134 bool JustWarn =
false;
6136 auto *VD = dyn_cast<
VarDecl>(OldDecl);
6137 if (VD && !VD->getDescribedVarTemplate())
6148 if (!isa<FunctionDecl>(OldDecl) || !NewImportAttr)
6151 unsigned DiagID = JustWarn ? diag::warn_attribute_dll_redeclaration
6152 : diag::err_attribute_dll_redeclaration;
6155 << (NewImportAttr ? (
const Attr *)NewImportAttr : NewExportAttr);
6168 bool IsInline =
false, IsStaticDataMember =
false, IsQualifiedFriend =
false;
6170 if (
const auto *VD = dyn_cast<VarDecl>(NewDecl)) {
6173 IsStaticDataMember = VD->isStaticDataMember();
6174 IsDefinition = VD->isThisDeclarationADefinition(S.
Context) !=
6176 }
else if (
const auto *FD = dyn_cast<FunctionDecl>(NewDecl)) {
6177 IsInline = FD->isInlined();
6178 IsQualifiedFriend = FD->getQualifier() &&
6182 if (OldImportAttr && !HasNewAttr &&
6183 (!IsInline || (IsMicrosoft && IsTemplate)) && !IsStaticDataMember &&
6185 if (IsMicrosoft && IsDefinition) {
6187 diag::warn_redeclaration_without_import_attribute)
6190 NewDecl->
dropAttr<DLLImportAttr>();
6192 NewImportAttr->getRange(), S.
Context,
6193 NewImportAttr->getSpellingListIndex()));
6196 diag::warn_redeclaration_without_attribute_prev_attribute_ignored)
6197 << NewDecl << OldImportAttr;
6199 S.
Diag(OldImportAttr->getLocation(), diag::note_previous_attribute);
6200 OldDecl->
dropAttr<DLLImportAttr>();
6201 NewDecl->
dropAttr<DLLImportAttr>();
6203 }
else if (IsInline && OldImportAttr && !IsMicrosoft) {
6206 OldDecl->
dropAttr<DLLImportAttr>();
6207 NewDecl->
dropAttr<DLLImportAttr>();
6209 diag::warn_dllimport_dropped_from_inline_function)
6210 << NewDecl << OldImportAttr;
6217 if (
const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(NewDecl)) {
6219 !NewImportAttr && !NewExportAttr) {
6220 if (
const DLLExportAttr *ParentExportAttr =
6221 MD->getParent()->getAttr<DLLExportAttr>()) {
6222 DLLExportAttr *NewAttr = ParentExportAttr->clone(S.
Context);
6223 NewAttr->setInherited(
true);
6263 template<
typename T>
6267 if (!D->isInExternCContext() || D->template hasAttr<OverloadableAttr>())
6271 if (S.
getLangOpts().CUDA && (D->template hasAttr<CUDADeviceAttr>() ||
6272 D->template hasAttr<CUDAHostAttr>()))
6275 return D->isExternC();
6281 isa<OMPDeclareMapperDecl>(DC))
6287 llvm_unreachable(
"Unexpected context");
6293 isa<OMPDeclareReductionDecl>(DC) || isa<OMPDeclareMapperDecl>(DC))
6297 llvm_unreachable(
"Unexpected context");
6343 if (
const auto *FD = dyn_cast<FunctionDecl>(D))
6344 return FD->isExternC();
6345 if (
const auto *VD = dyn_cast<VarDecl>(D))
6346 return VD->isExternC();
6348 llvm_unreachable(
"Unknown type of decl!");
6364 if (!Decomp.bindings().empty()) {
6365 II = Decomp.bindings()[0].Name;
6373 if (getLangOpts().OpenCL) {
6379 diag::err_opencl_type_can_only_be_used_as_function_parameter)
6392 diag::err_invalid_type_for_program_scope_var) << R;
6409 if (!getOpenCLOptions().
isEnabled(
"cl_khr_fp16")) {
6453 bool IsCXX = getLangOpts().OpenCLCPlusPlus;
6455 diag::err_opencl_unknown_type_specifier)
6456 << IsCXX << getLangOpts().getOpenCLVersionTuple().getAsString()
6474 bool IsLocalExternDecl = SC ==
SC_Extern &&
6475 adjustContextForLocalExternDecl(DC);
6486 !D.
getAsmLabel() && !getSourceManager().isInSystemMacro(
6492 getLangOpts().CPlusPlus17 ? diag::ext_register_storage_class
6493 : diag::warn_deprecated_register)
6509 bool IsMemberSpecialization =
false;
6510 bool IsVariableTemplateSpecialization =
false;
6512 bool IsVariableTemplate =
false;
6520 if (R->getContainedDeducedType())
6521 ParsingInitForAutoVars.insert(NewVD);
6529 NTCUC_AutoVar, NTCUK_Destruct);
6531 bool Invalid =
false;
6533 if (DC->
isRecord() && !CurContext->isRecord()) {
6540 diag::err_static_out_of_line)
6552 diag::err_storage_class_for_static_member)
6556 llvm_unreachable(
"C storage class in c++!");
6560 if (SC ==
SC_Static && CurContext->isRecord()) {
6561 if (
const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(DC)) {
6562 if (RD->isLocalClass())
6564 diag::err_static_data_member_not_allowed_in_local_class)
6565 << Name << RD->getDeclName();
6571 getLangOpts().CPlusPlus11
6572 ? diag::warn_cxx98_compat_static_data_member_in_union
6573 : diag::ext_static_data_member_in_union) << Name;
6575 else if (!RD->getDeclName())
6577 diag::err_static_data_member_not_allowed_in_anon_struct)
6578 << Name << RD->isUnion();
6584 TemplateParams = MatchTemplateParametersToScopeSpecifier(
6591 false, IsMemberSpecialization, Invalid);
6593 if (TemplateParams) {
6594 if (!TemplateParams->
size() &&
6599 diag::err_template_variable_noparams)
6603 TemplateParams =
nullptr;
6608 IsVariableTemplateSpecialization =
true;
6609 IsPartialSpecialization = TemplateParams->
size() > 0;
6612 IsVariableTemplate =
true;
6615 if (CheckTemplateDeclScope(S, TemplateParams))
6620 getLangOpts().CPlusPlus14
6621 ? diag::warn_cxx11_compat_variable_template
6622 : diag::ext_variable_template);
6628 "should have a 'template<>' for this decl");
6631 if (IsVariableTemplateSpecialization) {
6633 TemplateParamLists.size() > 0
6634 ? TemplateParamLists[0]->getTemplateLoc()
6636 DeclResult Res = ActOnVarTemplateSpecialization(
6637 S, D, TInfo, TemplateKWLoc, TemplateParams, SC,
6638 IsPartialSpecialization);
6641 NewVD = cast<VarDecl>(Res.
get());
6652 if (IsVariableTemplate) {
6655 TemplateParams, NewVD);
6656 NewVD->setDescribedVarTemplate(NewTemplate);
6661 if (R->getContainedDeducedType())
6662 ParsingInitForAutoVars.insert(NewVD);
6674 unsigned VDTemplateParamLists = TemplateParams ? 1 : 0;
6675 if (TemplateParamLists.size() > VDTemplateParamLists)
6676 NewVD->setTemplateParameterListsInfo(
6677 Context, TemplateParamLists.drop_back(VDTemplateParamLists));
6680 NewVD->setConstexpr(
true);
6684 if (NewVD->isStaticDataMember() && getLangOpts().CPlusPlus17)
6685 NewVD->setImplicitlyInline();
6688 diag::err_constexpr_wrong_decl_kind)
6694 if (!getLangOpts().CPlusPlus) {
6697 }
else if (CurContext->isFunctionOrMethod()) {
6700 diag::err_inline_declaration_block_scope) << Name
6704 getLangOpts().CPlusPlus17 ? diag::warn_cxx14_compat_inline_variable
6705 : diag::ext_inline_variable);
6716 if (IsLocalExternDecl) {
6718 for (
auto *B : Bindings)
6719 B->setLocalExternDecl();
6724 bool EmitTLSUnsupportedError =
false;
6737 diag::err_thread_non_global)
6740 if (getLangOpts().CUDA || getLangOpts().OpenMPIsDevice) {
6744 EmitTLSUnsupportedError =
true;
6751 diag::err_thread_unsupported);
6770 diag::warn_static_local_in_extern_inline);
6771 MaybeSuggestAddingStaticToDecl(CurFD);
6776 if (IsVariableTemplateSpecialization)
6778 << (IsPartialSpecialization ? 1 : 0)
6781 else if (IsMemberSpecialization)
6794 for (
auto *B : Bindings)
6795 B->setModulePrivate();
6800 ProcessDeclAttributes(S, NewVD, D);
6802 if (getLangOpts().CUDA || getLangOpts().OpenMPIsDevice) {
6803 if (EmitTLSUnsupportedError &&
6805 (getLangOpts().OpenMPIsDevice &&
6806 NewVD->
hasAttr<OMPDeclareTargetDeclAttr>())))
6808 diag::err_thread_unsupported);
6812 (NewVD->
hasAttr<CUDASharedAttr>() ||
6813 NewVD->
hasAttr<CUDAConstantAttr>())) {
6821 assert(!NewVD->
hasAttr<DLLImportAttr>() ||
6822 NewVD->
getAttr<DLLImportAttr>()->isInherited() ||
6827 if (getLangOpts().ObjCAutoRefCount && inferObjCARCLifetime(NewVD))
6839 Diag(E->getExprLoc(), diag::warn_asm_label_on_auto_decl) << Label;
6845 Diag(E->getExprLoc(), diag::err_asm_unknown_register_name) << Label;
6856 bool HasSizeMismatch;
6858 if (!TI.isValidGCCRegisterName(Label))
6859 Diag(E->getExprLoc(), diag::err_asm_unknown_register_name) << Label;
6860 else if (!TI.validateGlobalRegisterVariable(Label,
6863 Diag(E->getExprLoc(), diag::err_asm_invalid_global_var_reg) << Label;
6864 else if (HasSizeMismatch)
6865 Diag(E->getExprLoc(), diag::err_asm_register_size_mismatch) << Label;
6875 Context,
Label, 0));
6876 }
else if (!ExtnameUndeclaredIdentifiers.empty()) {
6877 llvm::DenseMap<IdentifierInfo*,AsmLabelAttr*>::iterator I =
6879 if (I != ExtnameUndeclaredIdentifiers.end()) {
6882 ExtnameUndeclaredIdentifiers.erase(I);
6891 ? getShadowedDeclaration(NewVD, Previous)
6899 IsMemberSpecialization ||
6900 IsVariableTemplateSpecialization);
6904 if (getLangOpts().CPlusPlus &&
6908 isDeclInScope(Previous.
getFoundDecl(), OriginalDC, S,
false));
6910 if (!getLangOpts().CPlusPlus) {
6915 CheckMemberSpecialization(NewVD, Previous))
6919 if (!Previous.
empty()) {
6938 if (!IsVariableTemplateSpecialization)
6950 if (CheckTemplateParameterList(
6956 ? TPC_ClassTemplateMember
6962 if (PrevVarTemplate &&
6970 CheckShadow(NewVD, ShadowedDecl, Previous);
6972 ProcessPragmaWeak(S, NewVD);
6978 RegisterLocallyScopedExternCDecl(NewVD, S);
6981 Decl *ManglingContextDecl;
6985 NewVD, MCtx->getManglingNumber(
6998 if (getLangOpts().CPlusPlus)
7016 ActOnDocumentableDecl(NewTemplate);
7021 CompleteMemberSpecialization(NewVD, Previous);
7039 if (isa<TypeAliasDecl>(ShadowedDecl))
7041 else if (isa<TypedefDecl>(ShadowedDecl))
7043 else if (isa<RecordDecl>(OldDC))
7082 return isa<VarDecl>(ShadowedDecl) || isa<FieldDecl>(ShadowedDecl)
7099 return isa<TypedefNameDecl>(ShadowedDecl) ? ShadowedDecl :
nullptr;
7115 if (
FieldDecl *FD = dyn_cast<FieldDecl>(ShadowedDecl)) {
7123 if (isa<CXXConstructorDecl>(NewDC))
7124 if (
const auto PVD = dyn_cast<ParmVarDecl>(D)) {
7127 ShadowingDecls.insert({PVD->getCanonicalDecl(), FD});
7132 if (
VarDecl *shadowedVar = dyn_cast<VarDecl>(ShadowedDecl))
7133 if (shadowedVar->isExternC()) {
7136 for (
auto I : shadowedVar->redecls())
7137 if (I->isFileVarDecl()) {
7145 unsigned WarningDiag = diag::warn_decl_shadow;
7147 if (isa<VarDecl>(D) && isa<VarDecl>(ShadowedDecl) && NewDC &&
7148 isa<CXXMethodDecl>(NewDC)) {
7149 if (
const auto *RD = dyn_cast<CXXRecordDecl>(NewDC->
getParent())) {
7151 if (RD->getLambdaCaptureDefault() ==
LCD_None) {
7153 const auto *LSI = cast<LambdaScopeInfo>(getCurFunction());
7156 if (CaptureLoc.isInvalid())
7157 WarningDiag = diag::warn_decl_shadow_uncaptured_local;
7161 cast<LambdaScopeInfo>(getCurFunction())
7162 ->ShadowingDecls.push_back(
7163 {cast<VarDecl>(D), cast<VarDecl>(ShadowedDecl)});
7168 if (cast<VarDecl>(ShadowedDecl)->hasLocalStorage()) {
7172 ParentDC && !ParentDC->
Equals(OldDC);
7176 if (!isa<BlockDecl>(ParentDC) && !isa<CapturedDecl>(ParentDC) &&
7203 if (getSourceManager().isInSystemMacro(R.
getNameLoc()))
7208 Diag(CaptureLoc, diag::note_var_explicitly_captured_here)
7217 const VarDecl *ShadowedDecl = Shadow.ShadowedDecl;
7222 ? diag::warn_decl_shadow_uncaptured_local
7223 : diag::warn_decl_shadow)
7224 << Shadow.VD->getDeclName()
7227 Diag(CaptureLoc, diag::note_var_explicitly_captured_here)
7228 << Shadow.VD->getDeclName() << 0;
7235 if (Diags.isIgnored(diag::warn_decl_shadow, D->
getLocation()))
7241 if (
NamedDecl *ShadowedDecl = getShadowedDeclaration(D, R))
7242 CheckShadow(D, ShadowedDecl, R);
7249 if (!getLangOpts().
CPlusPlus || ShadowingDecls.empty())
7255 const NamedDecl *D = cast<NamedDecl>(DRE->getDecl()->getCanonicalDecl());
7256 auto I = ShadowingDecls.find(D);
7257 if (I == ShadowingDecls.end())
7259 const NamedDecl *ShadowedDecl = I->second;
7261 Diag(Loc, diag::warn_modifying_shadowing_decl) << D << OldDC;
7266 ShadowingDecls.erase(I);
7271 template<
typename T>
7274 assert(S.
getLangOpts().CPlusPlus &&
"only C++ has extern \"C\"");
7295 if (!isa<VarDecl>(ND))
7305 if (isa<VarDecl>(*I)) {
7315 if (isa<VarDecl>(*I)) {
7333 assert(Prev &&
"should have found a previous declaration to diagnose");
7335 Prev = FD->getFirstDecl();
7337 Prev = cast<VarDecl>(Prev)->getFirstDecl();
7339 S.
Diag(ND->getLocation(), diag::err_extern_c_global_conflict)
7341 S.
Diag(Prev->getLocation(), diag::note_extern_c_global_conflict)
7354 template<
typename T>
7361 if (ND->getDeclContext()->getRedeclContext()->isTranslationUnit()) {
7373 if (ND->getDeclContext()->getRedeclContext()->isTranslationUnit())
7398 CheckAlignasUnderalignment(NewVD);
7420 if (getLangOpts().OpenCLVersion == 120 &&
7421 !getOpenCLOptions().
isEnabled(
"cl_clang_storage_class_specifiers") &&
7428 if (getLangOpts().OpenCL) {
7430 if (NewVD->
hasAttr<BlocksAttr>()) {
7439 Diag(NewVD->
getLocation(), diag::err_opencl_invalid_block_declaration)
7445 Diag(NewVD->
getLocation(), diag::err_opencl_extern_block_declaration);
7462 (getLangOpts().OpenCLVersion == 200 ||
7463 getLangOpts().OpenCLCPlusPlus)))) {
7465 if (getLangOpts().OpenCLVersion == 200 || getLangOpts().OpenCLCPlusPlus)
7466 Diag(NewVD->
getLocation(), diag::err_opencl_global_invalid_addr_space)
7467 << Scope <<
"global or constant";
7469 Diag(NewVD->
getLocation(), diag::err_opencl_global_invalid_addr_space)
7470 << Scope <<
"constant";
7486 if (FD && !FD->
hasAttr<OpenCLKernelAttr>()) {
7498 if (FD && FD->
hasAttr<OpenCLKernelAttr>()) {
7499 if (!getCurScope()->isFunctionScope()) {
7523 && !NewVD->
hasAttr<BlocksAttr>()) {
7527 assert(!getLangOpts().ObjCAutoRefCount);
7533 if (isVM || NewVD->
hasAttr<CleanupAttr>() ||
7535 setFunctionHasBranchProtectedScope();
7539 bool SizeIsNegative;
7540 llvm::APSInt Oversized;
7545 FixedT = FixedTInfo->
getType();
7546 else if (FixedTInfo) {
7602 if (isVM && NewVD->
hasAttr<BlocksAttr>()) {
7610 diag::err_constexpr_var_non_literal)) {
7629 CheckVariableDeclarationType(NewVD);
7637 if (Previous.
empty() &&
7641 if (!Previous.
empty()) {
7642 MergeVarDecl(NewVD, Previous);
7649 struct FindOverriddenMethod {
7675 if (MD->isVirtual() && !S->
IsOverload(Method, MD,
false))
7700 if ((OEK == OEK_All) ||
7701 (OEK == OEK_NonDeleted && !O->isDeleted()) ||
7702 (OEK == OEK_Deleted && O->isDeleted()))
7703 S.
Diag(O->getLocation(), diag::note_overridden_virtual_function);
7712 FindOverriddenMethod FOM;
7715 bool hasDeletedOverridenMethods =
false;
7716 bool hasNonDeletedOverridenMethods =
false;
7717 bool AddedAny =
false;
7722 if (!CheckOverridingFunctionReturnType(MD, OldMD) &&
7723 !CheckOverridingFunctionAttributes(MD, OldMD) &&
7724 !CheckOverridingFunctionExceptionSpec(MD, OldMD) &&
7725 !CheckIfOverriddenFunctionIsMarkedFinal(MD, OldMD)) {
7726 hasDeletedOverridenMethods |= OldMD->isDeleted();
7727 hasNonDeletedOverridenMethods |= !OldMD->isDeleted();
7734 if (hasDeletedOverridenMethods && !MD->
isDeleted()) {
7735 ReportOverrides(*
this, diag::err_non_deleted_override, MD, OEK_Deleted);
7737 if (hasNonDeletedOverridenMethods && MD->
isDeleted()) {
7738 ReportOverrides(*
this, diag::err_deleted_override, MD, OEK_NonDeleted);
7747 struct ActOnFDArgs {
7763 : Context(Context), OriginalFD(TypoFD),
7766 bool ValidateCandidate(
const TypoCorrection &candidate)
override {
7772 CDeclEnd = candidate.
end();
7773 CDecl != CDeclEnd; ++CDecl) {
7782 }
else if (!ExpectedParent) {
7791 std::unique_ptr<CorrectionCandidateCallback> clone()
override {
7792 return llvm::make_unique<DifferentNameValidatorCCC>(*this);
7804 TypoCorrectedFunctionDefinitions.insert(F);
7818 ActOnFDArgs &ExtraArgs,
bool IsLocalFriend,
Scope *S) {
7824 bool IsDefinition = ExtraArgs.D.isFunctionDefinition();
7826 IsLocalFriend ? diag::err_no_matching_local_friend :
7828 diag::err_member_decl_does_not_match;
7839 assert(!Prev.isAmbiguous() &&
7840 "Cannot have an ambiguity in previous-declaration lookup");
7842 DifferentNameValidatorCCC CCC(SemaRef.
Context, NewFD,
7844 if (!Prev.empty()) {
7846 Func != FuncEnd; ++Func) {
7853 MismatchedParams.empty() ? 0 : MismatchedParams.front() + 1;
7854 NearMatches.push_back(std::make_pair(FD, ParamNum));
7859 Prev.getLookupNameInfo(), Prev.getLookupKind(), S,
7861 IsLocalFriend ? nullptr : NewDC))) {
7864 ExtraArgs.D.getIdentifierLoc());
7868 CDeclEnd = Correction.
end();
7869 CDecl != CDeclEnd; ++CDecl) {
7876 bool wasRedeclaration = ExtraArgs.D.isRedeclaration();
7889 ExtraArgs.S, ExtraArgs.D,
7892 ExtraArgs.AddToScope);
7903 if ((*I)->getCanonicalDecl() == Canonical)
7910 SemaRef.
PDiag(IsLocalFriend
7911 ? diag::err_no_matching_local_friend_suggest
7912 : diag::err_member_decl_does_not_match_suggest)
7913 << Name << NewDC << IsDefinition);
7919 ExtraArgs.D.getIdentifierLoc());
7920 ExtraArgs.D.setRedeclaration(wasRedeclaration);
7926 << Name << NewDC << IsDefinition << NewFD->
getLocation();
7928 bool NewFDisConst =
false;
7930 NewFDisConst = NewMD->isConst();
7933 NearMatch = NearMatches.begin(), NearMatchEnd = NearMatches.end();
7934 NearMatch != NearMatchEnd; ++NearMatch) {
7937 bool FDisConst = MD && MD->
isConst();
7938 bool IsMember = MD || !IsLocalFriend;
7941 if (
unsigned Idx = NearMatch->second) {
7945 SemaRef.
Diag(Loc, IsMember ? diag::note_member_def_close_param_match
7946 : diag::note_local_decl_close_param_match)
7949 }
else if (FDisConst != NewFDisConst) {
7950 SemaRef.
Diag(FD->
getLocation(), diag::note_member_def_close_const_match)
7954 IsMember ? diag::note_member_def_close_match
7955 : diag::note_local_decl_close_match);
7962 default: llvm_unreachable(
"Unknown storage class!");
7967 diag::err_typecheck_sclass_func);
7984 diag::err_static_block_func);
8000 bool &IsVirtualOkay) {
8019 R, TInfo, SC, isInline, HasPrototype,
8041 "Constructors can only be declared in a member context");
8046 TInfo, ExplicitSpecifier, isInline,
8047 false, ConstexprKind);
8056 NameInfo, R, TInfo, isInline,
8065 IsVirtualOkay =
true;
8077 true, ConstexprKind);
8083 diag::err_conv_function_not_member);
8088 IsVirtualOkay =
true;
8091 TInfo, isInline, ExplicitSpecifier, ConstexprKind,
SourceLocation());
8097 ExplicitSpecifier, NameInfo, R, TInfo,
8128 R, TInfo, SC, isInline,
true ,
8146 StringRef SizeTypeNames[] = {
"size_t",
"intptr_t",
"uintptr_t",
"ptrdiff_t"};
8153 auto Match = llvm::find(Names, DesugaredTy.
getAsString());
8154 if (Names.end() != Match)
8159 }
while (DesugaredTy != Ty);
8215 llvm::SmallPtrSetImpl<const Type *> &ValidTypes) {
8262 S.
Diag(Loc, diag::note_entity_declared_at) << PT;
8285 HistoryStack.push_back(
nullptr);
8294 VisitStack.push_back(RecTy->
getDecl());
8295 assert(VisitStack.back() &&
"First decl null?");
8298 const Decl *Next = VisitStack.pop_back_val();
8300 assert(!HistoryStack.empty());
8302 if (
const FieldDecl *Hist = HistoryStack.pop_back_val())
8303 ValidTypes.insert(Hist->getType().getTypePtr());
8311 if (
const FieldDecl *Field = dyn_cast<FieldDecl>(Next)) {
8312 HistoryStack.push_back(Field);
8314 QualType FieldTy = Field->getType();
8318 "Unexpected type.");
8323 RD = cast<RecordDecl>(Next);
8327 VisitStack.push_back(
nullptr);
8329 for (
const auto *FD : RD->
fields()) {
8340 VisitStack.push_back(FD);
8351 diag::err_record_with_pointers_kernel_param)
8358 S.
Diag(OrigRecDecl->getLocation(), diag::note_within_field_of_type)
8359 << OrigRecDecl->getDeclName();
8364 I = HistoryStack.begin() + 1,
8365 E = HistoryStack.end();
8372 S.
Diag(FD->getLocation(), diag::note_illegal_field_declared_here)
8378 }
while (!VisitStack.empty());
8395 (LangOpts.CPlusPlus &&
8419 diag::err_invalid_thread)
8426 bool isFriend =
false;
8428 bool isMemberSpecialization =
false;
8429 bool isFunctionTemplateSpecialization =
false;
8431 bool isDependentClassScopeExplicitSpecialization =
false;
8432 bool HasExplicitTemplateArgs =
false;
8435 bool isVirtualOkay =
false;
8438 bool IsLocalExternDecl = adjustContextForLocalExternDecl(DC);
8442 if (!NewFD)
return nullptr;
8444 if (OriginalLexicalContext && OriginalLexicalContext->isObjCContainer())
8452 if (IsLocalExternDecl)
8473 if (
Parent->isInterface() && cast<CXXMethodDecl>(NewFD)->isUserProvided())
8478 if (isVirtual &&
Parent->isUnion())
8483 isMemberSpecialization =
false;
8484 isFunctionTemplateSpecialization =
false;
8490 bool Invalid =
false;
8492 MatchTemplateParametersToScopeSpecifier(
8498 TemplateParamLists, isFriend, isMemberSpecialization,
8500 if (TemplateParams->size() > 0) {
8504 if (CheckTemplateDeclScope(S, TemplateParams))
8518 if (RebuildTemplateParamsInCurrentInstantiation(TemplateParams))
8524 Name, TemplateParams,
8530 if (TemplateParamLists.size() > 1) {
8532 TemplateParamLists.drop_back(1));
8536 isFunctionTemplateSpecialization =
true;
8538 if (TemplateParamLists.size() > 0)
8544 SourceRange RemoveRange = TemplateParams->getSourceRange();
8554 InsertLoc = getLocForEndOfToken(InsertLoc);
8558 << Name << RemoveRange
8566 if (TemplateParamLists.size() > 0)
8573 if (FunctionTemplate)
8583 if (!isVirtualOkay) {
8585 diag::err_virtual_non_function);
8586 }
else if (!CurContext->isRecord()) {
8589 diag::err_virtual_out_of_class)
8595 diag::err_virtual_member_function_template)
8607 if (getLangOpts().CPlusPlus14 &&
8609 (isFriend && CurContext->isDependentContext())) &&
8629 if (CurContext->isFunctionOrMethod()) {
8632 diag::err_inline_declaration_block_scope) << Name
8642 !isa<CXXDeductionGuideDecl>(NewFD)) {
8643 if (!CurContext->isRecord()) {
8646 diag::err_explicit_out_of_class)
8648 }
else if (!isa<CXXConstructorDecl>(NewFD) &&
8649 !isa<CXXConversionDecl>(NewFD)) {
8653 diag::err_explicit_non_ctor_or_conv_function)
8666 if (isa<CXXDestructorDecl>(NewFD))
8673 if (isFunctionTemplateSpecialization) {
8676 Diag(ModulePrivateLoc, diag::err_module_private_specialization)
8681 if (FunctionTemplate)
8687 if (FunctionTemplate) {
8712 if (isa<CXXMethodDecl>(NewFD) && DC == CurContext &&
8720 if (SC ==
SC_Static && isa<CXXMethodDecl>(NewFD) &&
8721 !CurContext->isRecord()) {
8735 cast<CXXRecordDecl>(DC)->getDescribedClassTemplate()) ||
8737 ? diag::ext_static_out_of_line : diag::err_static_out_of_line)
8747 getLangOpts().CPlusPlus11 && FPT && !FPT->hasExceptionSpec())
8749 FPT->getReturnType(), FPT->getParamTypes(),
8756 isMemberSpecialization ||
8757 isFunctionTemplateSpecialization);
8765 }
else if (!ExtnameUndeclaredIdentifiers.empty()) {
8766 llvm::DenseMap<IdentifierInfo*,AsmLabelAttr*>::iterator I =
8768 if (I != ExtnameUndeclaredIdentifiers.end()) {
8771 ExtnameUndeclaredIdentifiers.erase(I);
8795 Params.push_back(Param);
8810 auto *TD = dyn_cast<
TagDecl>(NonParmDecl);
8815 if (
auto *ECD = dyn_cast<EnumConstantDecl>(NonParmDecl))
8816 TD = cast<EnumDecl>(ECD->getDeclContext());
8824 TD->setDeclContext(NewFD);
8832 if (TagDC != PrototypeTagContext)
8833 TD->setLexicalDeclContext(TagDC);
8847 for (
const auto &AI : FT->param_types()) {
8851 Params.push_back(Param);
8855 "Should not need args for typedef of non-prototype fn");
8859 NewFD->setParams(Params);
8876 !NewFD->
hasAttr<SectionAttr>()) {
8877 NewFD->
addAttr(PragmaClangTextSectionAttr::CreateImplicit(Context,
8878 PragmaClangTextSection.SectionName,
8879 PragmaClangTextSection.PragmaLocation));
8884 !NewFD->
hasAttr<SectionAttr>()) {
8886 SectionAttr::CreateImplicit(Context, SectionAttr::Declspec_allocate,
8887 CodeSegStack.CurrentValue->getString(),
8888 CodeSegStack.CurrentPragmaLocation));
8889 if (UnifySection(CodeSegStack.CurrentValue->getString(),
8898 if (!NewFD->
hasAttr<CodeSegAttr>()) {
8899 if (
Attr *SAttr = getImplicitCodeSegOrSectionAttrForFunction(NewFD,
8906 ProcessDeclAttributes(S, NewFD, D);
8908 if (getLangOpts().OpenCL) {
8914 diag::err_opencl_return_value_with_address_space);
8925 CheckMSVCRTEntryPoint(NewFD);
8929 isMemberSpecialization));
8930 else if (!Previous.
empty())
8935 "previous declaration set still overloaded");
8947 CC ==
CC_X86StdCall ? diag::warn_cconv_knr : diag::err_cconv_knr;
8957 NTCUC_FunctionReturn, NTCUK_Destruct|NTCUK_Copy);
8970 diag::ext_operator_new_delete_declared_inline)
8981 translateTemplateArguments(TemplateArgsPtr,
8984 HasExplicitTemplateArgs =
true;
8987 HasExplicitTemplateArgs =
false;
8988 }
else if (FunctionTemplate) {
8993 HasExplicitTemplateArgs =
false;
8995 assert((isFunctionTemplateSpecialization ||
8997 "should have a 'template<>' for this decl");
8999 isFunctionTemplateSpecialization =
true;
9001 }
else if (isFriend && isFunctionTemplateSpecialization) {
9008 HasExplicitTemplateArgs =
true;
9019 if (getLangOpts().CUDA & !isFunctionTemplateSpecialization)
9020 maybeAddCUDAHostDeviceAttrs(NewFD, Previous);
9026 bool InstantiationDependent =
false;
9027 if (isFunctionTemplateSpecialization && isFriend &&
9031 InstantiationDependent))) {
9032 assert(HasExplicitTemplateArgs &&
9033 "friend function specialization without template args");
9034 if (CheckDependentFunctionTemplateSpecialization(NewFD, TemplateArgs,
9037 }
else if (isFunctionTemplateSpecialization) {
9038 if (CurContext->isDependentContext() && CurContext->isRecord()
9040 isDependentClassScopeExplicitSpecialization =
true;
9042 CheckFunctionTemplateSpecialization(
9043 NewFD, (HasExplicitTemplateArgs ? &TemplateArgs :
nullptr),
9055 diag::err_explicit_specialization_inconsistent_storage_class)
9062 diag::ext_explicit_specialization_storage_class)
9066 }
else if (isMemberSpecialization && isa<CXXMethodDecl>(NewFD)) {
9067 if (CheckMemberSpecialization(NewFD, Previous))
9072 if (!isDependentClassScopeExplicitSpecialization) {
9077 CheckMSVCRTEntryPoint(NewFD);
9081 isMemberSpecialization));
9082 else if (!Previous.
empty())
9089 "previous declaration set still overloaded");
9091 NamedDecl *PrincipalDecl = (FunctionTemplate
9092 ? cast<NamedDecl>(FunctionTemplate)
9101 if (FunctionTemplate) FunctionTemplate->
setAccess(Access);
9110 if (FunctionTemplate) {
9118 ? TPC_FriendFunctionTemplateDefinition
9119 : TPC_FriendFunctionTemplate)
9123 ? TPC_ClassTemplateMember
9124 : TPC_FunctionTemplate);
9130 struct ActOnFDArgs ExtraArgs = { S, D, TemplateParamLists,
9153 (!Previous.
empty() && CurContext->isDependentContext()))) {
9172 *
this, Previous, NewFD, ExtraArgs,
false,
nullptr)) {
9173 AddToScope = ExtraArgs.AddToScope;
9180 }
else if (isFriend && cast<CXXRecordDecl>(CurContext)->isLocalClass()) {
9182 *
this, Previous, NewFD, ExtraArgs,
true, S)) {
9183 AddToScope = ExtraArgs.AddToScope;
9188 isa<CXXMethodDecl>(NewFD) && NewFD->
isOutOfLine() &&
9189 !isFriend && !isFunctionTemplateSpecialization &&
9190 !isMemberSpecialization) {
9203 ProcessPragmaWeak(S, NewFD);
9206 AddKnownFunctionAttributes(NewFD);
9208 if (NewFD->
hasAttr<OverloadableAttr>() &&
9211 diag::err_attribute_overloadable_no_prototype)
9219 EPI.ExtInfo = FT->getExtInfo();
9228 AddPushedVisibilityAttribute(NewFD);
9232 AddCFAuditedAttribute(NewFD);
9237 AddRangeBasedOptnone(NewFD);
9243 RegisterLocallyScopedExternCDecl(NewFD, S);
9251 isMemberSpecialization ||
9252 isFunctionTemplateSpecialization,
9256 if (getLangOpts().CUDA) {
9258 if (II && II->
isStr(getCudaConfigureFuncName()) &&
9263 << getCudaConfigureFuncName();
9270 if (!getLangOpts().CUDAAllowVariadicFunctions && NewFD->
isVariadic() &&
9271 (NewFD->
hasAttr<CUDADeviceAttr>() ||
9272 NewFD->
hasAttr<CUDAGlobalAttr>()) &&
9279 MarkUnusedFileScopedDecl(NewFD);
9283 if (getLangOpts().
OpenCL && NewFD->
hasAttr<OpenCLKernelAttr>()) {
9285 if ((getLangOpts().OpenCLVersion >= 120)
9300 llvm::SmallPtrSet<const Type *, 16> ValidTypes;
9304 if (getLangOpts().OpenCLCPlusPlus) {
9309 if (FunctionTemplate) {
9317 if (FunctionTemplate) {
9320 return FunctionTemplate;
9324 CompleteMemberSpecialization(NewFD, Previous);
9332 if (getLangOpts().OpenCLVersion >= 200 || getLangOpts().OpenCLCPlusPlus) {
9334 QualType ElemTy = PipeTy->getElementType();
9336 Diag(Param->getTypeSpecStartLoc(), diag::err_reference_pipe_type );
9346 if (isDependentClassScopeExplicitSpecialization) {
9350 cast<CXXMethodDecl>(NewFD),
9351 HasExplicitTemplateArgs, TemplateArgs);
9352 CurContext->addDecl(NewSpec);
9358 if (
const auto *attr = NewFD->
getAttr<AvailabilityAttr>()) {
9359 if (NewFD->
hasAttr<ConstructorAttr>()) {
9360 Diag(attr->getLocation(), diag::warn_availability_on_static_initializer)
9362 NewFD->
dropAttr<AvailabilityAttr>();
9364 if (NewFD->
hasAttr<DestructorAttr>()) {
9365 Diag(attr->getLocation(), diag::warn_availability_on_static_initializer)
9367 NewFD->
dropAttr<AvailabilityAttr>();
9389 if (
const auto *SAttr = Parent->
getAttr<CodeSegAttr>()) {
9400 while ((Parent = dyn_cast<CXXRecordDecl>(Parent->
getParent()))) {
9401 if (
const auto *SAttr = Parent->
getAttr<CodeSegAttr>()) {
9420 bool IsDefinition) {
9423 if (!FD->
hasAttr<SectionAttr>() && IsDefinition &&
9424 CodeSegStack.CurrentValue) {
9425 return SectionAttr::CreateImplicit(getASTContext(),
9426 SectionAttr::Declspec_allocate,
9427 CodeSegStack.CurrentValue->getString(),
9428 CodeSegStack.CurrentPragmaLocation);
9495 auto *PrevVD = dyn_cast<
ValueDecl>(PrevDecl);
9496 return !VD || !PrevVD ||
9497 canFullyTypeCheckRedeclaration(VD, PrevVD, VD->getType(),
9506 const auto *TA = FD->
getAttr<TargetAttr>();
9507 assert(TA &&
"MultiVersion Candidate requires a target attribute");
9508 TargetAttr::ParsedTargetAttr ParseInfo = TA->parse();
9510 enum ErrType { Feature = 0, Architecture = 1 };
9512 if (!ParseInfo.Architecture.empty() &&
9515 << Architecture << ParseInfo.Architecture;
9519 for (
const auto &Feat : ParseInfo.Features) {
9520 auto BareFeat = StringRef{Feat}.substr(1);
9521 if (Feat[0] ==
'-') {
9523 << Feature << (
"no-" + BareFeat).str();
9530 << Feature << BareFeat;
9540 switch (A->getKind()) {
9541 case attr::CPUDispatch:
9542 case attr::CPUSpecific:
9562 enum DoesntSupport {
9582 bool IsCPUSpecificCPUDispatchMVType =
9606 << IsCPUSpecificCPUDispatchMVType;
9612 return S.
Diag(NewFD->
getLocation(), diag::err_multiversion_no_other_attrs)
9613 << IsCPUSpecificCPUDispatchMVType;
9616 return S.
Diag(NewFD->
getLocation(), diag::err_multiversion_doesnt_support)
9617 << IsCPUSpecificCPUDispatchMVType << FuncTemplates;
9619 if (
const auto *NewCXXFD = dyn_cast<CXXMethodDecl>(NewFD)) {
9620 if (NewCXXFD->isVirtual())
9621 return S.
Diag(NewCXXFD->getLocation(),
9622 diag::err_multiversion_doesnt_support)
9623 << IsCPUSpecificCPUDispatchMVType << VirtFuncs;
9625 if (
const auto *NewCXXCtor = dyn_cast<CXXConstructorDecl>(NewFD))
9626 return S.
Diag(NewCXXCtor->getLocation(),
9627 diag::err_multiversion_doesnt_support)
9628 << IsCPUSpecificCPUDispatchMVType << Constructors;
9630 if (
const auto *NewCXXDtor = dyn_cast<CXXDestructorDecl>(NewFD))
9631 return S.
Diag(NewCXXDtor->getLocation(),
9632 diag::err_multiversion_doesnt_support)
9633 << IsCPUSpecificCPUDispatchMVType << Destructors;
9637 return S.
Diag(NewFD->
getLocation(), diag::err_multiversion_doesnt_support)
9638 << IsCPUSpecificCPUDispatchMVType << DeletedFuncs;
9641 return S.
Diag(NewFD->
getLocation(), diag::err_multiversion_doesnt_support)
9642 << IsCPUSpecificCPUDispatchMVType << DefaultedFuncs;
9646 return S.
Diag(NewFD->
getLocation(), diag::err_multiversion_doesnt_support)
9647 << IsCPUSpecificCPUDispatchMVType
9648 << (NewFD->
isConsteval() ? ConstevalFuncs : ConstexprFuncs);
9651 const auto *NewType = cast<FunctionType>(NewQType);
9652 QualType NewReturnType = NewType->getReturnType();
9654 if (NewReturnType->isUndeducedType())
9655 return S.
Diag(NewFD->
getLocation(), diag::err_multiversion_doesnt_support)
9656 << IsCPUSpecificCPUDispatchMVType << DeducedReturn;
9659 if (OldFD && CausesMV && OldFD->
isUsed(
false))
9660 return S.
Diag(NewFD->
getLocation(), diag::err_multiversion_after_used);
9665 const auto *OldType = cast<FunctionType>(OldQType);
9669 if (OldTypeInfo.getCC() != NewTypeInfo.
getCC())
9673 QualType OldReturnType = OldType->getReturnType();
9675 if (OldReturnType != NewReturnType)
9711 const TargetAttr *TA) {
9713 "Function lacks multiversion attribute");
9745 bool &Redeclaration,
NamedDecl *&OldDecl,
bool &MergeTypeWithPrevious,
9747 const auto *OldTA = OldFD->
getAttr<TargetAttr>();
9748 TargetAttr::ParsedTargetAttr NewParsed = NewTA->parse();
9750 llvm::sort(NewParsed.Features);
9754 if (!NewTA->isDefaultVersion() &&
9755 (!OldTA || OldTA->getFeaturesStr() == NewTA->getFeaturesStr()))
9778 if (!OldFD->
isMultiVersion() && !OldTA && NewTA->isDefaultVersion()) {
9779 Redeclaration =
true;
9792 TargetAttr::ParsedTargetAttr OldParsed =
9793 OldTA->parse(std::less<std::string>());
9795 if (OldParsed == NewParsed) {
9802 for (
const auto *FD : OldFD->
redecls()) {
9803 const auto *CurTA = FD->getAttr<TargetAttr>();
9807 (!CurTA || CurTA->isInherited())) {
9808 S.
Diag(FD->getLocation(), diag::err_multiversion_required_in_redecl)
9818 Redeclaration =
false;
9819 MergeTypeWithPrevious =
false;
9830 const CPUDispatchAttr *NewCPUDisp,
const CPUSpecificAttr *NewCPUSpec,
9831 bool &Redeclaration,
NamedDecl *&OldDecl,
bool &MergeTypeWithPrevious,
9846 TargetAttr::ParsedTargetAttr NewParsed;
9848 NewParsed = NewTA->parse();
9849 llvm::sort(NewParsed.Features);
9852 bool UseMemberUsingDeclRules =
9861 if (S.
IsOverload(NewFD, CurFD, UseMemberUsingDeclRules))
9865 const auto *CurTA = CurFD->
getAttr<TargetAttr>();
9866 if (CurTA->getFeaturesStr() == NewTA->getFeaturesStr()) {
9868 Redeclaration =
true;
9873 TargetAttr::ParsedTargetAttr CurParsed =
9874 CurTA->parse(std::less<std::string>());
9875 if (CurParsed == NewParsed) {
9882 const auto *CurCPUSpec = CurFD->
getAttr<CPUSpecificAttr>();
9883 const auto *CurCPUDisp = CurFD->
getAttr<CPUDispatchAttr>();
9888 CurFD->
hasAttr<CPUDispatchAttr>()) {
9889 if (CurCPUDisp->cpus_size() == NewCPUDisp->cpus_size() &&
9891 CurCPUDisp->cpus_begin(), CurCPUDisp->cpus_end(),
9892 NewCPUDisp->cpus_begin(),
9894 return Cur->
getName() == New->getName();
9897 Redeclaration =
true;
9910 if (CurCPUSpec->cpus_size() == NewCPUSpec->cpus_size() &&
9912 CurCPUSpec->cpus_begin(), CurCPUSpec->cpus_end(),
9913 NewCPUSpec->cpus_begin(),
9915 return Cur->
getName() == New->getName();
9918 Redeclaration =
true;
9926 if (CurII == NewII) {
9960 Redeclaration =
true;
9966 Redeclaration =
false;
9967 MergeTypeWithPrevious =
false;
9981 bool &Redeclaration,
NamedDecl *&OldDecl,
9982 bool &MergeTypeWithPrevious,
9984 const auto *NewTA = NewFD->
getAttr<TargetAttr>();
9985 const auto *NewCPUDisp = NewFD->
getAttr<CPUDispatchAttr>();
9986 const auto *NewCPUSpec = NewFD->
getAttr<CPUSpecificAttr>();
9989 if ((NewTA && NewCPUDisp) || (NewTA && NewCPUSpec) ||
9990 (NewCPUDisp && NewCPUSpec)) {
10004 S.
Diag(NewFD->
getLocation(), diag::err_multiversion_not_allowed_on_main);
10027 S.
Diag(NewFD->
getLocation(), diag::err_multiversion_required_in_redecl)
10036 Redeclaration, OldDecl,
10037 MergeTypeWithPrevious, Previous);
10043 S, OldFD, NewFD, MVType, NewTA, NewCPUDisp, NewCPUSpec, Redeclaration,
10044 OldDecl, MergeTypeWithPrevious, Previous);
10066 bool IsMemberSpecialization) {
10068 "Variably modified return types are not handled here");
10073 bool MergeTypeWithPrevious = !getLangOpts().CPlusPlus &&
10076 bool Redeclaration =
false;
10078 bool MayNeedOverloadableChecks =
false;
10082 if (!Previous.
empty()) {
10089 if (shouldLinkPossiblyHiddenDecl(Candidate, NewFD)) {
10090 Redeclaration =
true;
10091 OldDecl = Candidate;
10094 MayNeedOverloadableChecks =
true;
10095 switch (CheckOverload(S, NewFD, Previous, OldDecl,
10098 Redeclaration =
true;
10101 case Ovl_NonFunction:
10102 Redeclaration =
true;
10106 Redeclaration =
false;
10113 if (!Redeclaration &&
10115 if (!Previous.
empty()) {
10118 Redeclaration =
true;
10120 MergeTypeWithPrevious =
false;
10123 if (OldDecl->
hasAttr<OverloadableAttr>() ||
10124 NewFD->
hasAttr<OverloadableAttr>()) {
10125 if (IsOverload(NewFD, cast<FunctionDecl>(OldDecl),
false)) {
10126 MayNeedOverloadableChecks =
true;
10127 Redeclaration =
false;
10135 MergeTypeWithPrevious, Previous))
10136 return Redeclaration;
10148 if (!getLangOpts().CPlusPlus14 && MD && MD->
isConstexpr() &&
10149 !MD->
isStatic() && !isa<CXXConstructorDecl>(MD) &&
10153 OldMD = dyn_cast_or_null<CXXMethodDecl>(OldDecl->
getAsFunction());
10154 if (!OldMD || !OldMD->
isStatic()) {
10164 if (!inTemplateInstantiation()) {
10168 AddConstLoc = getLocForEndOfToken(FTL.getRParenLoc());
10176 if (Redeclaration) {
10179 if (MergeFunctionDecl(NewFD, OldDecl, S, MergeTypeWithPrevious)) {
10181 return Redeclaration;
10188 dyn_cast<FunctionTemplateDecl>(OldDecl)) {
10189 auto *OldFD = OldTemplateDecl->getTemplatedDecl();
10192 assert(NewTemplateDecl &&
"Template/non-template mismatch");
10202 NewFD->
setAccess(OldTemplateDecl->getAccess());
10203 NewTemplateDecl->
setAccess(OldTemplateDecl->getAccess());
10208 if (IsMemberSpecialization &&
10211 assert(OldTemplateDecl->isMemberSpecialization());
10214 if (OldFD->isDeleted()) {
10216 assert(OldFD->getCanonicalDecl() == OldFD);
10218 OldFD->setDeletedAsWritten(
false);
10223 if (shouldLinkDependentDeclWithPrevious(NewFD, OldDecl)) {
10224 auto *OldFD = cast<FunctionDecl>(OldDecl);
10232 }
else if (!getLangOpts().CPlusPlus && MayNeedOverloadableChecks &&
10233 !NewFD->
getAttr<OverloadableAttr>()) {
10234 assert((Previous.
empty() ||
10235 llvm::any_of(Previous,
10237 return ND->
hasAttr<OverloadableAttr>();
10239 "Non-redecls shouldn't happen without overloadable present");
10241 auto OtherUnmarkedIter = llvm::find_if(Previous, [](
const NamedDecl *ND) {
10243 return FD && !FD->
hasAttr<OverloadableAttr>();
10246 if (OtherUnmarkedIter != Previous.
end()) {
10248 diag::err_attribute_overloadable_multiple_unmarked_overloads);
10249 Diag((*OtherUnmarkedIter)->getLocation(),
10250 diag::note_attribute_overloadable_prev_overload)
10253 NewFD->
addAttr(OverloadableAttr::CreateImplicit(Context));
10262 CheckConstructor(Constructor);
10264 dyn_cast<CXXDestructorDecl>(NewFD)) {
10277 return Redeclaration;
10281 = dyn_cast<CXXConversionDecl>(NewFD)) {
10282 ActOnConversionDeclarator(Conversion);
10283 }
else if (
auto *Guide = dyn_cast<CXXDeductionGuideDecl>(NewFD)) {
10284 if (
auto *TD = Guide->getDescribedFunctionTemplate())
10285 CheckDeductionGuideTemplate(TD);
10290 Diag(Guide->getBeginLoc(), diag::err_deduction_guide_specialized)
10295 if (
CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(NewFD)) {
10296 if (!Method->isFunctionTemplateSpecialization() &&
10297 !Method->getDescribedFunctionTemplate() &&
10298 Method->isCanonicalDecl()) {
10299 if (AddOverriddenMethods(Method->getParent(), Method)) {
10307 if (Method->isStatic())
10308 checkThisInStaticMemberFunctionType(Method);
10313 CheckOverloadedOperatorDeclaration(NewFD)) {
10315 return Redeclaration;
10320 CheckLiteralOperatorDeclaration(NewFD)) {
10322 return Redeclaration;
10328 if (!CurContext->isRecord())
10329 CheckCXXDefaultArguments(NewFD);
10360 Diag(NewFD->
getLocation(), diag::warn_return_value_udt) << NewFD << R;
10373 auto HasNoexcept = [&](
QualType T) ->
bool {
10379 else if (T->isAnyPointerType())
10384 if (FPT->isNothrow())
10390 bool AnyNoexcept = HasNoexcept(FPT->getReturnType());
10391 for (
QualType T : FPT->param_types())
10392 AnyNoexcept |= HasNoexcept(T);
10395 diag::warn_cxx17_compat_exception_spec_in_signature)
10399 if (!Redeclaration && LangOpts.CUDA)
10400 checkCUDATargetOverload(NewFD, Previous);
10402 return Redeclaration;
10415 ? diag::err_static_main : diag::warn_static_main)
10422 SourceRange NoreturnRange(NoreturnLoc, getLocForEndOfToken(NoreturnLoc));
10423 Diag(NoreturnLoc, diag::ext_noreturn_main);
10424 Diag(NoreturnLoc, diag::note_main_remove_noreturn)
10434 if (getLangOpts().
OpenCL) {
10436 << FD->
hasAttr<OpenCLKernelAttr>();
10442 assert(T->
isFunctionType() &&
"function decl is not of function type");
10446 if (FT->getCallConv() !=
CC_C) {
10452 if (getLangOpts().GNUMode && !getLangOpts().CPlusPlus) {
10463 if (RTRange.isValid())
10464 Diag(RTRange.getBegin(), diag::note_main_change_return_type)
10486 if (isa<FunctionNoProtoType>(FT))
return;
10492 bool HasExtraParameters = (nparams > 3);
10504 HasExtraParameters =
false;
10506 if (HasExtraParameters) {
10519 for (
unsigned i = 0;
i < nparams; ++
i) {
10522 bool mismatch =
true;
10526 else if (Expected[i] == CharPP) {
10539 mismatch = !qs.
empty();
10544 Diag(FD->
getLocation(), diag::err_main_arg_wrong) << i << Expected[i];
10562 assert(T->
isFunctionType() &&
"function decl is not of function type");
10567 if (FT->getReturnType()->isIntegralOrEnumerationType() ||
10568 FT->getReturnType()->isAnyPointerType() ||
10569 FT->getReturnType()->isNullPtrType())
10571 if (FD->
getName() !=
"DllMain")
10589 const Expr *Culprit;
10592 Diag(Culprit->
getExprLoc(), diag::err_init_element_not_constant)
10600 class SelfReferenceChecker
10606 bool isReferenceType;
10614 SelfReferenceChecker(
Sema &S,
Decl *OrigDecl) : Inherited(S.
Context),
10615 S(S), OrigDecl(OrigDecl) {
10617 isRecordType =
false;
10618 isReferenceType =
false;
10619 isInitList =
false;
10620 if (
ValueDecl *VD = dyn_cast<ValueDecl>(OrigDecl)) {
10621 isPODType = VD->getType().isPODType(S.
Context);
10622 isRecordType = VD->getType()->isRecordType();
10623 isReferenceType = VD->getType()->isReferenceType();
10630 void CheckExpr(
Expr *E) {
10639 InitFieldIndex.push_back(0);
10640 for (
auto Child : InitList->
children()) {
10641 CheckExpr(cast<Expr>(Child));
10642 ++InitFieldIndex.back();
10644 InitFieldIndex.pop_back();
10649 bool CheckInitListMemberExpr(
MemberExpr *E,
bool CheckReference) {
10652 bool ReferenceField =
false;
10655 while (
MemberExpr *ME = dyn_cast<MemberExpr>(Base)) {
10659 Fields.push_back(FD);
10661 ReferenceField =
true;
10667 if (!DRE || DRE->
getDecl() != OrigDecl)
10671 if (CheckReference && !ReferenceField)
10676 for (
const FieldDecl *I : llvm::reverse(Fields))
10677 UsedFieldIndex.push_back(I->getFieldIndex());
10682 for (
auto UsedIter = UsedFieldIndex.begin(),
10683 UsedEnd = UsedFieldIndex.end(),
10684 OrigIter = InitFieldIndex.begin(),
10685 OrigEnd = InitFieldIndex.end();
10686 UsedIter != UsedEnd && OrigIter != OrigEnd; ++UsedIter, ++OrigIter) {
10687 if (*UsedIter < *OrigIter)
10689 if (*UsedIter > *OrigIter)
10694 HandleDeclRefExpr(DRE);
10701 void HandleValue(
Expr *E) {
10703 if (
DeclRefExpr* DRE = dyn_cast<DeclRefExpr>(E)) {
10704 HandleDeclRefExpr(DRE);
10709 Visit(CO->getCond());
10710 HandleValue(CO->getTrueExpr());
10711 HandleValue(CO->getFalseExpr());
10716 dyn_cast<BinaryConditionalOperator>(E)) {
10717 Visit(BCO->getCond());
10718 HandleValue(BCO->getFalseExpr());
10723 HandleValue(OVE->getSourceExpr());
10728 if (BO->getOpcode() == BO_Comma) {
10729 Visit(BO->getLHS());
10730 HandleValue(BO->getRHS());
10735 if (isa<MemberExpr>(E)) {
10737 if (CheckInitListMemberExpr(cast<MemberExpr>(E),
10743 while (
MemberExpr *ME = dyn_cast<MemberExpr>(Base)) {
10745 if (!isa<FieldDecl>(ME->getMemberDecl()))
10749 if (
DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Base))
10750 HandleDeclRefExpr(DRE);
10760 if (isReferenceType)
10761 HandleDeclRefExpr(E);
10770 Inherited::VisitImplicitCastExpr(E);
10775 if (CheckInitListMemberExpr(E,
true ))
10785 bool Warn = (MD && !MD->
isStatic());
10787 while (
MemberExpr *ME = dyn_cast<MemberExpr>(Base)) {
10788 if (!isa<FieldDecl>(ME->getMemberDecl()))
10793 if (
DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Base)) {
10795 HandleDeclRefExpr(DRE);
10807 if (isa<UnresolvedLookupExpr>(Callee))
10808 return Inherited::VisitCXXOperatorCallExpr(E);
10812 HandleValue(Arg->IgnoreParenImpCasts());
10817 if (E->
getOpcode() == UO_AddrOf && isRecordType &&
10829 Inherited::VisitUnaryOperator(E);
10837 if (
InitListExpr *ILE = dyn_cast<InitListExpr>(ArgExpr))
10838 if (ILE->getNumInits() == 1)
10839 ArgExpr = ILE->getInit(0);
10841 if (ICE->getCastKind() == CK_NoOp)
10842 ArgExpr = ICE->getSubExpr();
10843 HandleValue(ArgExpr);
10846 Inherited::VisitCXXConstructExpr(E);
10852 HandleValue(E->
getArg(0));
10856 Inherited::VisitCallExpr(E);
10861 HandleValue(E->
getLHS());
10866 Inherited::VisitBinaryOperator(E);
10879 if (OrigDecl != ReferenceDecl)
return;
10881 if (isReferenceType) {
10882 diag = diag::warn_uninit_self_reference_in_reference_init;
10883 }
else if (cast<VarDecl>(OrigDecl)->isStaticLocal()) {
10884 diag = diag::warn_static_self_reference_in_init;
10885 }
else if (isa<TranslationUnitDecl>(OrigDecl->
getDeclContext()) ||
10888 diag = diag::warn_uninit_self_reference_in_init;
10902 static void CheckSelfReference(
Sema &S,
Decl* OrigDecl,
Expr *E,
10906 if (isa<ParmVarDecl>(OrigDecl))
10913 if (!DirectInit && !cast<VarDecl>(OrigDecl)->getType()->
isRecordType())
10915 if (ICE->getCastKind() == CK_LValueToRValue)
10916 if (
DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(ICE->getSubExpr()))
10917 if (DRE->getDecl() == OrigDecl)
10920 SelfReferenceChecker(S, OrigDecl).CheckExpr(E);
10927 struct VarDeclOrName {
10933 return VN.VDecl ? Diag << VN.VDecl : Diag << VN.Name;
10943 bool IsInitCapture = !VDecl;
10945 "init captures are expected to be deduced prior to initialization");
10947 VarDeclOrName VN{VDecl, Name};
10950 assert(Deduced &&
"deduceVarTypeFromInitializer for non-deduced type");
10954 assert(VDecl &&
"no init for init capture deduction?");
10958 if (!isa<DeducedTemplateSpecializationType>(Deduced) ||
10969 DeduceInits = Init;
10972 if (
auto *PL = dyn_cast_or_null<ParenListExpr>(Init))
10973 DeduceInits = PL->exprs();
10976 if (isa<DeducedTemplateSpecializationType>(Deduced)) {
10977 assert(VDecl &&
"non-auto type for init capture deduction?");
10983 return DeduceTemplateSpecializationFromInitializer(TSI, Entity, Kind,
10988 if (
auto *IL = dyn_cast<InitListExpr>(Init))
10989 DeduceInits = IL->inits();
10993 if (DeduceInits.empty()) {
10997 ? diag::err_init_capture_no_expression
10998 : diag::err_auto_var_init_no_expression)
10999 << VN << Type << Range;
11003 if (DeduceInits.size() > 1) {
11004 Diag(DeduceInits[1]->getBeginLoc(),
11005 IsInitCapture ? diag::err_init_capture_multiple_expressions
11006 : diag::err_auto_var_init_multiple_expressions)
11007 << VN << Type << Range;
11011 Expr *DeduceInit = DeduceInits[0];
11012 if (DirectInit && isa<InitListExpr>(DeduceInit)) {
11014 ? diag::err_init_capture_paren_braces
11015 : diag::err_auto_var_init_paren_braces)
11016 << isa<InitListExpr>(Init) << VN << Type << Range;
11021 bool DefaultedAnyToId =
false;
11022 if (getLangOpts().DebuggerCastResultToId &&
11028 Init = Result.
get();
11029 DefaultedAnyToId =
true;
11035 if (VDecl && isa<DecompositionDecl>(VDecl) &&
11042 if (DeduceAutoType(TSI, DeduceInit, DeducedType) == DAR_Failed) {
11043 if (!IsInitCapture)
11044 DiagnoseAutoDeductionFailure(VDecl, DeduceInit);
11045 else if (isa<InitListExpr>(Init))
11047 diag::err_init_capture_deduction_failure_from_init_list)
11053 Diag(Range.
getBegin(), diag::err_init_capture_deduction_failure)
11065 if (!inTemplateInstantiation() && !DefaultedAnyToId && !IsInitCapture &&
11068 Diag(Loc, diag::warn_auto_var_is_id) << VN << Range;
11071 return DeducedType;
11079 if (DeducedType.
isNull()) {
11088 if (getLangOpts().ObjCAutoRefCount && inferObjCARCLifetime(VDecl))
11096 MergeVarDeclTypes(VDecl, Old,
false);
11100 CheckVariableDeclarationType(VDecl);
11106 if (
auto *CE = dyn_cast<ConstantExpr>(Init))
11107 Init = CE->getSubExpr();
11112 "shouldn't be called if type doesn't have a non-trivial C struct");
11113 if (
auto *ILE = dyn_cast<InitListExpr>(Init)) {
11114 for (
auto I : ILE->inits()) {
11115 if (!I->getType().hasNonTrivialToPrimitiveDefaultInitializeCUnion() &&
11116 !I->getType().hasNonTrivialToPrimitiveCopyCUnion())
11119 checkNonTrivialCUnionInInitializer(I, SL.
isValid() ? SL : Loc);
11124 if (isa<ImplicitValueInitExpr>(Init)) {
11126 checkNonTrivialCUnion(InitType, Loc, NTCUC_DefaultInitializedObject,
11134 checkNonTrivialCUnion(InitType, Loc, NTCUC_CopyInit, NTCUK_Copy);
11140 struct DiagNonTrivalCUnionDefaultInitializeVisitor
11147 DiagNonTrivalCUnionDefaultInitializeVisitor(
11150 : OrigTy(OrigTy), OrigLoc(OrigLoc), UseContext(UseContext), S(S) {}
11153 const FieldDecl *FD,
bool InNonTrivialUnion) {
11156 InNonTrivialUnion);
11157 return Super::visitWithKind(PDIK, QT, FD, InNonTrivialUnion);
11161 bool InNonTrivialUnion) {
11162 if (InNonTrivialUnion)
11164 << 1 << 0 << QT << FD->
getName();
11168 if (InNonTrivialUnion)
11170 << 1 << 0 << QT << FD->
getName();
11177 bool IsUnion =
false;
11179 IsUnion = OrigRD->isUnion();
11180 S.
Diag(OrigLoc, diag::err_non_trivial_c_union_in_invalid_context)
11181 << 0 << OrigTy << IsUnion << UseContext;
11185 InNonTrivialUnion =
true;
11188 if (InNonTrivialUnion)
11193 asDerived().visit(FD->
getType(), FD, InNonTrivialUnion);
11206 struct DiagNonTrivalCUnionDestructedTypeVisitor
11211 DiagNonTrivalCUnionDestructedTypeVisitor(
11214 : OrigTy(OrigTy), OrigLoc(OrigLoc), UseContext(UseContext), S(S) {}
11217 const FieldDecl *FD,
bool InNonTrivialUnion) {
11220 InNonTrivialUnion);
11221 return Super::visitWithKind(DK, QT, FD, InNonTrivialUnion);
11225 bool InNonTrivialUnion) {
11226 if (InNonTrivialUnion)
11228 << 1 << 1 << QT << FD->
getName();
11232 if (InNonTrivialUnion)
11234 << 1 << 1 << QT << FD->
getName();
11241 bool IsUnion =
false;
11243 IsUnion = OrigRD->isUnion();
11244 S.
Diag(OrigLoc, diag::err_non_trivial_c_union_in_invalid_context)
11245 << 1 << OrigTy << IsUnion << UseContext;
11249 InNonTrivialUnion =
true;
11252 if (InNonTrivialUnion)
11257 asDerived().visit(FD->
getType(), FD, InNonTrivialUnion);
11262 bool InNonTrivialUnion) {}
11272 struct DiagNonTrivalCUnionCopyVisitor
11279 : OrigTy(OrigTy), OrigLoc(OrigLoc), UseContext(UseContext), S(S) {}
11282 const FieldDecl *FD,
bool InNonTrivialUnion) {
11285 InNonTrivialUnion);
11286 return Super::visitWithKind(PCK, QT, FD, InNonTrivialUnion);
11290 bool InNonTrivialUnion) {
11291 if (InNonTrivialUnion)
11293 << 1 << 2 << QT << FD->
getName();
11297 if (InNonTrivialUnion)
11299 << 1 << 2 << QT << FD->
getName();
11306 bool IsUnion =
false;
11308 IsUnion = OrigRD->isUnion();
11309 S.
Diag(OrigLoc, diag::err_non_trivial_c_union_in_invalid_context)
11310 << 2 << OrigTy << IsUnion << UseContext;
11314 InNonTrivialUnion =
true;
11317 if (InNonTrivialUnion)
11322 asDerived().visit(FD->
getType(), FD, InNonTrivialUnion);
11326 const FieldDecl *FD,
bool InNonTrivialUnion) {}
11329 bool InNonTrivialUnion) {}
11343 unsigned NonTrivialKind) {
11347 "shouldn't be called if type doesn't have a non-trivial C union");
11349 if ((NonTrivialKind & NTCUK_Init) &&
11351 DiagNonTrivalCUnionDefaultInitializeVisitor(QT, Loc, UseContext, *
this)
11352 .visit(QT,
nullptr,
false);
11353 if ((NonTrivialKind & NTCUK_Destruct) &&
11355 DiagNonTrivalCUnionDestructedTypeVisitor(QT, Loc, UseContext, *
this)
11356 .visit(QT,
nullptr,
false);
11358 DiagNonTrivalCUnionCopyVisitor(QT, Loc, UseContext, *
this)
11359 .visit(QT,
nullptr,
false);
11369 CorrectDelayedTyposInExpr(Init, dyn_cast_or_null<VarDecl>(RealDecl));
11373 if (
CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(RealDecl)) {
11375 Diag(Method->getLocation(), diag::err_member_function_initialization)
11377 Method->setInvalidDecl();
11383 assert(!isa<FieldDecl>(RealDecl) &&
"field init shouldn't get here");
11394 ExprResult Res = CorrectDelayedTyposInExpr(Init, VDecl);
11401 if (DeduceVariableDeclarationType(VDecl, DirectInit, Init))
11407 Diag(VDecl->
getLocation(), diag::err_attribute_dllimport_data_definition);
11425 BaseDeclType = Array->getElementType();
11426 if (RequireCompleteType(VDecl->
getLocation(), BaseDeclType,
11427 diag::err_typecheck_decl_incomplete_type)) {
11434 diag::err_abstract_type_in_decl,
11435 AbstractVariableType))
11446 checkVarDeclRedefinition(Def, VDecl))
11449 if (getLangOpts().CPlusPlus) {
11463 Diag(Init->
getExprLoc(), diag::err_static_data_member_reinitialization)
11466 diag::note_previous_initializer)
11472 setFunctionHasBranchProtectedScope();
11474 if (DiagnoseUnexpandedParameterPack(Init, UPPC_Initializer)) {
11501 Init = Result.
get();
11517 for (
size_t Idx = 0; Idx < Args.size(); ++Idx) {
11519 Args[Idx], VDecl, [
this, Entity, Kind](
Expr *E) {
11525 }
else if (Res.
get() != Args[Idx]) {
11526 Args[Idx] = Res.
get();
11548 if (getLangOpts().CPlusPlus) {
11551 CheckSelfReference(*
this, RealDecl, Init, DirectInit);
11565 if (VDecl->
hasAttr<BlocksAttr>())
11566 checkRetainCycles(VDecl, Init);
11578 !Diags.isIgnored(diag::warn_arc_repeated_use_of_weak,
11580 FSI->markSafeWeakUse(Init);
11601 Init = Result.
get();
11614 CheckForConstantInitializer(Init, DclT);
11623 CheckForConstantInitializer(Init, DclT);
11630 isa<InitListExpr>(Init)) {
11631 const Expr *Culprit;
11634 diag::ext_aggregate_init_not_constant)
11639 if (
auto *E = dyn_cast<ExprWithCleanups>(Init))
11640 if (
auto *BE = dyn_cast<BlockExpr>(E->getSubExpr()->IgnoreParens()))
11642 BE->getBlockDecl()->setCanAvoidCopyToHeap();
11698 Diag(Loc, diag::ext_in_class_initializer_non_constant)
11703 Diag(Loc, diag::err_in_class_initializer_non_constant)
11712 if (getLangOpts().CPlusPlus11) {
11714 diag::ext_in_class_initializer_float_type_cxx11)
11717 diag::note_in_class_initializer_float_type_cxx11)
11720 Diag(VDecl->
getLocation(), diag::ext_in_class_initializer_float_type)
11724 Diag(Init->
getExprLoc(), diag::err_in_class_initializer_non_constant)
11732 Diag(VDecl->
getLocation(), diag::err_in_class_initializer_literal_type)
11751 ((!getLangOpts().CPlusPlus && !VDecl->
hasAttr<SelectAnyAttr>()) ||
11753 !(getLangOpts().CPlusPlus && VDecl->
isExternC()) &&
11767 CheckForConstantInitializer(Init, DclT);
11771 if (!InitType.
isNull() &&
11774 checkNonTrivialCUnionInInitializer(Init, Init->
getExprLoc());
11790 if (CXXDirectInit) {
11791 assert(DirectInit &&
"Call-style initializer must be direct init.");
11793 }
else if (DirectInit) {
11798 CheckCompleteVariableDeclaration(VDecl);
11813 if (
auto *DD = dyn_cast<DecompositionDecl>(D))
11814 for (
auto *BD : DD->bindings())
11818 if (ParsingInitForAutoVars.count(D)) {
11829 diag::err_typecheck_decl_incomplete_type)) {
11835 if (RequireNonAbstractType(VD->
getLocation(), Ty,
11836 diag::err_abstract_type_in_decl,
11837 AbstractVariableType)) {
11851 if (
VarDecl *Var = dyn_cast<VarDecl>(RealDecl)) {
11855 if (isa<DecompositionDecl>(RealDecl)) {
11856 Diag(Var->getLocation(), diag::err_decomp_decl_requires_init) << Var;
11857 Var->setInvalidDecl();
11862 DeduceVariableDeclarationType(Var,
false,
nullptr))
11871 if (Var->isConstexpr() && !Var->isThisDeclarationADefinition() &&
11872 !Var->isThisDeclarationADemotedDefinition()) {
11873 if (Var->isStaticDataMember()) {
11876 if (!getLangOpts().CPlusPlus17) {
11877 Diag(Var->getLocation(),
11878 diag::err_constexpr_static_mem_var_requires_init)
11879 << Var->getDeclName();
11880 Var->setInvalidDecl();
11884 Diag(Var->getLocation(), diag::err_invalid_constexpr_var_decl);
11885 Var->setInvalidDecl();
11892 if (!Var->isInvalidDecl() &&
11894 Var->getStorageClass() !=
SC_Extern && !Var->getInit()) {
11895 Diag(Var->getLocation(), diag::err_opencl_constant_no_init);
11896 Var->setInvalidDecl();
11902 Var->getType().hasNonTrivialToPrimitiveDefaultInitializeCUnion())
11903 checkNonTrivialCUnion(Var->getType(), Var->getLocation(),
11904 NTCUC_DefaultInitializedObject, NTCUK_Init);
11909 if (!Var->isStaticDataMember() || !Var->getAnyInitializer())
11925 !Var->hasLinkage() && !Var->isInvalidDecl() &&
11926 RequireCompleteType(Var->getLocation(), Type,
11927 diag::err_typecheck_decl_incomplete_type))
11928 Var->setInvalidDecl();
11932 RequireNonAbstractType(Var->getLocation(), Type,
11933 diag::err_abstract_type_in_decl,
11934 AbstractVariableType))
11935 Var->setInvalidDecl();
11938 Diag(Var->getLocation(), diag::warn_private_extern);
11939 Diag(Var->getLocation(), diag::note_private_extern);
11950 if (!Var->isInvalidDecl()) {
11953 if (RequireCompleteType(Var->getLocation(),
11954 ArrayT->getElementType(),
11955 diag::err_illegal_decl_array_incomplete_type))
11956 Var->setInvalidDecl();
11957 }
else if (Var->getStorageClass() ==
SC_Static) {
11967 if (Var->isFirstDecl())
11968 RequireCompleteType(Var->getLocation(), Type,
11969 diag::ext_typecheck_decl_incomplete_type);
11974 if (!Var->isInvalidDecl())
11975 TentativeDefinitions.push_back(Var);
11982 Diag(Var->getLocation(),
11983 diag::err_typecheck_incomplete_array_needs_initializer);
11984 Var->setInvalidDecl();
11991 Diag(Var->getLocation(), diag::err_reference_var_requires_init)
11992 << Var->getDeclName()
11993 <<
SourceRange(Var->getLocation(), Var->getLocation());
11994 Var->setInvalidDecl();
12003 if (Var->isInvalidDecl())
12006 if (!Var->hasAttr<AliasAttr>()) {
12007 if (RequireCompleteType(Var->getLocation(),
12009 diag::err_typecheck_decl_incomplete_type)) {
12010 Var->setInvalidDecl();
12018 if (RequireNonAbstractType(Var->getLocation(), Type,
12019 diag::err_abstract_type_in_decl,
12020 AbstractVariableType)) {
12021 Var->setInvalidDecl();
12035 if (getLangOpts().
CPlusPlus && Var->hasLocalStorage()) {
12038 CXXRecordDecl *CXXRecord = cast<CXXRecordDecl>(Record->getDecl());
12042 if (!CXXRecord->
isPOD())
12043 setFunctionHasBranchProtectedScope();
12048 if (getLangOpts().OpenCL &&
12070 ExprResult Init = InitSeq.Perform(*
this, Entity, Kind, None);
12072 Var->setInvalidDecl();
12073 else if (Init.
get()) {
12074 Var->setInit(MaybeCreateExprWithCleanups(Init.
get()));
12079 CheckCompleteVariableDeclaration(Var);
12137 const char *PrevSpec;
12140 getPrintingPolicy());
12148 Decl *Var = ActOnDeclarator(S, D);
12149 cast<VarDecl>(Var)->setCXXForRangeDecl(
true);
12150 FinalizeDeclaration(Var);
12151 return ActOnDeclStmt(FinalizeDeclaratorGroup(S, DS, Var), IdentLoc,
12152 AttrEnd.
isValid() ? AttrEnd : IdentLoc);
12158 if (getLangOpts().OpenCL) {
12172 if (getLangOpts().ObjC &&
12182 setFunctionHasBranchProtectedScope();
12189 setFunctionHasBranchProtectedScope();
12201 !getDiagnostics().isIgnored(diag::warn_missing_variable_declarations,
12209 Diag(var->
getLocation(), diag::warn_missing_variable_declarations) << var;
12217 const Expr *CacheCulprit =
nullptr;
12218 auto checkConstInit = [&]()
mutable {
12219 if (!CacheHasConstInit)
12222 return *CacheHasConstInit;
12231 if (getLangOpts().CPlusPlus11)
12233 }
else if (getLangOpts().CPlusPlus && var->
hasInit()) {
12234 if (!checkConstInit()) {
12250 !inTemplateInstantiation()) {
12254 Stack = &ConstSegStack;
12256 Stack = &BSSSegStack;
12259 Stack = &DataSegStack;
12263 var->
addAttr(SectionAttr::CreateImplicit(
12264 Context, SectionAttr::Declspec_allocate,
12267 if (
const SectionAttr *SA = var->
getAttr<SectionAttr>())
12268 if (UnifySection(SA->getName(), SectionFlags, var))
12274 if (CurInitSeg && var->
getInit())
12275 var->
addAttr(InitSegAttr::CreateImplicit(Context, CurInitSeg->getString(),
12280 if (!getLangOpts().CPlusPlus) {
12288 if (
auto *DD = dyn_cast<DecompositionDecl>(var))
12289 CheckCompleteDecompositionDeclaration(DD);
12294 if (var->
hasAttr<BlocksAttr>())
12295 getCurFunction()->addByrefBlockVar(var);
12308 if (Notes.size() == 1 && Notes[0].second.getDiagID() ==
12309 diag::note_invalid_subexpr_in_const_expr) {
12310 DiagLoc = Notes[0].first;
12313 Diag(DiagLoc, diag::err_constexpr_var_requires_const_init)
12315 for (
unsigned I = 0, N = Notes.size(); I != N; ++I)
12316 Diag(Notes[I].first, Notes[I].second);
12328 var->
hasAttr<RequireConstantInitAttr>()) {
12330 bool DiagErr = getLangOpts().CPlusPlus11
12333 auto attr = var->
getAttr<RequireConstantInitAttr>();
12336 Diag(attr->getLocation(), diag::note_declared_required_constant_init_here)
12337 << attr->getRange();
12342 for (
auto &it : Notes)
12343 Diag(it.first, it.second);
12346 diag::note_invalid_subexpr_in_const_expr)
12352 !getDiagnostics().isIgnored(diag::warn_global_constructor,
12359 if (!checkConstInit())
12381 if (I->isAlignmentDependent())
12395 !FD->hasAttr<DLLExportStaticLocalAttr>() &&
12396 !FD->hasAttr<DLLImportStaticLocalAttr>()) {
12397 FD = dyn_cast_or_null<FunctionDecl>(FD->getParentFunctionOrMethod());
12405 auto *NewAttr = cast<InheritableAttr>(A->clone(getASTContext()));
12406 NewAttr->setInherited(
true);
12408 }
else if (
Attr *A = FD->getAttr<DLLExportStaticLocalAttr>()) {
12409 auto *NewAttr = ::new (getASTContext()) DLLExportAttr(A->getRange(),
12411 A->getSpellingListIndex());
12412 NewAttr->setInherited(
true);
12417 if (!FD->hasAttr<DLLExportAttr>())
12418 FD->addAttr(NewAttr);
12420 }
else if (
Attr *A = FD->getAttr<DLLImportStaticLocalAttr>()) {
12421 auto *NewAttr = ::new (getASTContext()) DLLImportAttr(A->getRange(),
12423 A->getSpellingListIndex());
12424 NewAttr->setInherited(
true);
12433 ParsingInitForAutoVars.erase(ThisDecl);
12435 VarDecl *VD = dyn_cast_or_null<VarDecl>(ThisDecl);
12441 !inTemplateInstantiation() && !VD->
hasAttr<SectionAttr>()) {
12442 if (PragmaClangBSSSection.Valid)
12443 VD->
addAttr(PragmaClangBSSSectionAttr::CreateImplicit(Context,
12444 PragmaClangBSSSection.SectionName,
12445 PragmaClangBSSSection.PragmaLocation));
12446 if (PragmaClangDataSection.Valid)
12447 VD->
addAttr(PragmaClangDataSectionAttr::CreateImplicit(Context,
12448 PragmaClangDataSection.SectionName,
12449 PragmaClangDataSection.PragmaLocation));
12450 if (PragmaClangRodataSection.Valid)
12451 VD->
addAttr(PragmaClangRodataSectionAttr::CreateImplicit(Context,
12452 PragmaClangRodataSection.SectionName,
12453 PragmaClangRodataSection.PragmaLocation));
12456 if (
auto *DD = dyn_cast<DecompositionDecl>(ThisDecl)) {
12457 for (
auto *BD : DD->bindings()) {
12458 FinalizeDeclaration(BD);
12482 CheckStaticLocalForDllExport(VD);
12492 if (!getLangOpts().CUDA)
12494 if (VD->
hasAttr<CUDASharedAttr>())
12497 !(VD->
hasAttr<CUDADeviceAttr>() || VD->
hasAttr<CUDAConstantAttr>()))
12500 diag::err_device_static_local_var)
12501 << CurrentCUDATarget())
12512 if (getLangOpts().CUDA)
12513 checkAllowedCUDAInitializer(VD);
12519 if (
const auto *IA = dyn_cast_or_null<DLLImportAttr>(DLLAttr)) {
12526 bool IsClassTemplateMember =
12527 isa<ClassTemplatePartialSpecializationDecl>(Context) ||
12531 IsClassTemplateMember
12532 ? diag::warn_attribute_dllimport_static_field_definition
12533 : diag::err_attribute_dllimport_static_field_definition);
12534 Diag(IA->getLocation(), diag::note_attribute);
12535 if (!IsClassTemplateMember)
12567 AddPushedVisibilityAttribute(VD);
12570 if (VD->
isFileVarDecl() && !isa<VarTemplatePartialSpecializationDecl>(VD))
12571 MarkUnusedFileScopedDecl(VD);
12575 if (!VD->
hasAttr<TypeTagForDatatypeAttr>() ||
12579 for (
const auto *I : ThisDecl->
specific_attrs<TypeTagForDatatypeAttr>()) {
12581 if (!MagicValueExpr) {
12584 llvm::APSInt MagicValueInt;
12586 Diag(I->getRange().getBegin(),
12587 diag::err_type_tag_for_datatype_not_ice)
12591 if (MagicValueInt.getActiveBits() > 64) {
12592 Diag(I->getRange().getBegin(),
12593 diag::err_type_tag_for_datatype_too_large)
12597 uint64_t MagicValue = MagicValueInt.getZExtValue();
12598 RegisterTypeTagForDatatype(I->getArgumentKind(),
12600 I->getMatchingCType(),
12601 I->getLayoutCompatible(),
12602 I->getMustBeNull());
12607 auto *VD = dyn_cast<
VarDecl>(DD);
12620 bool DiagnosedMultipleDecomps =
false;
12622 bool DiagnosedNonDeducedAuto =
false;
12624 for (
unsigned i = 0, e = Group.size();
i != e; ++
i) {
12625 if (
Decl *D = Group[
i]) {
12628 if (
auto *DD = dyn_cast<DeclaratorDecl>(D)) {
12629 if (!FirstDeclaratorInGroup)
12630 FirstDeclaratorInGroup = DD;
12631 if (!FirstDecompDeclaratorInGroup)
12635 FirstNonDeducedAutoInGroup = DD;
12637 if (FirstDeclaratorInGroup != DD) {
12640 if (FirstDecompDeclaratorInGroup && !DiagnosedMultipleDecomps) {
12642 diag::err_decomp_decl_not_alone)
12644 << DD->getSourceRange();
12645 DiagnosedMultipleDecomps =
true;
12651 if (FirstNonDeducedAutoInGroup && !DiagnosedNonDeducedAuto) {
12653 diag::err_auto_non_deduced_not_alone)
12654 << FirstNonDeducedAutoInGroup->
getType()
12657 << DD->getSourceRange();
12658 DiagnosedNonDeducedAuto =
true;
12663 Decls.push_back(D);
12669 handleTagNumbering(Tag, S);
12670 if (FirstDeclaratorInGroup && !Tag->hasNameForLinkage() &&
12671 getLangOpts().CPlusPlus)
12676 return BuildDeclaratorGroup(Decls);
12686 if (Group.size() > 1) {
12688 VarDecl *DeducedDecl =
nullptr;
12689 for (
unsigned i = 0, e = Group.size();
i != e; ++
i) {
12700 auto *AT = dyn_cast<
AutoType>(DT);
12702 diag::err_auto_different_deductions)
12703 << (AT ? (
unsigned)AT->getKeyword() : 3)
12714 ActOnDocumentableDecls(Group);
12716 return DeclGroupPtrTy::make(
12721 ActOnDocumentableDecls(D);
12726 if (Group.empty() || !Group[0])
12729 if (Diags.isIgnored(diag::warn_doc_param_not_found,
12730 Group[0]->getLocation()) &&
12731 Diags.isIgnored(diag::warn_unknown_comment_command_name,
12732 Group[0]->getLocation()))
12735 if (Group.size() >= 2) {
12743 Decl *MaybeTagDecl = Group[0];
12744 if (MaybeTagDecl && isa<TagDecl>(MaybeTagDecl)) {
12745 Group = Group.slice(1);
12751 if (!Comments.empty() &&
12752 !Comments.back()->isAttached()) {
12760 for (
unsigned i = 0, e = Group.size();
i != e; ++
i)
12771 CheckExtraCXXDefaultArguments(D);
12793 << GetNameForDeclarator(D).getName();
12817 if (getLangOpts().CPlusPlus11) {
12819 getLangOpts().CPlusPlus17 ? diag::ext_register_storage_class
12820 : diag::warn_deprecated_register)
12823 }
else if (getLangOpts().CPlusPlus &&
12828 diag::err_invalid_storage_class_in_func_decl);
12837 << getLangOpts().CPlusPlus17;
12842 DiagnoseFunctionSpecifiers(DS);
12844 CheckFunctionOrTemplateParamDeclarator(S, D);
12853 ForVisibleRedeclaration);
12855 if (R.isSingleResult()) {
12856 NamedDecl *PrevDecl = R.getFoundDecl();
12861 PrevDecl =
nullptr;
12892 IdResolver.AddDecl(New);
12894 ProcessDeclAttributes(S, New, D);
12902 if (New->
hasAttr<BlocksAttr>()) {
12926 if (inTemplateInstantiation())
12932 Diag(
Parameter->getLocation(), diag::warn_unused_parameter)
12940 if (LangOpts.NumLargeByValueCopy == 0)
12947 if (Size > LangOpts.NumLargeByValueCopy)
12959 if (Size > LangOpts.NumLargeByValueCopy)
12970 if (getLangOpts().ObjCAutoRefCount &&
12984 NameLoc, diag::err_arc_array_param_no_ownership, T,
false));
12986 Diag(NameLoc, diag::err_arc_array_param_no_ownership)
12998 TSInfo, SC,
nullptr);
13003 NTCUC_FunctionParam, NTCUK_Destruct|NTCUK_Copy);
13008 if (!CurContext->isRecord() &&
13009 RequireNonAbstractType(NameLoc, T, diag::err_abstract_type_in_decl,
13010 AbstractParamType))
13019 diag::err_object_cannot_be_passed_returned_by_value) << 1 << T
13032 !(getLangOpts().OpenCL &&
13034 Diag(NameLoc, diag::err_arg_with_address_space);
13052 llvm::raw_svector_ostream(Code)
13062 const char* PrevSpec;
13071 FTI.
Params[
i].
Param = ActOnParamDeclarator(S, ParamD);
13081 assert(getCurFunctionDecl() ==
nullptr &&
"Function parsing confused");
13086 Decl *DP = HandleDeclarator(ParentScope, D, TemplateParameterLists);
13087 return ActOnStartOfFunctionDef(FnBodyScope, DP, SkipBody);
13091 Consumer.HandleInlineFunctionDefinition(D);
13106 if (isa<CXXMethodDecl>(FD))
13126 if (FD->
hasAttr<OpenCLKernelAttr>())
13137 if (Prev->getLexicalDeclContext()->isFunctionOrMethod())
13140 PossiblePrototype = Prev;
13168 for (
auto I : FD->
redecls()) {
13181 if (Original->isThisDeclarationADefinition()) {
13195 for (
auto I : FTD->redecls()) {
13196 auto D = cast<FunctionTemplateDecl>(I);
13198 assert(!D->isThisDeclarationADefinition() &&
13199 "More than one definition in redeclaration chain");
13202 D->getInstantiatedFromMemberTemplate()) {
13203 if (FT->isThisDeclarationADefinition()) {
13204 Definition = D->getTemplatedDecl();
13220 if (TypoCorrectedFunctionDefinitions.count(Definition))
13225 if (SkipBody && !hasVisibleDefinition(Definition) &&
13233 makeMergedDefinitionVisible(TD);
13234 makeMergedDefinitionVisible(const_cast<FunctionDecl*>(Definition));
13255 LSI->
Lambda = LambdaClass;
13273 for (
const auto &C : LambdaClass->
captures()) {
13274 if (C.capturesVariable()) {
13275 VarDecl *VD = C.getCapturedVar();
13279 const bool ByRef = C.getCaptureKind() ==
LCK_ByRef;
13281 true, C.getLocation(),
13282 C.isPackExpansion()
13284 CaptureType,
false);
13286 }
else if (C.capturesThis()) {
13302 PushFunctionScope();
13303 PushExpressionEvaluationContext(ExprEvalContexts.back().Context);
13310 FD = FunTmpl->getTemplatedDecl();
13312 FD = cast<FunctionDecl>(D);
13317 PushExpressionEvaluationContext(ExprEvalContexts.back().Context);
13320 if (
const auto *
Attr = FD->
getAttr<AliasAttr>()) {
13325 if (
const auto *
Attr = FD->
getAttr<IFuncAttr>()) {
13334 CheckForFunctionRedefinition(FD,
nullptr, SkipBody);
13356 assert(inTemplateInstantiation() &&
13357 "There should be an active template instantiation on the stack " 13358 "when instantiating a generic lambda!");
13362 PushFunctionScope();
13379 RequireCompleteType(FD->
getLocation(), ResultType,
13380 diag::err_func_def_incomplete_result))
13384 PushDeclContext(FnBodyScope, FD);
13394 auto *NonParmDecl = dyn_cast<
NamedDecl>(NPD);
13397 assert(!isa<ParmVarDecl>(NonParmDecl) &&
13398 "parameters should not be in newly created FD yet");
13401 if (NonParmDecl->getDeclName())
13402 PushOnScopeChains(NonParmDecl, FnBodyScope,
false);
13406 if (
auto *ED = dyn_cast<EnumDecl>(NonParmDecl)) {
13407 for (
auto *EI : ED->enumerators())
13408 PushOnScopeChains(EI, FnBodyScope,
false);
13415 Param->setOwningFunction(FD);
13418 if (Param->getIdentifier() && FnBodyScope) {
13419 CheckShadow(FnBodyScope, Param);
13421 PushOnScopeChains(Param, FnBodyScope);
13432 assert(!FD->
hasAttr<DLLExportAttr>());
13433 Diag(FD->
getLocation(), diag::err_attribute_dllimport_function_definition);
13439 ActOnDocumentableDecl(D);
13440 if (getCurLexicalContext()->isObjCContainer() &&
13441 getCurLexicalContext()->getDeclKind() != Decl::ObjCCategoryImpl &&
13442 getCurLexicalContext()->getDeclKind() != Decl::ObjCImplementation)
13463 for (
unsigned I = 0, E = Scope->
Returns.size(); I != E; ++I) {
13464 if (
const VarDecl *NRVOCandidate = Returns[I]->getNRVOCandidate()) {
13465 if (!NRVOCandidate->isNRVOVariable())
13466 Returns[I]->setNRVOCandidate(
nullptr);
13484 Outer.Fun.hasTrailingReturnType()) {
13485 QualType Ty = GetTypeFromParser(Outer.Fun.getTrailingReturnType());
13502 if (FD->isConstexpr())
13507 if (FD->getReturnType()->getContainedDeducedType())
13510 return Consumer.shouldSkipFunctionBody(D);
13517 FD->setHasSkippedBody();
13519 MD->setHasSkippedBody();
13524 return ActOnFinishFunctionBody(D, BodyArg,
false);
13539 bool IsLambda =
false;
13543 llvm::DenseMap<const BlockDecl *, bool> EscapeInfo;
13545 auto IsOrNestedInEscapingBlock = [&](
const BlockDecl *BD) {
13546 if (EscapeInfo.count(BD))
13547 return EscapeInfo[BD];
13559 return EscapeInfo[BD] = R;
13564 for (
const std::pair<SourceLocation, const BlockDecl *> &
P :
13566 if (IsOrNestedInEscapingBlock(P.second))
13567 S.
Diag(P.first, diag::warn_implicitly_retains_self)
13572 bool IsInstantiation) {
13578 if (getLangOpts().Coroutines && getCurFunction()->isCoroutine())
13579 CheckCompletedCoroutineBody(FD, Body);
13602 TypeLoc ResultType = getReturnTypeLoc(FD);
13610 auto *LSI = getCurLambda();
13611 if (LSI->HasImplicitReturnType) {
13612 deduceClosureReturnType(*LSI);
13618 LSI->ReturnType.isNull() ? Context.
VoidTy : LSI->ReturnType;
13642 DiagnoseSizeOfParametersAndReturnValue(FD->
parameters(),
13647 MarkVTableUsed(FD->
getLocation(), Constructor->getParent());
13649 MarkVTableUsed(FD->
getLocation(), Destructor->getParent());
13656 computeNRVO(Body, getCurFunction());
13668 if (PossiblePrototype) {
13672 TypeLoc TL = TI->getTypeLoc();
13675 diag::note_declaration_not_a_prototype)
13698 !LangOpts.CPlusPlus) {
13708 if (
const auto *CmpndBody = dyn_cast<CompoundStmt>(Body))
13709 if (!CmpndBody->body_empty())
13710 Diag(CmpndBody->body_front()->getBeginLoc(),
13711 diag::warn_dispatch_body_ignored);
13713 if (
auto *MD = dyn_cast<CXXMethodDecl>(FD)) {
13715 if (MD->isOutOfLine() && (MD = MD->getCanonicalDecl()) &&
13728 if (KeyFunction && KeyFunction->
isDefined(Definition))
13729 MarkVTableUsed(Definition->
getLocation(), MD->getParent(),
true);
13732 MarkVTableUsed(FD->
getLocation(), MD->getParent(),
true);
13737 assert((FD == getCurFunctionDecl() || getCurLambda()->CallOperator == FD) &&
13738 "Function parsing confused");
13739 }
else if (
ObjCMethodDecl *MD = dyn_cast_or_null<ObjCMethodDecl>(dcl)) {
13740 assert(MD == getCurMethodDecl() &&
"Method parsing confused");
13742 if (!MD->isInvalidDecl()) {
13743 DiagnoseSizeOfParametersAndReturnValue(MD->parameters(),
13744 MD->getReturnType(), MD);
13747 computeNRVO(Body, getCurFunction());
13749 if (getCurFunction()->ObjCShouldCallSuper) {
13750 Diag(MD->getEndLoc(), diag::warn_objc_missing_super_call)
13751 << MD->getSelector().getAsString();
13752 getCurFunction()->ObjCShouldCallSuper =
false;
13754 if (getCurFunction()->ObjCWarnForNoDesignatedInitChain) {
13756 bool isDesignated =
13758 assert(isDesignated && InitMethod);
13759 (void)isDesignated;
13762 auto IFace = MD->getClassInterface();
13765 auto SuperD = IFace->getSuperClass();
13768 return SuperD->getIdentifier() ==
13773 if (!MD->isUnavailable() && !superIsNSObject(MD)) {
13774 Diag(MD->getLocation(),
13775 diag::warn_objc_designated_init_missing_super_call);
13777 diag::note_objc_designated_init_marked_here);
13779 getCurFunction()->ObjCWarnForNoDesignatedInitChain =
false;
13781 if (getCurFunction()->ObjCWarnForNoInitDelegation) {
13783 if (!MD->isUnavailable())
13784 Diag(MD->getLocation(),
13785 diag::warn_objc_secondary_init_missing_init_call);
13786 getCurFunction()->ObjCWarnForNoInitDelegation =
false;
13793 PopFunctionScopeInfo(ActivePolicy, dcl);
13797 if (Body && getCurFunction()->HasPotentialAvailabilityViolations)
13798 DiagnoseUnguardedAvailabilityViolations(dcl);
13800 assert(!getCurFunction()->ObjCShouldCallSuper &&
13801 "This should only be set for ObjC methods, which should have been " 13802 "handled in the block above.");
13809 if (FD && isa<CXXConstructorDecl>(FD) && isa<CXXTryStmt>(Body))
13810 DiagnoseReturnInConstructorExceptionHandler(cast<CXXTryStmt>(Body));
13813 if (getCurFunction()->NeedsScopeChecking() &&
13814 !PP.isCodeCompletionEnabled())
13815 DiagnoseInvalidJumps(Body);
13818 if (!Destructor->getParent()->isDependentType())
13819 CheckDestructor(Destructor);
13821 MarkBaseAndMemberDestructorsReferenced(Destructor->getLocation(),
13822 Destructor->getParent());
13828 if (getDiagnostics().hasErrorOccurred() ||
13829 getDiagnostics().getSuppressAllDiagnostics()) {
13830 DiscardCleanupsInEvaluationContext();
13832 if (!getDiagnostics().hasUncompilableErrorOccurred() &&
13833 !isa<FunctionTemplateDecl>(dcl)) {
13836 ActivePolicy = &WP;
13840 (!CheckConstexprFunctionDecl(FD) ||
13841 !CheckConstexprFunctionBody(FD, Body)))
13844 if (FD && FD->
hasAttr<NakedAttr>()) {
13848 bool RegisterVariables =
false;
13849 if (
auto *DS = dyn_cast<DeclStmt>(S)) {
13850 for (
const auto *
Decl : DS->decls()) {
13851 if (
const auto *Var = dyn_cast<VarDecl>(
Decl)) {
13852 RegisterVariables =
13853 Var->hasAttr<AsmLabelAttr>() && !Var->hasInit();
13854 if (!RegisterVariables)
13859 if (RegisterVariables)
13861 if (!isa<AsmStmt>(S) && !isa<NullStmt>(S)) {
13862 Diag(S->getBeginLoc(), diag::err_non_asm_stmt_in_naked_function);
13863 Diag(FD->
getAttr<NakedAttr>()->getLocation(), diag::note_attribute);
13870 assert(ExprCleanupObjects.size() ==
13871 ExprEvalContexts.back().NumCleanupObjects &&
13872 "Leftover temporaries in function");
13873 assert(!Cleanup.exprNeedsCleanups() &&
"Unaccounted cleanups in function");
13874 assert(MaybeODRUseExprs.empty() &&
13875 "Leftover expressions for odr-use checking");
13878 if (!IsInstantiation)
13881 PopFunctionScopeInfo(ActivePolicy, dcl);
13885 if (getDiagnostics().hasErrorOccurred()) {
13886 DiscardCleanupsInEvaluationContext();
13898 D = TD->getTemplatedDecl();
13899 ProcessDeclAttributeList(S, D, Attrs);
13901 if (
CXXMethodDecl *Method = dyn_cast_or_null<CXXMethodDecl>(D))
13902 if (Method->isStatic())
13903 checkThisInStaticMemberFunctionAttributes(Method);
13915 Scope *BlockScope = S;
13919 Scope *ContextScope = BlockScope;
13921 ContextScope = ContextScope->
getParent();
13928 NamedDecl *ExternCPrev = findLocallyScopedExternCDecl(&II);
13932 PushOnScopeChains(ExternCPrev, BlockScope,
false);
13937 if (!isa<FunctionDecl>(ExternCPrev) ||
13939 cast<FunctionDecl>(ExternCPrev)->getType(),
13941 Diag(Loc, diag::ext_use_out_of_scope_declaration)
13942 << ExternCPrev << !getLangOpts().C99;
13943 Diag(ExternCPrev->getLocation(), diag::note_previous_declaration);
13944 return ExternCPrev;
13950 if (II.
getName().startswith(
"__builtin_"))
13951 diag_id = diag::warn_builtin_unknown;
13953 else if (getLangOpts().OpenCL)
13954 diag_id = diag::err_opencl_implicit_function_decl;
13955 else if (getLangOpts().C99)
13956 diag_id = diag::ext_implicit_function_decl;
13958 diag_id = diag::warn_implicit_function_decl;
13959 Diag(Loc, diag_id) << &II;
13965 return ExternCPrev;
13972 if (S && (Corrected =
13974 S,
nullptr, CCC, CTK_NonError)))
13975 diagnoseTypo(Corrected, PDiag(diag::note_function_suggestion),
13987 assert(!Error &&
"Error setting up implicit decl!");
14012 FunctionDecl *FD = cast<FunctionDecl>(ActOnDeclarator(BlockScope, D));
14015 AddKnownFunctionAttributes(FD);
14037 unsigned FormatIdx;
14040 if (!FD->
hasAttr<FormatAttr>()) {
14041 const char *fmt =
"printf";
14043 if (FormatIdx < NumParams &&
14046 FD->
addAttr(FormatAttr::CreateImplicit(Context,
14049 HasVAListArg ? 0 : FormatIdx+2,
14055 if (!FD->
hasAttr<FormatAttr>())
14056 FD->
addAttr(FormatAttr::CreateImplicit(Context,
14059 HasVAListArg ? 0 : FormatIdx+2,
14065 if (!FD->
hasAttr<CallbackAttr>() &&
14067 FD->
addAttr(CallbackAttr::CreateImplicit(
14068 Context, Encoding.data(), Encoding.size(), FD->
getLocation()));
14073 if (!getLangOpts().MathErrno && !FD->
hasAttr<ConstAttr>() &&
14081 if ((Trip.isGNUEnvironment() || Trip.isAndroid() || Trip.isOSMSVCRT()) &&
14083 switch (BuiltinID) {
14084 case Builtin::BI__builtin_fma:
14085 case Builtin::BI__builtin_fmaf:
14086 case Builtin::BI__builtin_fmal:
14087 case Builtin::BIfma:
14088 case Builtin::BIfmaf:
14089 case Builtin::BIfmal:
14098 !FD->
hasAttr<ReturnsTwiceAttr>())
14099 FD->
addAttr(ReturnsTwiceAttr::CreateImplicit(Context,
14108 !FD->
hasAttr<CUDADeviceAttr>() && !FD->
hasAttr<CUDAHostAttr>()) {
14112 if (getLangOpts().CUDAIsDevice !=
14123 if (getLangOpts().CXXExceptions && getLangOpts().ExternCNoUnwind &&
14126 if (!FPT || FPT->getExceptionSpecType() ==
EST_None)
14143 if (Name->
isStr(
"asprintf") || Name->
isStr(
"vasprintf")) {
14146 if (!FD->
hasAttr<FormatAttr>())
14147 FD->
addAttr(FormatAttr::CreateImplicit(Context,
14149 Name->
isStr(
"vasprintf") ? 0 : 3,
14153 if (Name->
isStr(
"__CFStringMakeConstantString")) {
14156 if (!FD->
hasAttr<FormatArgAttr>())
14164 assert(D.
getIdentifier() &&
"Wrong callback for declspec without declarator");
14165 assert(!T.
isNull() &&
"GetTypeForDeclarator() returned null type");
14168 assert(D.
isInvalidType() &&
"no declarator info for valid type");
14184 if (CurContext->isFunctionOrMethod())
14206 setTagNameForLinkagePurposes(tagFromDeclSpec, NewTD);
14226 if (BT->isInteger())
14229 Diag(UnderlyingLoc, diag::err_enum_invalid_underlying) << T;
14236 QualType EnumUnderlyingTy,
bool IsFixed,
14238 if (IsScoped != Prev->
isScoped()) {
14239 Diag(EnumLoc, diag::err_enum_redeclare_scoped_mismatch)
14245 if (IsFixed && Prev->
isFixed()) {
14251 Diag(EnumLoc, diag::err_enum_redeclare_type_mismatch)
14257 }
else if (IsFixed != Prev->
isFixed()) {
14258 Diag(EnumLoc, diag::err_enum_redeclare_fixed_mismatch)
14277 default: llvm_unreachable(
"Invalid tag kind for redecl diagnostic!");
14292 if (isa<TypedefDecl>(PrevDecl))
14293 return NTK_Typedef;
14294 else if (isa<TypeAliasDecl>(PrevDecl))
14295 return NTK_TypeAlias;
14296 else if (isa<ClassTemplateDecl>(PrevDecl))
14297 return NTK_Template;
14298 else if (isa<TypeAliasTemplateDecl>(PrevDecl))
14299 return NTK_TypeAliasTemplate;
14300 else if (isa<TemplateTemplateParmDecl>(PrevDecl))
14301 return NTK_TemplateTemplateArgument;
14306 return getLangOpts().CPlusPlus ? NTK_NonClass : NTK_NonStruct;
14308 return NTK_NonUnion;
14310 return NTK_NonEnum;
14312 llvm_unreachable(
"invalid TTK");
14337 if (OldTag != NewTag &&
14352 return getDiagnostics().isIgnored(diag::warn_struct_class_tag_mismatch,
14355 if (IsIgnoredLoc(NewTagLoc))
14358 auto IsIgnored = [&](
const TagDecl *Tag) {
14359 return IsIgnoredLoc(Tag->getLocation());
14361 while (IsIgnored(Previous)) {
14369 if (
const CXXRecordDecl *Record = dyn_cast<CXXRecordDecl>(Previous))
14370 isTemplate = Record->getDescribedClassTemplate();
14372 if (inTemplateInstantiation()) {
14373 if (OldTag != NewTag) {
14376 Diag(NewTagLoc, diag::warn_struct_class_tag_mismatch)
14384 if (isDefinition) {
14392 bool previousMismatch =
false;
14394 if (I->getTagKind() != NewTag) {
14399 if (!previousMismatch) {
14400 previousMismatch =
true;
14401 Diag(NewTagLoc, diag::warn_struct_class_previous_tag_mismatch)
14405 Diag(I->getInnerLocStart(), diag::note_struct_class_suggestion)
14418 if (PrevDef && IsIgnored(PrevDef))
14422 Diag(NewTagLoc, diag::warn_struct_class_tag_mismatch)
14429 Diag(NewTagLoc, diag::note_struct_class_suggestion)
14462 Namespaces.push_back(II);
14465 if (Lookup == Namespace)
14472 llvm::raw_svector_ostream OS(Insertion);
14475 std::reverse(Namespaces.begin(), Namespaces.end());
14476 for (
auto *II : Namespaces)
14477 OS << II->getName() <<
"::";
14490 if (OldDC->
Equals(NewDC))
14518 bool &OwnedDecl,
bool &IsDependent,
14520 bool ScopedEnumUsesClassTag,
TypeResult UnderlyingType,
14521 bool IsTypeSpecifier,
bool IsTemplateParamOrArg,
14525 assert((Name !=
nullptr || TUK == TUK_Definition) &&
14526 "Nameless record must be a definition!");
14527 assert(TemplateParameterLists.size() == 0 || TUK != TUK_Reference);
14531 bool ScopedEnum = ScopedEnumKWLoc.
isValid();
14534 bool isMemberSpecialization =
false;
14535 bool Invalid =
false;
14540 if (TemplateParameterLists.size() > 0 ||
14541 (SS.
isNotEmpty() && TUK != TUK_Reference)) {
14543 MatchTemplateParametersToScopeSpecifier(
14544 KWLoc, NameLoc, SS,
nullptr, TemplateParameterLists,
14545 TUK == TUK_Friend, isMemberSpecialization, Invalid)) {
14547 Diag(KWLoc, diag::err_enum_template);
14551 if (TemplateParams->size() > 0) {
14560 S, TagSpec, TUK, KWLoc, SS, Name, NameLoc, Attrs, TemplateParams,
14561 AS, ModulePrivateLoc,
14563 TemplateParameterLists.data(), SkipBody);
14564 return Result.
get();
14567 Diag(TemplateParams->getTemplateLoc(), diag::err_template_tag_noparams)
14569 isMemberSpecialization =
true;
14577 llvm::PointerUnion<const Type*, TypeSourceInfo*> EnumUnderlying;
14578 bool IsFixed = !UnderlyingType.
isUnset() || ScopedEnum;
14581 if (UnderlyingType.
isInvalid() || (!UnderlyingType.
get() && ScopedEnum)) {
14585 }
else if (UnderlyingType.
get()) {
14589 GetTypeFromParser(UnderlyingType.
get(), &TI);
14590 EnumUnderlying = TI;
14592 if (CheckEnumUnderlyingType(TI))
14597 UPPC_FixedUnderlyingType))
14605 if (TUK == TUK_Definition || getLangOpts().MSVCCompat)
14612 bool isStdBadAlloc =
false;
14613 bool isStdAlignValT =
false;
14616 if (TUK == TUK_Friend || TUK == TUK_Reference)
14617 Redecl = NotForRedeclaration;
14622 auto createTagFromNewDecl = [&]() ->
TagDecl * {
14623 assert(!getLangOpts().
CPlusPlus &&
"not meant for C++ usage");
14632 ScopedEnum, ScopedEnumUsesClassTag, IsFixed);
14634 if (TUK != TUK_Definition && !Invalid)
14636 if (EnumUnderlying) {
14637 EnumDecl *ED = cast<EnumDecl>(New);
14649 if (
RecordDecl *RD = dyn_cast<RecordDecl>(New)) {
14659 if (TUK == TUK_Definition && (!SkipBody || !SkipBody->
ShouldSkip)) {
14660 AddAlignmentAttributesForRecord(RD);
14661 AddMsStructLayoutForRecord(RD);
14675 goto CreateNewDecl;
14680 if (TUK == TUK_Friend || TUK == TUK_Reference) {
14681 DC = computeDeclContext(SS,
false);
14683 IsDependent =
true;
14687 DC = computeDeclContext(SS,
true);
14695 if (RequireCompleteDeclContext(SS, DC))
14700 LookupQualifiedName(Previous, DC);
14705 if (Previous.
empty()) {
14713 (TUK == TUK_Reference || TUK == TUK_Friend)) {
14714 IsDependent =
true;
14719 Diag(NameLoc, diag::err_not_tag_in_scope)
14720 << Kind << Name << DC << SS.
getRange();
14723 goto CreateNewDecl;
14730 if (TUK != TUK_Reference && TUK != TUK_Friend &&
14739 LookupName(Previous, S);
14744 (TUK == TUK_Definition || TUK == TUK_Declaration)) {
14768 if (!Previous.
empty() && TUK == TUK_Friend) {
14771 bool FriendSawTagOutsideEnclosingNamespace =
false;
14777 if (getLangOpts().MSVCCompat)
14778 FriendSawTagOutsideEnclosingNamespace =
true;
14787 if (Previous.
isSingleResult() && FriendSawTagOutsideEnclosingNamespace) {
14789 Diag(NameLoc, diag::ext_friend_tag_redecl_outside_namespace)
14798 if (!getLangOpts().CPlusPlus && TUK != TUK_Reference) {
14803 while (isa<RecordDecl>(SearchDC) || isa<EnumDecl>(SearchDC))
14811 DiagnoseTemplateParameterShadow(NameLoc, Previous.
getFoundDecl());
14816 if (getLangOpts().
CPlusPlus && Name && DC && StdNamespace &&
14817 DC->
Equals(getStdNamespace())) {
14818 if (Name->
isStr(
"bad_alloc")) {
14820 isStdBadAlloc =
true;
14825 if (Previous.
empty() && StdBadAlloc)
14826 Previous.
addDecl(getStdBadAlloc());
14827 }
else if (Name->
isStr(
"align_val_t")) {
14828 isStdAlignValT =
true;
14829 if (Previous.
empty() && StdAlignValT)
14830 Previous.
addDecl(getStdAlignValT());
14838 if (Name && Previous.
empty() &&
14839 (TUK == TUK_Reference || TUK == TUK_Friend || IsTemplateParamOrArg)) {
14840 if (Invalid)
goto CreateNewDecl;
14843 if (TUK == TUK_Reference || IsTemplateParamOrArg) {
14877 assert(TUK == TUK_Friend);
14893 LookupQualifiedName(Previous, SearchDC);
14896 LookupName(Previous, S);
14904 if (!Previous.
empty()) {
14920 TagDecl *Tag = TT->getDecl();
14923 ->
Equals(TD->getDeclContext()->getRedeclContext())) {
14936 if (
auto *Shadow = dyn_cast<UsingShadowDecl>(DirectPrevDecl)) {
14937 auto *OldTag = dyn_cast<
TagDecl>(PrevDecl);
14938 if (SS.
isEmpty() && TUK != TUK_Reference && TUK != TUK_Friend &&
14939 isDeclInScope(Shadow, SearchDC, S, isMemberSpecialization) &&
14941 *
this, OldTag->getDeclContext(), SearchDC))) {
14942 Diag(KWLoc, diag::err_using_decl_conflict_reverse);
14943 Diag(Shadow->getTargetDecl()->getLocation(),
14944 diag::note_using_decl_target);
14945 Diag(Shadow->getUsingDecl()->getLocation(), diag::note_using_decl)
14949 goto CreateNewDecl;
14953 if (
TagDecl *PrevTagDecl = dyn_cast<TagDecl>(PrevDecl)) {
14957 if (TUK == TUK_Reference || TUK == TUK_Friend ||
14958 isDeclInScope(DirectPrevDecl, SearchDC, S,
14959 SS.
isNotEmpty() || isMemberSpecialization)) {
14962 if (!isAcceptableTagRedeclaration(PrevTagDecl, Kind,
14963 TUK == TUK_Definition, KWLoc,
14965 bool SafeToContinue
14966 = (PrevTagDecl->getTagKind() !=
TTK_Enum &&
14968 if (SafeToContinue)
14969 Diag(KWLoc, diag::err_use_with_wrong_tag)
14972 PrevTagDecl->getKindName());
14974 Diag(KWLoc, diag::err_use_with_wrong_tag) << Name;
14975 Diag(PrevTagDecl->getLocation(), diag::note_previous_use);
14977 if (SafeToContinue)
14978 Kind = PrevTagDecl->getTagKind();
14988 const EnumDecl *PrevEnum = cast<EnumDecl>(PrevTagDecl);
14992 if (TUK == TUK_Reference || TUK == TUK_Friend) {
14994 Diag(ScopedEnumKWLoc, diag::err_enum_class_reference)
14997 return PrevTagDecl;
15002 EnumUnderlyingTy = TI->getType().getUnqualifiedType();
15003 else if (
const Type *T = EnumUnderlying.dyn_cast<
const Type*>())
15004 EnumUnderlyingTy =
QualType(T, 0);
15009 if (CheckEnumRedeclaration(NameLoc.
isValid() ? NameLoc : KWLoc,
15010 ScopedEnum, EnumUnderlyingTy,
15011 IsFixed, PrevEnum))
15012 return TUK == TUK_Declaration ? PrevTagDecl :
nullptr;
15021 Diag(NameLoc, diag::ext_member_redeclared);
15022 Diag(PrevTagDecl->getLocation(), diag::note_previous_declaration);
15028 if (TUK == TUK_Reference || TUK == TUK_Friend) {
15029 if (!Attrs.
empty()) {
15032 }
else if (TUK == TUK_Reference &&
15033 (PrevTagDecl->getFriendObjectKind() ==
15046 return PrevTagDecl;
15051 return PrevTagDecl;
15056 if (TUK == TUK_Definition) {
15057 if (
NamedDecl *Def = PrevTagDecl->getDefinition()) {
15061 bool IsExplicitSpecializationAfterInstantiation =
false;
15062 if (isMemberSpecialization) {
15064 IsExplicitSpecializationAfterInstantiation =
15065 RD->getTemplateSpecializationKind() !=
15067 else if (
EnumDecl *ED = dyn_cast<EnumDecl>(Def))
15068 IsExplicitSpecializationAfterInstantiation =
15069 ED->getTemplateSpecializationKind() !=
15078 if (SkipBody && !hasVisibleDefinition(Def, &Hidden)) {
15089 SkipBody->
New = createTagFromNewDecl();
15095 makeMergedDefinitionVisible(Hidden);
15099 }
else if (!IsExplicitSpecializationAfterInstantiation) {
15103 Diag(NameLoc, diag::warn_redefinition_in_param_list) << Name;
15105 Diag(NameLoc, diag::err_redefinition) << Name;
15106 notePreviousDefinition(Def,
15107 NameLoc.
isValid() ? NameLoc : KWLoc);
15119 if (TD->isBeingDefined()) {
15120 Diag(NameLoc, diag::err_nested_redefinition) << Name;
15121 Diag(PrevTagDecl->getLocation(),
15122 diag::note_previous_definition);
15136 if (TUK == TUK_Friend || TUK == TUK_Reference) {
15137 SearchDC = PrevTagDecl->getDeclContext();
15162 if ((TUK == TUK_Reference || TUK == TUK_Friend) &&
15164 NonTagKind NTK = getNonTagTypeDeclKind(PrevDecl, Kind);
15165 Diag(NameLoc, diag::err_tag_reference_non_tag) << PrevDecl << NTK
15171 }
else if (!isDeclInScope(DirectPrevDecl, SearchDC, S,
15172 SS.
isNotEmpty() || isMemberSpecialization)) {
15176 }
else if (TUK == TUK_Reference || TUK == TUK_Friend) {
15177 NonTagKind NTK = getNonTagTypeDeclKind(PrevDecl, Kind);
15178 Diag(NameLoc, diag::err_tag_reference_conflict) << NTK;
15184 }
else if (
TypedefNameDecl *TND = dyn_cast<TypedefNameDecl>(PrevDecl)) {
15186 if (isa<TypeAliasDecl>(PrevDecl)) Kind = 1;
15187 Diag(NameLoc, diag::err_tag_definition_of_typedef)
15188 << Name << Kind << TND->getUnderlyingType();
15196 Diag(NameLoc, diag::err_redefinition_different_kind) << Name;
15197 notePreviousDefinition(PrevDecl, NameLoc);
15228 cast_or_null<EnumDecl>(PrevDecl), ScopedEnum,
15229 ScopedEnumUsesClassTag, IsFixed);
15231 if (isStdAlignValT && (!StdAlignValT || getStdAlignValT()->isImplicit()))
15232 StdAlignValT = cast<EnumDecl>(New);
15235 if (TUK != TUK_Definition && !Invalid) {
15237 if (IsFixed && cast<EnumDecl>(New)->isFixed()) {
15241 else if (PrevDecl && (Def = cast<EnumDecl>(PrevDecl)->
getDefinition())) {
15242 Diag(Loc, diag::ext_forward_ref_enum_def)
15246 unsigned DiagID = diag::ext_forward_ref_enum;
15247 if (getLangOpts().MSVCCompat)
15248 DiagID = diag::ext_ms_forward_ref_enum;
15249 else if (getLangOpts().CPlusPlus)
15250 DiagID = diag::err_forward_ref_enum;
15255 if (EnumUnderlying) {
15256 EnumDecl *ED = cast<EnumDecl>(New);
15262 assert(ED->
isComplete() &&
"enum with type should be complete");
15269 if (getLangOpts().CPlusPlus) {
15272 cast_or_null<CXXRecordDecl>(PrevDecl));
15274 if (isStdBadAlloc && (!StdBadAlloc || getStdBadAlloc()->isImplicit()))
15275 StdBadAlloc = cast<CXXRecordDecl>(New);
15278 cast_or_null<RecordDecl>(PrevDecl));
15283 if (getLangOpts().
CPlusPlus && (IsTypeSpecifier || IsTemplateParamOrArg) &&
15284 TUK == TUK_Definition) {
15290 if (!Invalid && getLangOpts().
CPlusPlus && TUK == TUK_Definition &&
15302 if ((TUK == TUK_Definition || TUK == TUK_Declaration) &&
15303 diagnoseQualifiedDeclaration(SS, DC, OrigName, Loc,
15304 isMemberSpecialization))
15308 if (TemplateParameterLists.size() > 0) {
15316 if (
RecordDecl *RD = dyn_cast<RecordDecl>(New)) {
15326 if (TUK == TUK_Definition && (!SkipBody || !SkipBody->
ShouldSkip)) {
15327 AddAlignmentAttributesForRecord(RD);
15328 AddMsStructLayoutForRecord(RD);
15332 if (ModulePrivateLoc.
isValid()) {
15333 if (isMemberSpecialization)
15346 if (isMemberSpecialization && CheckMemberSpecialization(New, Previous))
15353 getNonFieldDeclScope(S)->isFunctionPrototypeScope()) {
15357 if (TUK == TUK_Definition && !IsTypeSpecifier) {
15358 Diag(Loc, diag::err_type_defined_in_param_type)
15362 }
else if (!PrevDecl) {
15378 if (TUK == TUK_Friend)
15382 if (!Invalid && SearchDC->
isRecord())
15383 SetMemberAccessSpecifier(New, PrevDecl, AS);
15386 CheckRedeclarationModuleOwnership(New, PrevDecl);
15388 if (TUK == TUK_Definition && (!SkipBody || !SkipBody->
ShouldSkip))
15391 ProcessDeclAttributeList(S, New, Attrs);
15392 AddPragmaAttributes(S, New);
15395 if (TUK == TUK_Friend) {
15404 if (
Scope *EnclosingScope = getScopeForDeclContext(S, DC))
15405 PushOnScopeChains(New, EnclosingScope,
false);
15407 S = getNonFieldDeclScope(S);
15408 PushOnScopeChains(New, S,
true);
15410 CurContext->addDecl(New);
15421 mergeDeclAttributes(New, PrevDecl);
15425 AddPushedVisibilityAttribute(New);
15428 CompleteMemberSpecialization(New, Previous);
15433 if (Invalid && getLangOpts().CPlusPlus) {
15435 if (
auto RD = dyn_cast<RecordDecl>(New))
15436 RD->completeDefinition();
15438 }
else if (SkipBody && SkipBody->
ShouldSkip) {
15446 AdjustDeclIfTemplate(TagD);
15447 TagDecl *Tag = cast<TagDecl>(TagD);
15450 PushDeclContext(S, Tag);
15452 ActOnDocumentableDecl(TagD);
15456 AddPushedVisibilityAttribute(Tag);
15461 if (!hasStructuralCompatLayout(Prev, SkipBody.
New))
15465 makeMergedDefinitionVisible(SkipBody.
Previous);
15470 assert(isa<ObjCContainerDecl>(IDecl) &&
15471 "ActOnObjCContainerStartDefinition - Not ObjCContainerDecl");
15473 assert(getContainingDC(OCD) == CurContext &&
15474 "The next DeclContext should be lexically contained in the current one.");
15481 bool IsFinalSpelledSealed,
15483 AdjustDeclIfTemplate(TagD);
15486 FieldCollector->StartClass();
15492 Record->
addAttr(new (Context)
15493 FinalAttr(FinalLoc, Context, IsFinalSpelledSealed));
15510 PushOnScopeChains(InjectedClassName, S);
15512 "Broken injected-class-name");
15517 AdjustDeclIfTemplate(TagD);
15518 TagDecl *Tag = cast<TagDecl>(TagD);
15523 assert(Tag->
isInvalidDecl() &&
"We should already have completed it");
15524 if (
RecordDecl *RD = dyn_cast<RecordDecl>(Tag))
15525 RD->completeDefinition();
15528 if (isa<CXXRecordDecl>(Tag)) {
15529 FieldCollector->FinishClass();
15535 if (getCurLexicalContext()->isObjCContainer() &&
15541 Consumer.HandleTagDeclDefinition(Tag);
15550 assert(DC == CurContext &&
"Mismatch of container contexts");
15551 OriginalLexicalContext = DC;
15552 ActOnObjCContainerFinishDefinition();
15556 ActOnObjCContainerStartDefinition(cast<Decl>(DC));
15557 OriginalLexicalContext =
nullptr;
15561 AdjustDeclIfTemplate(TagD);
15562 TagDecl *Tag = cast<TagDecl>(TagD);
15567 if (
RecordDecl *RD = dyn_cast<RecordDecl>(Tag))
15568 RD->completeDefinition();
15581 QualType FieldTy,
bool IsMsStruct,
15582 Expr *BitWidth,
bool *ZeroWidth) {
15591 if (RequireCompleteType(FieldLoc, FieldTy, diag::err_field_incomplete))
15594 return Diag(FieldLoc, diag::err_not_integral_type_bitfield)
15596 return Diag(FieldLoc, diag::err_not_integral_type_anon_bitfield)
15598 }
else if (DiagnoseUnexpandedParameterPack(const_cast<Expr *>(BitWidth),
15599 UPPC_BitFieldWidth))
15607 llvm::APSInt
Value;
15608 ExprResult ICE = VerifyIntegerConstantExpression(BitWidth, &Value);
15611 BitWidth = ICE.
get();
15613 if (Value != 0 && ZeroWidth)
15614 *ZeroWidth =
false;
15617 if (Value == 0 && FieldName)
15618 return Diag(FieldLoc, diag::err_bitfield_has_zero_width) << FieldName;
15620 if (Value.isSigned() && Value.isNegative()) {
15622 return Diag(FieldLoc, diag::err_bitfield_has_negative_width)
15623 << FieldName << Value.toString(10);
15624 return Diag(FieldLoc, diag::err_anon_bitfield_has_negative_width)
15625 << Value.toString(10);
15629 uint64_t TypeStorageSize = Context.
getTypeSize(FieldTy);
15630 uint64_t TypeWidth = Context.
getIntWidth(FieldTy);
15631 bool BitfieldIsOverwide = Value.ugt(TypeWidth);
15635 bool CStdConstraintViolation =
15636 BitfieldIsOverwide && !getLangOpts().CPlusPlus;
15637 bool MSBitfieldViolation =
15638 Value.ugt(TypeStorageSize) &&
15640 if (CStdConstraintViolation || MSBitfieldViolation) {
15641 unsigned DiagWidth =
15642 CStdConstraintViolation ? TypeWidth : TypeStorageSize;
15644 return Diag(FieldLoc, diag::err_bitfield_width_exceeds_type_width)
15645 << FieldName << (unsigned)Value.getZExtValue()
15646 << !CStdConstraintViolation << DiagWidth;
15648 return Diag(FieldLoc, diag::err_anon_bitfield_width_exceeds_type_width)
15649 << (unsigned)Value.getZExtValue() << !CStdConstraintViolation
15658 Diag(FieldLoc, diag::warn_bitfield_width_exceeds_type_width)
15659 << FieldName << (unsigned)Value.getZExtValue()
15660 << (unsigned)TypeWidth;
15662 Diag(FieldLoc, diag::warn_anon_bitfield_width_exceeds_type_width)
15663 << (unsigned)Value.getZExtValue() << (unsigned)TypeWidth;
15674 FieldDecl *Res = HandleField(S, cast_or_null<RecordDecl>(TagD),
15675 DeclStart, D, static_cast<Expr*>(BitfieldWidth),
15701 CheckExtraCXXDefaultArguments(D);
15704 UPPC_DataMemberType)) {
15715 << getLangOpts().CPlusPlus17;
15718 diag::err_invalid_thread)
15724 ForVisibleRedeclaration);
15725 LookupName(Previous, S);
15747 PrevDecl =
nullptr;
15750 if (PrevDecl && !isDeclInScope(PrevDecl, Record, S))
15751 PrevDecl =
nullptr;
15757 = CheckFieldDecl(II, T, TInfo, Record, Loc, Mutable, BitWidth, InitStyle,
15758 TSSL, AS, PrevDecl, &D);
15770 PushOnScopeChains(NewFD, S);
15790 bool Mutable,
Expr *BitWidth,
15796 bool InvalidDecl =
false;
15802 InvalidDecl =
true;
15808 if (RequireCompleteType(Loc, EltTy, diag::err_field_incomplete)) {
15811 InvalidDecl =
true;
15817 InvalidDecl =
true;
15825 Diag(Loc, diag::err_field_with_address_space);
15827 InvalidDecl =
true;
15830 if (LangOpts.OpenCL) {
15835 Diag(Loc, diag::err_opencl_type_struct_or_union_field) << T;
15837 InvalidDecl =
true;
15841 Diag(Loc, diag::err_opencl_bitfields);
15842 InvalidDecl =
true;
15847 if (!InvalidDecl && getLangOpts().
CPlusPlus && !II && BitWidth &&
15849 InvalidDecl =
true;
15850 Diag(Loc, diag::err_anon_bitfield_qualifiers);
15856 bool SizeIsNegative;
15857 llvm::APSInt Oversized;
15864 Diag(Loc, diag::warn_illegal_constant_array_size);
15865 TInfo = FixedTInfo;
15868 if (SizeIsNegative)
15869 Diag(Loc, diag::err_typecheck_negative_array_size);
15870 else if (Oversized.getBoolValue())
15871 Diag(Loc, diag::err_array_too_large)
15872 << Oversized.toString(10);
15874 Diag(Loc, diag::err_typecheck_field_variable_size);
15875 InvalidDecl =
true;
15880 if (!InvalidDecl && RequireNonAbstractType(Loc, T,
15881 diag::err_abstract_type_in_decl,
15882 AbstractFieldType))
15883 InvalidDecl =
true;
15885 bool ZeroWidth =
false;
15887 BitWidth =
nullptr;
15890 BitWidth = VerifyBitField(Loc, II, T, Record->
isMsStruct(Context), BitWidth,
15893 InvalidDecl =
true;
15894 BitWidth =
nullptr;
15900 if (!InvalidDecl && Mutable) {
15901 unsigned DiagID = 0;
15903 DiagID = getLangOpts().MSVCCompat ? diag::ext_mutable_reference
15904 : diag::err_mutable_reference;
15906 DiagID = diag::err_mutable_const;
15912 Diag(ErrLoc, DiagID);
15913 if (DiagID != diag::ext_mutable_reference) {
15915 InvalidDecl =
true;
15927 BitWidth, Mutable, InitStyle);
15931 if (PrevDecl && !isa<TagDecl>(PrevDecl)) {
15932 Diag(Loc, diag::err_duplicate_member) << II;
15937 if (!InvalidDecl && getLangOpts().
CPlusPlus) {
15947 if (CheckNontrivialField(NewFD))
15957 diag::ext_union_member_of_reference_type :
15958 diag::err_union_member_of_reference_type)
15960 if (!getLangOpts().MicrosoftExt)
15970 ProcessDeclAttributes(getCurScope(), NewFD, *D);
15973 CheckAlignasUnderalignment(NewFD);
15978 if (getLangOpts().ObjCAutoRefCount && inferObjCARCLifetime(NewFD))
15982 Diag(Loc, diag::warn_attribute_weak_on_field);
15990 assert(getLangOpts().
CPlusPlus &&
"valid check only for C++");
16010 member = CXXCopyConstructor;
16012 member = CXXDefaultConstructor;
16014 member = CXXCopyAssignment;
16016 member = CXXDestructor;
16018 if (member != CXXInvalid) {
16019 if (!getLangOpts().CPlusPlus11 &&
16027 if (getSourceManager().isInSystemHeader(Loc)) {
16028 if (!FD->
hasAttr<UnavailableAttr>())
16029 FD->
addAttr(UnavailableAttr::CreateImplicit(Context,
"",
16030 UnavailableAttr::IR_ARCFieldWithOwnership, Loc));
16036 diag::warn_cxx98_compat_nontrivial_union_or_anon_struct_member :
16037 diag::err_illegal_union_or_anon_struct_member)
16039 DiagnoseNontrivial(RDecl, member);
16040 return !getLangOpts().CPlusPlus11;
16052 switch (ivarVisibility) {
16053 default: llvm_unreachable(
"Unknown visitibility kind");
16069 Expr *BitWidth = (
Expr*)BitfieldWidth;
16081 BitWidth = VerifyBitField(Loc, II, T,
false, BitWidth).get();
16091 Diag(Loc, diag::err_ivar_reference_type);
16097 Diag(Loc, diag::err_typecheck_ivar_variable_size);
16111 dyn_cast<ObjCImplementationDecl>(EnclosingDecl)) {
16112 if (LangOpts.ObjCRuntime.isFragile()) {
16114 EnclosingContext = IMPDecl->getClassInterface();
16115 assert(EnclosingContext &&
"Implementation has no class interface!");
16118 EnclosingContext = EnclosingDecl;
16121 dyn_cast<ObjCCategoryDecl>(EnclosingDecl)) {
16122 if (LangOpts.ObjCRuntime.isFragile() || !CDecl->IsClassExtension()) {
16123 Diag(Loc, diag::err_misplaced_ivar) << CDecl->IsClassExtension();
16127 EnclosingContext = EnclosingDecl;
16132 DeclStart, Loc, II, T,
16133 TInfo, ac, (
Expr *)BitfieldWidth);
16136 NamedDecl *PrevDecl = LookupSingleName(S, II, Loc, LookupMemberName,
16137 ForVisibleRedeclaration);
16138 if (PrevDecl && isDeclInScope(PrevDecl, EnclosingContext, S)
16139 && !isa<TagDecl>(PrevDecl)) {
16140 Diag(Loc, diag::err_duplicate_member) << II;
16147 ProcessDeclAttributes(S, NewID, D);
16153 if (getLangOpts().ObjCAutoRefCount && inferObjCARCLifetime(NewID))
16163 IdResolver.AddDecl(NewID);
16166 if (LangOpts.ObjCRuntime.isNonFragile() &&
16167 !NewID->
isInvalidDecl() && isa<ObjCInterfaceDecl>(EnclosingDecl))
16168 Diag(Loc, diag::warn_ivars_in_interface);
16179 if (LangOpts.ObjCRuntime.isFragile() || AllIvarDecls.empty())
16182 Decl *ivarDecl = AllIvarDecls[AllIvarDecls.size()-1];
16190 if (!CD->IsClassExtension())
16202 DeclLoc, DeclLoc,
nullptr,
16208 AllIvarDecls.push_back(Ivar);
16215 assert(EnclosingDecl &&
"missing record or interface decl");
16220 if (!Fields.empty() && isa<ObjCContainerDecl>(EnclosingDecl)) {
16224 case Decl::ObjCCategory:
16225 Context.
ResetObjCLayout(cast<ObjCCategoryDecl>(DC)->getClassInterface());
16227 case Decl::ObjCImplementation:
16229 ResetObjCLayout(cast<ObjCImplementationDecl>(DC)->getClassInterface());
16239 unsigned NumNamedMembers = 0;
16241 for (
const auto *I : Record->
decls()) {
16242 if (
const auto *IFD = dyn_cast<IndirectFieldDecl>(I))
16243 if (IFD->getDeclName())
16260 RecFields.push_back(FD);
16280 bool IsLastField = (i + 1 == Fields.end());
16289 (Record || isa<ObjCContainerDecl>(EnclosingDecl))) {
16295 unsigned DiagID = 0;
16296 if (!Record->
isUnion() && !IsLastField) {
16299 Diag((*(i + 1))->getLocation(), diag::note_next_field_declaration);
16303 }
else if (Record->
isUnion())
16304 DiagID = getLangOpts().MicrosoftExt
16305 ? diag::ext_flexible_array_union_ms
16306 : getLangOpts().CPlusPlus
16307 ? diag::ext_flexible_array_union_gnu
16308 : diag::err_flexible_array_union;
16309 else if (NumNamedMembers < 1)
16310 DiagID = getLangOpts().MicrosoftExt
16311 ? diag::ext_flexible_array_empty_aggregate_ms
16312 : getLangOpts().CPlusPlus
16313 ? diag::ext_flexible_array_empty_aggregate_gnu
16314 : diag::err_flexible_array_empty_aggregate;
16324 if (CXXRecord && CXXRecord->getNumVBases() != 0)
16327 if (!getLangOpts().
C99)
16338 Diag(FD->
getLocation(), diag::err_flexible_array_has_nontrivial_dtor)
16353 diag::err_field_incomplete)) {
16378 if (isa<ObjCContainerDecl>(EnclosingDecl) &&
16380 diag::err_abstract_type_in_decl,
16381 AbstractIvarType)) {
16395 }
else if (getLangOpts().ObjC &&
16412 if (Record && !getLangOpts().
CPlusPlus && !FD->
hasAttr<UnavailableAttr>()) {
16434 if (RT->getDecl()->getArgPassingRestrictions() ==
16450 bool Completed =
false;
16452 if (!CXXRecord->isInvalidDecl()) {
16455 I = CXXRecord->conversion_begin(),
16456 E = CXXRecord->conversion_end(); I != E; ++I)
16457 I.setAccess((*I)->getAccess());
16460 if (!CXXRecord->isDependentType()) {
16462 AddImplicitlyDeclaredMembersToClass(CXXRecord);
16464 if (!CXXRecord->isInvalidDecl()) {
16468 if (CXXRecord->getNumVBases()) {
16470 CXXRecord->getFinalOverriders(FinalOverriders);
16472 for (CXXFinalOverriderMap::iterator M = FinalOverriders.begin(),
16473 MEnd = FinalOverriders.end();
16476 SOEnd = M->second.end();
16477 SO != SOEnd; ++SO) {
16478 assert(SO->second.size() > 0 &&
16479 "Virtual function without overriding functions?");
16480 if (SO->second.size() == 1)
16488 << (
const NamedDecl *)M->first << Record;
16489 Diag(M->first->getLocation(),
16490 diag::note_overridden_virtual_function);
16492 OM = SO->second.begin(),
16493 OMEnd = SO->second.end();
16495 Diag(OM->Method->getLocation(), diag::note_final_overrider)
16496 << (
const NamedDecl *)M->first << OM->Method->getParent();
16501 CXXRecord->completeDefinition(&FinalOverriders);
16512 ProcessDeclAttributeList(S, Record, Attrs);
16516 auto *Dtor = CXXRecord->getDestructor();
16517 if (Dtor && Dtor->isImplicit() &&
16518 ShouldDeleteSpecialMember(Dtor, CXXDestructor)) {
16519 CXXRecord->setImplicitDestructorIsDeleted();
16520 SetDeclDeleted(Dtor, CXXRecord->getLocation());
16525 CheckAlignasUnderalignment(Record);
16527 if (
const MSInheritanceAttr *IA = Record->
getAttr<MSInheritanceAttr>())
16528 checkMSInheritanceAttrOnDefinition(cast<CXXRecordDecl>(Record),
16529 IA->getRange(), IA->getBestCase(),
16530 IA->getSemanticSpelling());
16536 bool CheckForZeroSize;
16537 if (!getLangOpts().CPlusPlus) {
16538 CheckForZeroSize =
true;
16547 if (CheckForZeroSize) {
16548 bool ZeroSize =
true;
16549 bool IsEmpty =
true;
16550 unsigned NonBitFields = 0;
16553 (NonBitFields == 0 || ZeroSize) && I != E; ++I) {
16555 if (I->isUnnamedBitfield()) {
16556 if (!I->isZeroLengthBitField(Context))
16560 QualType FieldType = I->getType();
16572 diag::warn_zero_size_struct_union_in_extern_c :
16573 diag::warn_zero_size_struct_union_compat)
16574 << IsEmpty << Record->
isUnion() << (NonBitFields > 1);
16579 if (NonBitFields == 0 && !getLangOpts().CPlusPlus) {
16580 Diag(RecLoc, IsEmpty ? diag::ext_empty_struct_union :
16581 diag::ext_no_named_members_in_struct_union)
16589 ID->setEndOfDefinitionLoc(RBrac);
16591 for (
unsigned i = 0, e = RecFields.size();
i != e; ++
i) {
16593 ID->addDecl(ClsFields[
i]);
16597 if (
ID->getSuperClass())
16598 DiagnoseDuplicateIvars(
ID,
ID->getSuperClass());
16600 dyn_cast<ObjCImplementationDecl>(EnclosingDecl)) {
16601 assert(IMPDecl &&
"ActOnFields - missing ObjCImplementationDecl");
16602 for (
unsigned I = 0, N = RecFields.size(); I != N; ++I)
16605 ClsFields[I]->setLexicalDeclContext(IMPDecl);
16606 CheckImplementationIvars(IMPDecl, ClsFields, RecFields.size(), RBrac);
16607 IMPDecl->setIvarLBraceLoc(LBrac);
16608 IMPDecl->setIvarRBraceLoc(RBrac);
16610 dyn_cast<ObjCCategoryDecl>(EnclosingDecl)) {
16618 for (
unsigned i = 0, e = RecFields.size();
i != e; ++
i) {
16622 Diag(ClsFields[
i]->getLocation(),
16623 diag::err_duplicate_ivar_declaration);
16624 Diag(ClsIvar->getLocation(), diag::note_previous_definition);
16630 Diag(ClsFields[
i]->getLocation(),
16631 diag::err_duplicate_ivar_declaration);
16632 Diag(ClsExtIvar->getLocation(), diag::note_previous_definition);
16638 CDecl->addDecl(ClsFields[
i]);
16640 CDecl->setIvarLBraceLoc(LBrac);
16641 CDecl->setIvarRBraceLoc(RBrac);
16649 llvm::APSInt &
Value,
16652 "Integral type required!");
16655 if (Value.isUnsigned() || Value.isNonNegative()) {
16658 return Value.getActiveBits() <= BitWidth;
16660 return Value.getMinSignedBits() <= BitWidth;
16670 const unsigned NumTypes = 4;
16671 QualType SignedIntegralTypes[NumTypes] = {
16674 QualType UnsignedIntegralTypes[NumTypes] = {
16681 : UnsignedIntegralTypes;
16682 for (
unsigned I = 0; I != NumTypes; ++I)
16695 llvm::APSInt EnumVal(IntWidth);
16698 if (Val && DiagnoseUnexpandedParameterPack(Val, UPPC_EnumeratorValue))
16702 Val = DefaultLvalueConversion(Val).get();
16708 if (getLangOpts().CPlusPlus11 && Enum->
isFixed() &&
16709 !getLangOpts().MSVCCompat) {
16720 Val = Converted.
get();
16722 !(Val = VerifyIntegerConstantExpression(Val,
16723 &EnumVal).get())) {
16734 if (getLangOpts().MSVCCompat) {
16735 Diag(IdLoc, diag::ext_enumerator_too_large) << EltTy;
16736 Val = ImpCastExprToType(Val, EltTy, CK_IntegralCast).get();
16738 Diag(IdLoc, diag::err_enumerator_too_large) << EltTy;
16740 Val = ImpCastExprToType(Val, EltTy,
16742 CK_IntegralToBoolean : CK_IntegralCast)
16759 Diag(IdLoc, diag::ext_enum_value_not_int)
16761 << (EnumVal.isUnsigned() || EnumVal.isNonNegative());
16764 Val = ImpCastExprToType(Val, Context.
IntTy, CK_IntegralCast).get();
16773 if (Enum->isDependentType())
16775 else if (!LastEnumConst) {
16784 if (Enum->isFixed()) {
16785 EltTy = Enum->getIntegerType();
16788 EltTy = Context.
IntTy;
16792 EnumVal = LastEnumConst->getInitVal();
16794 EltTy = LastEnumConst->getType();
16797 if (EnumVal < LastEnumConst->getInitVal()) {
16809 if (T.
isNull() || Enum->isFixed()) {
16812 EnumVal = LastEnumConst->getInitVal();
16813 EnumVal = EnumVal.zext(EnumVal.getBitWidth() * 2);
16815 if (Enum->isFixed())
16817 Diag(IdLoc, diag::err_enumerator_wrapped)
16818 << EnumVal.toString(10)
16821 Diag(IdLoc, diag::ext_enumerator_increment_too_large)
16822 << EnumVal.toString(10);
16830 EnumVal = LastEnumConst->getInitVal();
16831 EnumVal.setIsSigned(EltTy->isSignedIntegerOrEnumerationType());
16832 EnumVal = EnumVal.zextOrTrunc(Context.
getIntWidth(EltTy));
16840 if (!getLangOpts().CPlusPlus && !T.
isNull())
16841 Diag(IdLoc, diag::warn_enum_value_overflow);
16842 }
else if (!getLangOpts().CPlusPlus &&
16845 Diag(IdLoc, diag::ext_enum_value_not_int)
16846 << EnumVal.toString(10) << 1;
16851 if (!EltTy->isDependentType()) {
16854 EnumVal = EnumVal.extOrTrunc(Context.
getIntWidth(EltTy));
16855 EnumVal.setIsSigned(EltTy->isSignedIntegerOrEnumerationType());
16864 if (!(getLangOpts().Modules || getLangOpts().ModulesLocalVisibility) ||
16871 NamedDecl *PrevDecl = LookupSingleName(S, II, IILoc, LookupOrdinaryName,
16872 forRedeclarationInCurContext());
16873 auto *PrevECD = dyn_cast_or_null<EnumConstantDecl>(PrevDecl);
16877 EnumDecl *PrevED = cast<EnumDecl>(PrevECD->getDeclContext());
16879 if (!PrevED->
getDeclName() && !hasVisibleDefinition(PrevED, &Hidden)) {
16892 EnumDecl *TheEnumDecl = cast<EnumDecl>(theEnumDecl);
16894 cast_or_null<EnumConstantDecl>(lastEnumConst);
16898 S = getNonFieldDeclScope(S);
16902 LookupResult R(*
this, Id, IdLoc, LookupOrdinaryName, ForVisibleRedeclaration);
16908 DiagnoseTemplateParameterShadow(IdLoc, PrevDecl);
16910 PrevDecl =
nullptr;
16923 CheckEnumConstant(TheEnumDecl, LastEnumConst, IdLoc, Id, Val);
16928 if (!TheEnumDecl->
isScoped() && isa<ValueDecl>(PrevDecl)) {
16930 CheckShadow(New, PrevDecl, R);
16935 assert((getLangOpts().
CPlusPlus || !isa<TagDecl>(PrevDecl)) &&
16936 "Received TagDecl when not in C++!");
16937 if (!isa<TagDecl>(PrevDecl) && isDeclInScope(PrevDecl, CurContext, S)) {
16938 if (isa<EnumConstantDecl>(PrevDecl))
16939 Diag(IdLoc, diag::err_redefinition_of_enumerator) <<
Id;
16941 Diag(IdLoc, diag::err_redefinition) <<
Id;
16942 notePreviousDefinition(PrevDecl, IdLoc);
16948 ProcessDeclAttributeList(S, New, Attrs);
16949 AddPragmaAttributes(S, New);
16953 PushOnScopeChains(New, S);
16955 ActOnDocumentableDecl(New);
16973 if (!BO->isAdditiveOp())
16981 InitExpr = BO->getLHS();
17018 typedef llvm::PointerUnion<EnumConstantDecl*, ECDVector*> DeclOrVector;
17019 typedef std::unordered_map<int64_t, DeclOrVector> ValueToVectorMap;
17023 llvm::APSInt Val = D->getInitVal();
17024 return Val.isSigned() ? Val.getSExtValue() : Val.getZExtValue();
17027 DuplicatesVector DupVector;
17028 ValueToVectorMap EnumMap;
17032 for (
auto *Element : Elements) {
17046 EnumMap.insert({EnumConstantToKey(ECD), ECD});
17049 if (EnumMap.size() == 0)
17053 for (
auto *Element : Elements) {
17059 auto Iter = EnumMap.find(EnumConstantToKey(ECD));
17060 if (Iter == EnumMap.end())
17063 DeclOrVector& Entry = Iter->second;
17070 auto Vec = llvm::make_unique<ECDVector>();
17072 Vec->push_back(ECD);
17079 DupVector.emplace_back(std::move(Vec));
17083 ECDVector *Vec = Entry.get<ECDVector*>();
17085 if (*Vec->begin() == ECD)
17088 Vec->push_back(ECD);
17092 for (
const auto &Vec : DupVector) {
17093 assert(Vec->size() > 1 &&
"ECDVector should have at least 2 elements.");
17096 auto *FirstECD = Vec->front();
17097 S.
Diag(FirstECD->getLocation(), diag::warn_duplicate_enum_values)
17098 << FirstECD << FirstECD->getInitVal().toString(10)
17099 << FirstECD->getSourceRange();
17103 for (
auto *ECD : llvm::make_range(Vec->begin() + 1, Vec->end()))
17104 S.
Diag(ECD->getLocation(), diag::note_duplicate_element)
17105 << ECD << ECD->getInitVal().toString(10)
17106 << ECD->getSourceRange();
17111 bool AllowMask)
const {
17112 assert(ED->
isClosedFlag() &&
"looking for value in non-flag or open enum");
17115 auto R = FlagBitsCache.insert(std::make_pair(ED, llvm::APInt()));
17116 llvm::APInt &FlagBits = R.first->second;
17120 const auto &EVal = E->getInitVal();
17122 if (EVal.isPowerOf2())
17123 FlagBits = FlagBits.zextOrSelf(EVal.getBitWidth()) | EVal;
17135 llvm::APInt FlagMask = ~FlagBits.zextOrTrunc(Val.getBitWidth());
17136 return !(FlagMask & Val) || (AllowMask && !(FlagMask & ~Val));
17142 EnumDecl *Enum = cast<EnumDecl>(EnumDeclX);
17145 ProcessDeclAttributeList(S, Enum, Attrs);
17148 for (
unsigned i = 0, e = Elements.size();
i != e; ++
i) {
17150 cast_or_null<EnumConstantDecl>(Elements[
i]);
17151 if (!ECD)
continue;
17169 unsigned NumNegativeBits = 0;
17170 unsigned NumPositiveBits = 0;
17173 bool AllElementsInt =
true;
17175 for (
unsigned i = 0, e = Elements.size();
i != e; ++
i) {
17177 cast_or_null<EnumConstantDecl>(Elements[
i]);
17178 if (!ECD)
continue;
17180 const llvm::APSInt &InitVal = ECD->
getInitVal();
17183 if (InitVal.isUnsigned() || InitVal.isNonNegative())
17184 NumPositiveBits =
std::max(NumPositiveBits,
17185 (
unsigned)InitVal.getActiveBits());
17187 NumNegativeBits =
std::max(NumNegativeBits,
17188 (
unsigned)InitVal.getMinSignedBits());
17191 if (AllElementsInt)
17197 unsigned BestWidth;
17210 bool Packed = Enum->
hasAttr<PackedAttr>();
17213 if (LangOpts.ShortEnums)
17223 BestPromotionType = BestType;
17227 else if (NumNegativeBits) {
17231 if (Packed && NumNegativeBits <= CharWidth && NumPositiveBits < CharWidth) {
17233 BestWidth = CharWidth;
17234 }
else if (Packed && NumNegativeBits <= ShortWidth &&
17235 NumPositiveBits < ShortWidth) {
17237 BestWidth = ShortWidth;
17238 }
else if (NumNegativeBits <= IntWidth && NumPositiveBits < IntWidth) {
17239 BestType = Context.
IntTy;
17240 BestWidth = IntWidth;
17244 if (NumNegativeBits <= BestWidth && NumPositiveBits < BestWidth) {
17245 BestType = Context.
LongTy;
17249 if (NumNegativeBits > BestWidth || NumPositiveBits >= BestWidth)
17254 BestPromotionType = (BestWidth <= IntWidth ? Context.
IntTy : BestType);
17259 if (Packed && NumPositiveBits <= CharWidth) {
17261 BestPromotionType = Context.
IntTy;
17262 BestWidth = CharWidth;
17263 }
else if (Packed && NumPositiveBits <= ShortWidth) {
17265 BestPromotionType = Context.
IntTy;
17266 BestWidth = ShortWidth;
17267 }
else if (NumPositiveBits <= IntWidth) {
17269 BestWidth = IntWidth;
17271 = (NumPositiveBits == BestWidth || !getLangOpts().CPlusPlus)
17273 }
else if (NumPositiveBits <=
17277 = (NumPositiveBits == BestWidth || !getLangOpts().CPlusPlus)
17281 assert(NumPositiveBits <= BestWidth &&
17282 "How could an initializer get larger than ULL?");
17285 = (NumPositiveBits == BestWidth || !getLangOpts().CPlusPlus)
17292 for (
auto *D : Elements) {
17293 auto *ECD = cast_or_null<EnumConstantDecl>(D);
17294 if (!ECD)
continue;
17303 llvm::APSInt InitVal = ECD->getInitVal();
17313 NewTy = Context.
IntTy;
17314 NewWidth = IntWidth;
17316 }
else if (ECD->getType() == BestType) {
17318 if (getLangOpts().CPlusPlus)
17322 ECD->setType(EnumType);
17326 NewWidth = BestWidth;
17331 InitVal = InitVal.extOrTrunc(NewWidth);
17332 InitVal.setIsSigned(NewSign);
17333 ECD->setInitVal(InitVal);
17336 if (ECD->getInitExpr() &&
17337 !Context.
hasSameType(NewTy, ECD->getInitExpr()->getType()))
17340 ECD->getInitExpr(),
17343 if (getLangOpts().CPlusPlus)
17347 ECD->setType(EnumType);
17349 ECD->setType(NewTy);
17353 NumPositiveBits, NumNegativeBits);
17358 for (
Decl *D : Elements) {
17360 if (!ECD)
continue;
17363 if (InitVal != 0 && !InitVal.isPowerOf2() &&
17364 !IsValueInFlagEnum(Enum, InitVal,
true))
17372 CheckAlignasUnderalignment(Enum);
17381 AsmString, StartLoc,
17383 CurContext->addDecl(New);
17392 NamedDecl *PrevDecl = LookupSingleName(TUScope, Name, NameLoc,
17393 LookupOrdinaryName);
17394 AsmLabelAttr *
Attr =
17395 AsmLabelAttr::CreateImplicit(Context, AliasName->
getName(), AliasNameLoc);
17401 if (PrevDecl && (isa<FunctionDecl>(PrevDecl) || isa<VarDecl>(PrevDecl))) {
17405 Diag(PrevDecl->
getLocation(), diag::warn_redefine_extname_not_applied)
17406 << (isa<FunctionDecl>(PrevDecl) ? 0 : 1) << PrevDecl;
17409 (
void)ExtnameUndeclaredIdentifiers.insert(std::make_pair(Name, Attr));
17415 Decl *PrevDecl = LookupSingleName(TUScope, Name, NameLoc, LookupOrdinaryName);
17418 PrevDecl->
addAttr(WeakAttr::CreateImplicit(Context, PragmaLoc));
17420 (void)WeakUndeclaredIdentifiers.insert(
17421 std::pair<IdentifierInfo*,WeakInfo>
17431 Decl *PrevDecl = LookupSingleName(TUScope, AliasName, AliasNameLoc,
17432 LookupOrdinaryName);
17435 if (PrevDecl && (isa<FunctionDecl>(PrevDecl) || isa<VarDecl>(PrevDecl))) {
17436 if (!PrevDecl->
hasAttr<AliasAttr>())
17437 if (
NamedDecl *ND = dyn_cast<NamedDecl>(PrevDecl))
17438 DeclApplyPragmaWeak(TUScope, ND, W);
17440 (void)WeakUndeclaredIdentifiers.insert(
17441 std::pair<IdentifierInfo*,WeakInfo>(AliasName, W));
17446 return (dyn_cast_or_null<ObjCContainerDecl>(CurContext));
VarTemplateDecl * getDescribedVarTemplate() const
Retrieves the variable template that is described by this variable declaration.
A call to an overloaded operator written using operator syntax.
SourceLocation getLoc() const
getLoc - Returns the main location of the declaration name.
const IncompleteArrayType * getAsIncompleteArrayType(QualType T) const
Defines the clang::ASTContext interface.
bool isNonWeakInMRRWithObjCWeak(const ASTContext &Context) const
QualType getDeducedType() const
Get the type deduced for this placeholder type, or null if it's either not been deduced or was deduce...
SourceLocation getBeginLoc() const LLVM_READONLY
bool isCallToStdMove() const
void setScopeInfo(unsigned scopeDepth, unsigned parameterIndex)
PragmaStack< StringLiteral * > CodeSegStack
const char * getHeaderName(unsigned ID) const
If this is a library function that comes from a specific header, retrieve that header name...
NamedDecl * getTargetDecl() const
Gets the underlying declaration which has been brought into the local scope.
The lookup results will be used for redeclaration of a name, if an entity by that name already exists...
bool RequireNonAbstractType(SourceLocation Loc, QualType T, TypeDiagnoser &Diagnoser)
bool mightBeUsableInConstantExpressions(ASTContext &C) const
Determine whether this variable's value might be usable in a constant expression, according to the re...
static StringRef getHeaderName(Builtin::Context &BuiltinInfo, unsigned ID, ASTContext::GetBuiltinTypeError Error)
void setImplicit(bool I=true)
Represents a function declaration or definition.
void CheckShadow(NamedDecl *D, NamedDecl *ShadowedDecl, const LookupResult &R)
Diagnose variable or built-in function shadowing.
ParsedType CreateParsedType(QualType T, TypeSourceInfo *TInfo)
Package the given type and TSI into a ParsedType.
FunctionTemplateDecl * getTemplate() const
Retrieve the template from which this function was specialized.
Name lookup found a set of overloaded functions that met the criteria.
SourceRange IntroducerRange
Source range covering the lambda introducer [...].
DeclaratorChunk::FunctionTypeInfo & getFunctionTypeInfo()
getFunctionTypeInfo - Retrieves the function type info object (looking through parentheses).
static DiagnosticBuilder Diag(DiagnosticsEngine *Diags, const LangOptions &Features, FullSourceLoc TokLoc, const char *TokBegin, const char *TokRangeBegin, const char *TokRangeEnd, unsigned DiagID)
Produce a diagnostic highlighting some portion of a literal.
Decl * ActOnTag(Scope *S, unsigned TagSpec, TagUseKind TUK, SourceLocation KWLoc, CXXScopeSpec &SS, IdentifierInfo *Name, SourceLocation NameLoc, const ParsedAttributesView &Attr, AccessSpecifier AS, SourceLocation ModulePrivateLoc, MultiTemplateParamsArg TemplateParameterLists, bool &OwnedDecl, bool &IsDependent, SourceLocation ScopedEnumKWLoc, bool ScopedEnumUsesClassTag, TypeResult UnderlyingType, bool IsTypeSpecifier, bool IsTemplateParamOrArg, SkipBodyInfo *SkipBody=nullptr)
This is invoked when we see 'struct foo' or 'struct {'.
bool isPure(unsigned ID) const
Return true if this function has no side effects.
bool isThisDeclarationADemotedDefinition() const
If this definition should pretend to be a declaration.
static FunctionDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation NLoc, DeclarationName N, QualType T, TypeSourceInfo *TInfo, StorageClass SC, bool isInlineSpecified=false, bool hasWrittenPrototype=true, ConstexprSpecKind ConstexprKind=CSK_unspecified)
void setNonTrivialToPrimitiveDestroy(bool V)
bool isForRedeclaration() const
True if this lookup is just looking for an existing declaration.
static void CheckForDuplicateEnumValues(Sema &S, ArrayRef< Decl *> Elements, EnumDecl *Enum, QualType EnumType)
bool isPredefinedLibFunction(unsigned ID) const
Determines whether this builtin is a predefined libc/libm function, such as "malloc", where we know the signature a priori.
bool CheckNontrivialField(FieldDecl *FD)
void setjmp_bufDecl(TypeDecl *jmp_bufDecl)
Set the type for the C jmp_buf type.
no exception specification
QualType getObjCIdType() const
Represents the Objective-CC id type.
QualType getAdjustedParameterType(QualType T) const
Perform adjustment on the parameter type of a function.
void setAnonymousStructOrUnion(bool Anon)
Module * getOwningModule() const
Get the module that owns this declaration (for visibility purposes).
Holds information about both target-independent and target-specific builtins, allowing easy queries b...
if(T->getSizeExpr()) TRY_TO(TraverseStmt(T -> getSizeExpr()))
PointerType - C99 6.7.5.1 - Pointer Declarators.
unsigned getRawEncoding() const
When a SourceLocation itself cannot be used, this returns an (opaque) 32-bit integer encoding for it...
EvaluatedExprVisitor - This class visits 'Expr *'s.
QualType getPointeeType() const
A (possibly-)qualified type.
Keeps information about an identifier in a nested-name-spec.
Decl * ActOnIvar(Scope *S, SourceLocation DeclStart, Declarator &D, Expr *BitfieldWidth, tok::ObjCKeywordKind visibility)
ActOnIvar - Each ivar field of an objective-c class is passed into this in order to create an IvarDec...
bool isBlockPointerType() const
TagDecl * getDefinition() const
Returns the TagDecl that actually defines this struct/union/class/enum.
Simple class containing the result of Sema::CorrectTypo.
bool isPODType(const ASTContext &Context) const
Determine whether this is a Plain Old Data (POD) type (C++ 3.9p10).
void InstantiatedLocal(const Decl *D, Decl *Inst)
bool hasNonTrivialToPrimitiveCopyCUnion() const
Check if this is or contains a C union that is non-trivial to copy, which is a union that has a membe...
bool diagnoseQualifiedDeclaration(CXXScopeSpec &SS, DeclContext *DC, DeclarationName Name, SourceLocation Loc, bool IsTemplateId)
Diagnose a declaration whose declarator-id has the given nested-name-specifier.
NoSpeculativeLoadHardeningAttr * mergeNoSpeculativeLoadHardeningAttr(Decl *D, const NoSpeculativeLoadHardeningAttr &AL)
void MakeTrivial(ASTContext &Context, NestedNameSpecifier *Qualifier, SourceRange R)
Make a new nested-name-specifier from incomplete source-location information.
ValueDecl * getMemberDecl() const
Retrieve the member declaration to which this expression refers.
virtual unsigned getManglingNumber(const CXXMethodDecl *CallOperator)=0
Retrieve the mangling number of a new lambda expression with the given call operator within this cont...
bool isOverloadedOperator() const
Whether this function declaration represents an C++ overloaded operator, e.g., "operator+".
void ActOnPragmaWeakAlias(IdentifierInfo *WeakName, IdentifierInfo *AliasName, SourceLocation PragmaLoc, SourceLocation WeakNameLoc, SourceLocation AliasNameLoc)
ActOnPragmaWeakAlias - Called on well formed #pragma weak ident = ident.
Expr * getArg(unsigned Arg)
getArg - Return the specified argument.
bool containedInPrototypeScope() const
containedInPrototypeScope - Return true if this or a parent scope is a FunctionPrototypeScope.
SourceRange getCXXOperatorNameRange() const
getCXXOperatorNameRange - Gets the range of the operator name (without the operator keyword)...
const DeclarationNameLoc & getInfo() const
bool isCompatibleWithMSVC(MSVCMajorVersion MajorVersion) const
SourceRange getSourceRange() const LLVM_READONLY
Return the source range that covers this unqualified-id.
bool isExternC() const
Determines whether this function is a function with external, C linkage.
void CheckTypedefForVariablyModifiedType(Scope *S, TypedefNameDecl *D)
unsigned getLongWidth() const
getLongWidth/Align - Return the size of 'signed long' and 'unsigned long' for this target...
SourceLocation StartLocation
The location of the first token that describes this unqualified-id, which will be the location of the...
static void adjustDeclContextForDeclaratorDecl(DeclaratorDecl *NewD, DeclaratorDecl *OldD)
If necessary, adjust the semantic declaration context for a qualified declaration to name the correct...
SpeculativeLoadHardeningAttr * mergeSpeculativeLoadHardeningAttr(Decl *D, const SpeculativeLoadHardeningAttr &AL)
const DeclaratorChunk & getTypeObject(unsigned i) const
Return the specified TypeInfo from this declarator.
PrimitiveDefaultInitializeKind isNonTrivialToPrimitiveDefaultInitialize() const
Functions to query basic properties of non-trivial C struct types.
Ordinary name lookup, which finds ordinary names (functions, variables, typedefs, etc...
A class which encapsulates the logic for delaying diagnostics during parsing and other processing...
IdentifierInfo * Name
FIXME: Temporarily stores the name of a specialization.
bool willHaveBody() const
True if this function will eventually have a body, once it's fully parsed.
void MergeTypedefNameDecl(Scope *S, TypedefNameDecl *New, LookupResult &OldDecls)
MergeTypedefNameDecl - We just parsed a typedef 'New' which has the same name and scope as a previous...
ExtInfo withNoCallerSavedRegs(bool noCallerSavedRegs) const
static ShadowedDeclKind computeShadowedDeclKind(const NamedDecl *ShadowedDecl, const DeclContext *OldDC)
Determine what kind of declaration we're shadowing.
void setAttrs(const AttrVec &Attrs)
void CheckCompleteVariableDeclaration(VarDecl *VD)
void setLookupName(DeclarationName Name)
Sets the name to look up.
SourceLocation TemplateNameLoc
TemplateNameLoc - The location of the template name within the source.
bool LookupName(LookupResult &R, Scope *S, bool AllowBuiltinCreation=false)
Perform unqualified name lookup starting from a given scope.
Module * getOwningModuleForLinkage(bool IgnoreLinkage=false) const
Get the module that owns this declaration for linkage purposes.
void setNonTrivialToPrimitiveDefaultInitialize(bool V)
AmbiguityKind getAmbiguityKind() const
static IndirectFieldDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation L, IdentifierInfo *Id, QualType T, llvm::MutableArrayRef< NamedDecl *> CH)
Stmt - This represents one statement.
IdentifierInfo * Identifier
When Kind == IK_Identifier, the parsed identifier, or when Kind == IK_UserLiteralId, the identifier suffix.
void setStarLoc(SourceLocation Loc)
bool isGenericLambdaCallOperatorSpecialization(const CXXMethodDecl *MD)
Filter makeFilter()
Create a filter for this result set.
void setPreviousDecl(decl_type *PrevDecl)
Set the previous declaration.
FunctionType - C99 6.7.5.3 - Function Declarators.
VarDecl * getTemplatedDecl() const
Get the underlying variable declarations of the template.
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee...
bool isMain() const
Determines whether this function is "main", which is the entry point into an executable program...
Merge availability attributes for an override, which requires an exact match or a weakening of constr...
bool isOutOfLine() const override
Determine whether this is or was instantiated from an out-of-line definition of a member function...
const llvm::Triple & getTriple() const
Returns the target triple of the primary target.
An instance of this object exists for each enum constant that is defined.
bool EvaluateAsInitializer(APValue &Result, const ASTContext &Ctx, const VarDecl *VD, SmallVectorImpl< PartialDiagnosticAt > &Notes) const
EvaluateAsInitializer - Evaluate an expression as if it were the initializer of the given declaration...
QualType ReturnType
ReturnType - The target type of return statements in this context, or null if unknown.
StorageClass getStorageClass() const
Returns the storage class as written in the source.
bool is(tok::TokenKind K) const
is/isNot - Predicates to check if this token is a specific kind, as in "if (Tok.is(tok::l_brace)) {...
RAII object that pops an ExpressionEvaluationContext when exiting a function body.
void setTypedefNameForAnonDecl(TypedefNameDecl *TDD)
Represents the declaration of a typedef-name via the 'typedef' type specifier.
Defines the SourceManager interface.
static void diagnoseImplicitlyRetainedSelf(Sema &S)
void setObjCClassRedefinitionType(QualType RedefType)
Set the user-written type that redefines 'SEL'.
void ActOnDocumentableDecl(Decl *D)
Should be called on all declarations that might have attached documentation comments.
static const Builtin::Info BuiltinInfo[]
Microsoft's '__super' specifier, stored as a CXXRecordDecl* of the class it appeared in...
bool isConstexpr() const
Whether this is a (C++11) constexpr function or constexpr constructor.
virtual bool isValidFeatureName(StringRef Feature) const
Determine whether this TargetInfo supports the given feature.
void setucontext_tDecl(TypeDecl *ucontext_tDecl)
Set the type for the C ucontext_t type.
bool hasVolatileMember() const
bool hasNonTrivialCopyConstructor() const
Determine whether this class has a non-trivial copy constructor (C++ [class.copy]p6, C++11 [class.copy]p12)
bool isRecordType() const
AvailabilityAttr * mergeAvailabilityAttr(NamedDecl *D, SourceRange Range, IdentifierInfo *Platform, bool Implicit, VersionTuple Introduced, VersionTuple Deprecated, VersionTuple Obsoleted, bool IsUnavailable, StringRef Message, bool IsStrict, StringRef Replacement, AvailabilityMergeKind AMK, int Priority, unsigned AttrSpellingListIndex)
Attribute merging methods. Return true if a new attribute was added.
bool isEmpty() const
No scope specifier.
void computeNRVO(Stmt *Body, sema::FunctionScopeInfo *Scope)
Given the set of return statements within a function body, compute the variables that are subject to ...
bool isSingleTagDecl() const
Asks if the result is a single tag decl.
bool isInitICE() const
Determines whether the initializer is an integral constant expression, or in C++11, whether the initializer is a constant expression.
void erase()
Erase the last element returned from this iterator.
static const TST TST_typeofExpr
QualType getQualifiedType(SplitQualType split) const
Un-split a SplitQualType.
QualType getElaboratedType(ElaboratedTypeKeyword Keyword, const CXXScopeSpec &SS, QualType T, TagDecl *OwnedTagDecl=nullptr)
Retrieve a version of the type 'T' that is elaborated by Keyword, qualified by the nested-name-specif...
const Type * getTypeForDecl() const
SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID)
Emit a diagnostic.
Decl - This represents one declaration (or definition), e.g.
void setRangeEnd(SourceLocation E)
bool isVariadic() const
Whether this function prototype is variadic.
SourceLocation getBeginLoc() const LLVM_READONLY
void forgetBuiltin(unsigned ID, IdentifierTable &Table)
Completely forget that the given ID was ever considered a builtin, e.g., because the user provided a ...
const RecordType * getAsStructureType() const
CommonAttr * mergeCommonAttr(Decl *D, const ParsedAttr &AL)
LambdaCaptureDefault
The default, if any, capture method for a lambda expression.
void setArgPassingRestrictions(ArgPassingKind Kind)
VarDecl * getDefinition(ASTContext &)
Get the real (not just tentative) definition for this declaration.
bool IsOverload(FunctionDecl *New, FunctionDecl *Old, bool IsForUsingDecl, bool ConsiderCudaAttrs=true)
void DiagnoseFunctionSpecifiers(const DeclSpec &DS)
Diagnose function specifiers on a declaration of an identifier that does not identify a function...
bool isPrintfLike(unsigned ID, unsigned &FormatIdx, bool &HasVAListArg)
Determine whether this builtin is like printf in its formatting rules and, if so, set the index to th...
SmallVectorImpl< NamedDecl * >::const_iterator const_decl_iterator
QualType getDeducedTemplateSpecializationType(TemplateName Template, QualType DeducedType, bool IsDependent) const
C++17 deduced class template specialization type.
SmallVectorImpl< NamedDecl * >::iterator decl_iterator
bool isPOD() const
Whether this class is a POD-type (C++ [class]p4)
Defines the C++ template declaration subclasses.
bool LookupParsedName(LookupResult &R, Scope *S, CXXScopeSpec *SS, bool AllowBuiltinCreation=false, bool EnteringContext=false)
Performs name lookup for a name that was parsed in the source code, and may contain a C++ scope speci...
OverloadedOperatorKind getCXXOverloadedOperator() const
If this name is the name of an overloadable operator in C++ (e.g., operator+), retrieve the kind of o...
Represents a C++11 auto or C++14 decltype(auto) type.
static bool canRedefineFunction(const FunctionDecl *FD, const LangOptions &LangOpts)
canRedefineFunction - checks if a function can be redefined.
void setPure(bool P=true)
void setPreviousDeclaration(FunctionDecl *PrevDecl)
bool RebuildNestedNameSpecifierInCurrentInstantiation(CXXScopeSpec &SS)
bool hasWrittenPrototype() const
Whether this function has a written prototype.
Decl * getPreviousDecl()
Retrieve the previous declaration that declares the same entity as this declaration, or NULL if there is no previous declaration.
static bool CheckMultiVersionFunction(Sema &S, FunctionDecl *NewFD, bool &Redeclaration, NamedDecl *&OldDecl, bool &MergeTypeWithPrevious, LookupResult &Previous)
Check the validity of a mulitversion function declaration.
A constructor named via a template-id.
const DiagnosticBuilder & operator<<(const DiagnosticBuilder &DB, const Attr *At)
const RecordDecl * getParent() const
Returns the parent of this field declaration, which is the struct in which this field is defined...
The base class of the type hierarchy.
static bool haveIncompatibleLanguageLinkages(const T *Old, const T *New)
static void checkDuplicateDefaultInit(Sema &S, CXXRecordDecl *Parent, SourceLocation DefaultInitLoc)
SourceLocation getBeginLoc() const LLVM_READONLY
One instance of this struct is used for each type in a declarator that is parsed. ...
Represents an array type, per C99 6.7.5.2 - Array Declarators.
Declaration of a variable template.
static InitializationKind CreateDefault(SourceLocation InitLoc)
Create a default initialization.
Represent a C++ namespace.
RedeclarationKind
Specifies whether (or how) name lookup is being performed for a redeclaration (vs.
bool isFunctionDeclarator(unsigned &idx) const
isFunctionDeclarator - This method returns true if the declarator is a function declarator (looking t...
Represents a call to a C++ constructor.
static const char * getSpecifierName(DeclSpec::TST T, const PrintingPolicy &Policy)
Turn a type-specifier-type into a string like "_Bool" or "union".
SourceLocation getEndLoc() const LLVM_READONLY
virtual void completeDefinition()
Note that the definition of this type is now complete.
bool isZero() const
isZero - Test whether the quantity equals zero.
SourceLocation getEndLoc() const LLVM_READONLY
const TargetInfo & getTargetInfo() const
AccessSpecifier
A C++ access specifier (public, private, protected), plus the special value "none" which means differ...
void ActOnExitFunctionContext()
const NestedNameSpecifier * Specifier
void checkNonTrivialCUnion(QualType QT, SourceLocation Loc, NonTrivialCUnionContext UseContext, unsigned NonTrivialKind)
Emit diagnostics if a non-trivial C union type or a struct that contains a non-trivial C union is use...
A container of type source information.
Store information needed for an explicit specifier.
static Attr * getImplicitCodeSegAttrFromClass(Sema &S, const FunctionDecl *FD)
Return a CodeSegAttr from a containing class.
Wrapper for void* pointer.
capture_const_range captures() const
Look up of a name that precedes the '::' scope resolution operator in C++.
static NestedNameSpecifier * synthesizeCurrentNestedNameSpecifier(ASTContext &Context, DeclContext *DC)
bool hasExplicitSpecifier() const
SourceRange getIntegerTypeRange() const LLVM_READONLY
Retrieve the source range that covers the underlying type if specified.
An overloaded operator name, e.g., operator+.
bool isDefined(const FunctionDecl *&Definition) const
Returns true if the function has a definition that does not need to be instantiated.
static unsigned GetDiagnosticTypeSpecifierID(DeclSpec::TST T)
TSCS getThreadStorageClassSpec() const
void SetIdentifier(IdentifierInfo *Id, SourceLocation IdLoc)
Set the name of this declarator to be the given identifier.
void setInitStyle(InitializationStyle Style)
Represents a path from a specific derived class (which is not represented as part of the path) to a p...
unsigned getCharWidth() const
param_const_iterator param_end() const
Represents a C++ constructor within a class.
LLVM_ATTRIBUTE_REINITIALIZES void clear()
Clears out any current state.
void mergePrevDecl(FunctionTemplateDecl *Prev)
Merge Prev with our RedeclarableTemplateDecl::Common.
const DeclContext * getParentFunctionOrMethod() const
If this decl is defined inside a function/method/block it returns the corresponding DeclContext...
size_t param_size() const
SourceLocation getEndLoc() const
Get the end source location.
const ParsedAttributes & getAttributes() const
bool CheckVariableDeclaration(VarDecl *NewVD, LookupResult &Previous)
Perform semantic checking on a newly-created variable declaration.
bool hasAttribute(ParsedAttr::Kind K) const
QualType getElementType() const
const AttributedType * getCallingConvAttributedType(QualType T) const
Get the outermost AttributedType node that sets a calling convention.
bool isCompleteDefinition() const
Return true if this decl has its body fully specified.
const RecordType * getAsUnionType() const
NOTE: getAs*ArrayType are methods on ASTContext.
unsigned getTypeAlign(QualType T) const
Return the ABI-specified alignment of a (complete) type T, in bits.
***static FixItHint createFriendTagNNSFixIt(Sema &SemaRef, NamedDecl *ND, Scope *S, SourceLocation NameLoc)
The type would be trivial except that it is volatile-qualified.
Retains information about a function, method, or block that is currently being parsed.
This file provides some common utility functions for processing Lambda related AST Constructs...
bool DiagnoseClassNameShadow(DeclContext *DC, DeclarationNameInfo Info)
DiagnoseClassNameShadow - Implement C++ [class.mem]p13: If T is the name of a class, then each of the following shall have a name different from T:
void setRAngleLoc(SourceLocation Loc)
void ActOnObjCReenterContainerContext(DeclContext *DC)
DeclContext::lookup_result Decls
The set of declarations found inside this base class subobject.
enumerator_range enumerators() const
Represents a variable declaration or definition.
PartialDiagnostic PDiag(unsigned DiagID=0)
Build a partial diagnostic.
bool isStructureType() const
NamedDecl * LazilyCreateBuiltin(IdentifierInfo *II, unsigned ID, Scope *S, bool ForRedeclaration, SourceLocation Loc)
LazilyCreateBuiltin - The specified Builtin-ID was first used at file scope.
static const TST TST_underlyingType
static NestedNameSpecifier * Create(const ASTContext &Context, NestedNameSpecifier *Prefix, IdentifierInfo *II)
Builds a specifier combining a prefix and an identifier.
DeclarationName getLookupName() const
Gets the name to look up.
Information about one declarator, including the parsed type information and the identifier.
QualType getReturnType() const
DiagnosticsEngine & Diags
unsigned getNumParams() const
bool isEnumeralType() const
void setCXXLiteralOperatorNameLoc(SourceLocation Loc)
setCXXLiteralOperatorNameLoc - Sets the location of the literal operator name (not the operator keywo...
const internal::VariadicDynCastAllOfMatcher< Stmt, Expr > expr
Matches expressions.
bool isFixed() const
Returns true if this is an Objective-C, C++11, or Microsoft-style enumeration with a fixed underlying...
const T * getAs() const
Member-template getAs<specific type>'.
static void SetNestedNameSpecifier(Sema &S, DeclaratorDecl *DD, Declarator &D)
Extra information about a function prototype.
decl_range decls() const
decls_begin/decls_end - Iterate over the declarations stored in this context.
const ArrayType * castAsArrayTypeUnsafe() const
A variant of castAs<> for array type which silently discards qualifiers from the outermost type...
TypeSpecifierType
Specifies the kind of type.
LangAS
Defines the address space values used by the address space qualifier of QualType. ...
The "__interface" keyword.
bool isExternCContext() const
Determines whether this context or some of its ancestors is a linkage specification context that spec...
void ActOnTagFinishSkippedDefinition(SkippedDefinitionContext Context)
ExtInfo withProducesResult(bool producesResult) const
ObjCMethodDecl - Represents an instance or class method declaration.
NamedDecl * getUnderlyingDecl()
Looks through UsingDecls and ObjCCompatibleAliasDecls for the underlying named decl.
void ActOnObjCTemporaryExitContainerContext(DeclContext *DC)
Invoked when we must temporarily exit the objective-c container scope for parsing/looking-up C constr...
static const TST TST_interface
bool isZeroLengthBitField(const ASTContext &Ctx) const
Is this a zero-length bit-field? Such bit-fields aren't really bit-fields at all and instead act as a...
NestedNameSpecifier * getCorrectionSpecifier() const
Gets the NestedNameSpecifier needed to use the typo correction.
bool hasTrivialDefaultConstructor() const
Determine whether this class has a trivial default constructor (C++11 [class.ctor]p5).
bool isInvalidDecl() const
bool AddOverriddenMethods(CXXRecordDecl *DC, CXXMethodDecl *MD)
AddOverriddenMethods - See if a method overrides any in the base classes, and if so, check that it's a valid override and remember it.
QualType getObjCClassType() const
Represents the Objective-C Class type.
Stores a list of template parameters for a TemplateDecl and its derived classes.
static StringRef getTagTypeKindName(TagTypeKind Kind)
bool isCallingConv() const
Describes how types, statements, expressions, and declarations should be printed. ...
NamedDecl * ActOnFunctionDeclarator(Scope *S, Declarator &D, DeclContext *DC, TypeSourceInfo *TInfo, LookupResult &Previous, MultiTemplateParamsArg TemplateParamLists, bool &AddToScope)
Decl * ActOnParamDeclarator(Scope *S, Declarator &D)
ActOnParamDeclarator - Called from Parser::ParseFunctionDeclarator() to introduce parameters into fun...
llvm::SmallVector< ShadowedOuterDecl, 4 > ShadowingDecls
SpecifierKind getKind() const
Determine what kind of nested name specifier is stored.
ParsedType getTypeName(const IdentifierInfo &II, SourceLocation NameLoc, Scope *S, CXXScopeSpec *SS=nullptr, bool isClassName=false, bool HasTrailingDot=false, ParsedType ObjectType=nullptr, bool IsCtorOrDtorName=false, bool WantNontrivialTypeSourceInfo=false, bool IsClassTemplateDeductionContext=true, IdentifierInfo **CorrectedII=nullptr)
If the identifier refers to a type name within this scope, return the declaration of that type...
bool canSkipFunctionBody(Decl *D)
Determine whether we can skip parsing the body of a function definition, assuming we don't care about...
bool hasDefinition() const
static QualType getCoreType(QualType Ty)
Represents an expression – generally a full-expression – that introduces cleanups to be run at the ...
static const NamedDecl * getDefinition(const Decl *D)
Represents a parameter to a function.
Linkage
Describes the different kinds of linkage (C++ [basic.link], C99 6.2.2) that an entity may have...
OpenCLOptions & getOpenCLOptions()
Defines the clang::Expr interface and subclasses for C++ expressions.
void removeDecl(Decl *D)
Removes a declaration from this context.
enum clang::DeclaratorChunk::@217 Kind
void addVLATypeCapture(SourceLocation Loc, const VariableArrayType *VLAType, QualType CaptureType)
void setQualifierLoc(NestedNameSpecifierLoc QualifierLoc)
void setTagNameForLinkagePurposes(TagDecl *TagFromDeclSpec, TypedefNameDecl *NewTD)
static const TemplateDecl * isTemplate(const NamedDecl *ND, const TemplateArgumentList *&TemplateArgs)
static TypeSourceInfo * TryToFixInvalidVariablyModifiedTypeSourceInfo(TypeSourceInfo *TInfo, ASTContext &Context, bool &SizeIsNegative, llvm::APSInt &Oversized)
Helper method to turn variable array types into constant array types in certain situations which woul...
bool isVariableArrayType() const
Information about a template-id annotation token.
static CXXMethodDecl * Create(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc, const DeclarationNameInfo &NameInfo, QualType T, TypeSourceInfo *TInfo, StorageClass SC, bool isInline, ConstexprSpecKind ConstexprKind, SourceLocation EndLocation)
bool isAnonymousStructOrUnion() const
Determines whether this field is a representative for an anonymous struct or union.
ModuleKind Kind
The kind of this module.
FieldDecl * HandleField(Scope *S, RecordDecl *TagD, SourceLocation DeclStart, Declarator &D, Expr *BitfieldWidth, InClassInitStyle InitStyle, AccessSpecifier AS)
HandleField - Analyze a field of a C struct or a C++ data member.
SourceRange getReturnTypeSourceRange() const
Attempt to compute an informative source range covering the function return type. ...
bool FTIHasNonVoidParameters(const DeclaratorChunk::FunctionTypeInfo &FTI)
QualType CheckConstructorDeclarator(Declarator &D, QualType R, StorageClass &SC)
CheckConstructorDeclarator - Called by ActOnDeclarator to check the well-formedness of the constructo...
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
void setCorrectionDecl(NamedDecl *CDecl)
Clears the list of NamedDecls before adding the new one.
void ActOnUninitializedDecl(Decl *dcl)
Base wrapper for a particular "section" of type source info.
Decl * ActOnStartOfFunctionDef(Scope *S, Declarator &D, MultiTemplateParamsArg TemplateParamLists, SkipBodyInfo *SkipBody=nullptr)
bool isMoveAssignmentOperator() const
Determine whether this is a move assignment operator.
const AstTypeMatcher< RecordType > recordType
Matches record types (e.g.
bool isRedeclaration() const
Represents a struct/union/class.
void DiagnoseSizeOfParametersAndReturnValue(ArrayRef< ParmVarDecl *> Parameters, QualType ReturnTy, NamedDecl *D)
Diagnose whether the size of parameters or return value of a function or obj-c method definition is p...
This is the private module fragment within some C++ module.
TemplateIdAnnotation * TemplateId
When Kind == IK_TemplateId or IK_ConstructorTemplateId, the template-id annotation that contains the ...
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
static bool CheckTargetCausesMultiVersioning(Sema &S, FunctionDecl *OldFD, FunctionDecl *NewFD, const TargetAttr *NewTA, bool &Redeclaration, NamedDecl *&OldDecl, bool &MergeTypeWithPrevious, LookupResult &Previous)
bool Encloses(const DeclContext *DC) const
Determine whether this declaration context encloses the declaration context DC.
Linkage getFormalLinkage() const
Get the linkage from a semantic point of view.
bool isComplete() const
Returns true if this can be considered a complete type.
One of these records is kept for each identifier that is lexed.
void CheckFunctionOrTemplateParamDeclarator(Scope *S, Declarator &D)
Common checks for a parameter-declaration that should apply to both function parameters and non-type ...
void setIntegerType(QualType T)
Set the underlying integer type.
TargetCXXABI getCXXABI() const
Get the C++ ABI currently in use.
LocalInstantiationScope * CurrentInstantiationScope
The current instantiation scope used to store local variables.
Name lookup results in an ambiguity; use getAmbiguityKind to figure out what kind of ambiguity we hav...
SourceLocation getOuterLocStart() const
Return start of source range taking into account any outer template declarations. ...
void MarkUnusedFileScopedDecl(const DeclaratorDecl *D)
If it's a file scoped decl that must warn if not used, keep track of it.
static bool isFunctionDefinitionDiscarded(Sema &S, FunctionDecl *FD)
Given that we are within the definition of the given function, will that definition behave like C99's...
bool doesNotEscape() const
DeclarationNameInfo GetNameFromUnqualifiedId(const UnqualifiedId &Name)
Retrieves the declaration name from a parsed unqualified-id.
void RegisterLocallyScopedExternCDecl(NamedDecl *ND, Scope *S)
Register the given locally-scoped extern "C" declaration so that it can be found later for redeclarat...
static bool isDeclExternC(const Decl *D)
Returns true if given declaration has external C language linkage.
void MergeVarDeclTypes(VarDecl *New, VarDecl *Old, bool MergeTypeWithOld)
MergeVarDeclTypes - We parsed a variable 'New' which has the same name and scope as a previous declar...
static bool hasDeducedAuto(DeclaratorDecl *DD)
unsigned getRegParm() const
bool isStr(const char(&Str)[StrLen]) const
Return true if this is the identifier for the specified string.
ExprResult RebuildExprInCurrentInstantiation(Expr *E)
UnionParsedType ConversionFunctionId
When Kind == IK_ConversionFunctionId, the type that the conversion function names.
static RecordDecl * Create(const ASTContext &C, TagKind TK, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, RecordDecl *PrevDecl=nullptr)
void setManglingNumber(const NamedDecl *ND, unsigned Number)
static void mergeParamDeclTypes(ParmVarDecl *NewParam, const ParmVarDecl *OldParam, Sema &S)
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
A C++ nested-name-specifier augmented with source location information.
DeclarationName getCorrection() const
Gets the DeclarationName of the typo correction.
static InitializationKind CreateForInit(SourceLocation Loc, bool DirectInit, Expr *Init)
Create an initialization from an initializer (which, for direct initialization from a parenthesized l...
ArrayRef< QualType > getParamTypes() const
The results of name lookup within a DeclContext.
SourceLocation getTypeSpecTypeLoc() const
const ParmVarDecl *const * param_const_iterator
bool isObjCLifetimeType() const
Returns true if objects of this type have lifetime semantics under ARC.
TypeLoc getInnerLoc() const
ConstexprSpecKind getConstexprKind() const
void ActOnTagStartDefinition(Scope *S, Decl *TagDecl)
ActOnTagStartDefinition - Invoked when we have entered the scope of a tag's definition (e...
Missing a type from <ucontext.h>
bool CheckEnumUnderlyingType(TypeSourceInfo *TI)
Check that this is a valid underlying type for an enum declaration.
TemplateDecl * getAsTemplateDecl() const
Retrieve the underlying template declaration that this template name refers to, if known...
unsigned getFunctionPrototypeDepth() const
Returns the number of function prototype scopes in this scope chain.
RecordDecl * getDefinition() const
Returns the RecordDecl that actually defines this struct/union/class.
static bool anyDependentTemplateArguments(ArrayRef< TemplateArgumentLoc > Args, bool &InstantiationDependent)
Determine whether any of the given template arguments are dependent.
Base class for callback objects used by Sema::CorrectTypo to check the validity of a potential typo c...
field_range fields() const
QualType getLifetimeQualifiedType(QualType type, Qualifiers::ObjCLifetime lifetime)
Return a type with the given lifetime qualifier.
TypeSourceInfo * getTypeSourceInfo(ASTContext &Context, QualType T)
Creates a TypeSourceInfo for the given type.
QualType getDependentNameType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier *NNS, const IdentifierInfo *Name, QualType Canon=QualType()) const
SourceLocation getBeginLoc() const LLVM_READONLY
static const TST TST_class
NameKind getNameKind() const
Determine what kind of name this is.
bool isObjCIdType() const
bool isAcceptableTagRedeclaration(const TagDecl *Previous, TagTypeKind NewTag, bool isDefinition, SourceLocation NewTagLoc, const IdentifierInfo *Name)
Determine whether a tag with a given kind is acceptable as a redeclaration of the given tag declarati...
static DecompositionDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation LSquareLoc, QualType T, TypeSourceInfo *TInfo, StorageClass S, ArrayRef< BindingDecl *> Bindings)
bool hasSkippedBody() const
True if the function was a definition but its body was skipped.
UnionParsedTemplateTy TemplateName
When Kind == IK_DeductionGuideName, the parsed template-name.
Represents a member of a struct/union/class.
const Type * getAsType() const
Retrieve the type stored in this nested name specifier.
const llvm::APSInt & getInitVal() const
bool supportsMultiVersioning() const
Identify whether this target supports multiversioning of functions, which requires support for cpu_su...
DeclGroupPtrTy ConvertDeclToDeclGroup(Decl *Ptr, Decl *OwnedType=nullptr)
OverloadedOperatorKind Operator
The kind of overloaded operator.
unsigned getFunctionScopeIndex() const
Returns the index of this parameter in its prototype or method scope.
static bool isIncrementDecrementOp(Opcode Op)
const DeclarationNameInfo & getLookupNameInfo() const
Gets the name info to look up.
bool isFunctionDefinition() const
void startDefinition()
Starts the definition of this tag declaration.
Attr * getImplicitCodeSegOrSectionAttrForFunction(const FunctionDecl *FD, bool IsDefinition)
Returns an implicit CodeSegAttr if a __declspec(code_seg) is found on a containing class...
struct OFI OperatorFunctionId
When Kind == IK_OperatorFunctionId, the overloaded operator that we parsed.
bool hasAutoTypeSpec() const
CXXMethodDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
void setName(DeclarationName N)
setName - Sets the embedded declaration name.
bool isReferenceType() const
void setElaboratedKeywordLoc(SourceLocation Loc)
The iterator over UnresolvedSets.
static const TST TST_error
Token - This structure provides full information about a lexed token.
void setStaticLocalNumber(const VarDecl *VD, unsigned Number)
bool isInIdentifierNamespace(unsigned NS) const
SkipBodyInfo shouldSkipAnonEnumBody(Scope *S, IdentifierInfo *II, SourceLocation IILoc)
Determine whether the body of an anonymous enumeration should be skipped.
static OpenCLParamType getOpenCLKernelParameterType(Sema &S, QualType PT)
TemplateName getOverloadedTemplateName(UnresolvedSetIterator Begin, UnresolvedSetIterator End) const
Retrieve the template name that corresponds to a non-empty lookup.
bool isLinkageValid() const
True if the computed linkage is valid.
This declaration is definitely a definition.
static const TST TST_enum
bool Equals(const DeclContext *DC) const
Determine whether this declaration context is equivalent to the declaration context DC...
void CheckMain(FunctionDecl *FD, const DeclSpec &D)
ExplicitSpecifier getExplicitSpecifier() const
TypedefDecl * ParseTypedefDecl(Scope *S, Declarator &D, QualType T, TypeSourceInfo *TInfo)
Subroutines of ActOnDeclarator().
OpaquePtr< QualType > ParsedType
An opaque type for threading parsed type information through the parser.
LookupResultKind getResultKind() const
bool isMicrosoftMissingTypename(const CXXScopeSpec *SS, Scope *S)
isMicrosoftMissingTypename - In Microsoft mode, within class scope, if a CXXScopeSpec's type is equal...
void ActOnFinishDelayedAttribute(Scope *S, Decl *D, ParsedAttributes &Attrs)
ActOnFinishDelayedAttribute - Invoked when we have finished parsing an attribute for which parsing is...
__DEVICE__ int max(int __a, int __b)
void ClearStorageClassSpecs()
SourceLocation getBeginLoc() const LLVM_READONLY
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Declaration of a function specialization at template class scope.
void CheckDeductionGuideDeclarator(Declarator &D, QualType &R, StorageClass &SC)
Check the validity of a declarator that we parsed for a deduction-guide.
SourceLocation getTemplateLoc() const
TypeVisibilityAttr * mergeTypeVisibilityAttr(Decl *D, SourceRange Range, TypeVisibilityAttr::VisibilityType Vis, unsigned AttrSpellingListIndex)
bool isPreviousDeclInSameBlockScope() const
Whether this local extern variable declaration's previous declaration was declared in the same block ...
void PopExpressionEvaluationContext()
bool isIntegralOrEnumerationType() const
Determine whether this type is an integral or enumeration type.
No entity found met the criteria within the current instantiation,, but there were dependent base cla...
A user-defined literal name, e.g., operator "" _i.
static bool adjustContextForLocalExternDecl(DeclContext *&DC)
Adjust the DeclContext for a function or variable that might be a function-local external declaration...
Describes a module or submodule.
RawCommentList & getRawCommentList()
An r-value expression (a pr-value in the C++11 taxonomy) produces a temporary value.
bool isInvalidType() const
ArrayRef< ParmVarDecl * > parameters() const
bool canKeyFunctionBeInline() const
Can an out-of-line inline function serve as a key function?
Provides information about a function template specialization, which is a FunctionDecl that has been ...
bool getProducesResult() const
DeclClass * getAsSingle() const
static bool InjectAnonymousStructOrUnionMembers(Sema &SemaRef, Scope *S, DeclContext *Owner, RecordDecl *AnonRecord, AccessSpecifier AS, SmallVectorImpl< NamedDecl *> &Chaining)
InjectAnonymousStructOrUnionMembers - Inject the members of the anonymous struct or union AnonRecord ...
QualType mergeObjCGCQualifiers(QualType, QualType)
mergeObjCGCQualifiers - This routine merges ObjC's GC attribute of 'LHS' and 'RHS' attributes and ret...
VarDecl * getActingDefinition()
Get the tentative definition that acts as the real definition in a TU.
UnionParsedType DestructorName
When Kind == IK_DestructorName, the type referred to by the class-name.
bool isReplaceableGlobalAllocationFunction(bool *IsAligned=nullptr) const
Determines whether this function is one of the replaceable global allocation functions: void *operato...
Describes an C or C++ initializer list.
bool isFunctionPrototypeScope() const
isFunctionPrototypeScope - Return true if this scope is a function prototype scope.
Represents a C++ unqualified-id that has been parsed.
static ExprResult CheckConvertedConstantExpression(Sema &S, Expr *From, QualType T, APValue &Value, Sema::CCEKind CCE, bool RequireInt)
CheckConvertedConstantExpression - Check that the expression From is a converted constant expression ...
bool isBitField() const
Determines whether this field is a bitfield.
static ClassScopeFunctionSpecializationDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation Loc, CXXMethodDecl *FD, bool HasExplicitTemplateArgs, const TemplateArgumentListInfo &TemplateArgs)
DeclContext * getEnclosingNamespaceContext()
Retrieve the nearest enclosing namespace context.
void resolveKind()
Resolves the result kind of the lookup, possibly hiding decls.
void setNameLoc(SourceLocation Loc)
static CXXDeductionGuideDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, ExplicitSpecifier ES, const DeclarationNameInfo &NameInfo, QualType T, TypeSourceInfo *TInfo, SourceLocation EndLocation)
Represents the results of name lookup.
void mergeDeclAttributes(NamedDecl *New, Decl *Old, AvailabilityMergeKind AMK=AMK_Redeclaration)
mergeDeclAttributes - Copy attributes from the Old decl to the New one.
bool checkVarDeclRedefinition(VarDecl *OldDefn, VarDecl *NewDefn)
We've just determined that Old and New both appear to be definitions of the same variable.
std::string getFullModuleName(bool AllowStringLiterals=false) const
Retrieve the full name of this module, including the path from its top-level module.
NamedDecl * ActOnVariableDeclarator(Scope *S, Declarator &D, DeclContext *DC, TypeSourceInfo *TInfo, LookupResult &Previous, MultiTemplateParamsArg TemplateParamLists, bool &AddToScope, ArrayRef< BindingDecl *> Bindings=None)
bool isElidable() const
Whether this construction is elidable.
ObjCContainerDecl - Represents a container for method declarations.
static void filterNonConflictingPreviousTypedefDecls(Sema &S, TypedefNameDecl *Decl, LookupResult &Previous)
Typedef declarations don't have linkage, but they still denote the same entity if their types are the...
TagKind getTagKind() const
bool isReferenced() const
Whether any declaration of this entity was referenced.
CharUnits - This is an opaque type for sizes expressed in character units.
APValue Val
Val - This is the value the expression can be folded to.
A convenient class for passing around template argument information.
void setcudaConfigureCallDecl(FunctionDecl *FD)
void setParamDestroyedInCallee(bool V)
Scope * getNonFieldDeclScope(Scope *S)
getNonFieldDeclScope - Retrieves the innermost scope, starting from S, where a non-field would be dec...
bool ActOnDuplicateDefinition(DeclSpec &DS, Decl *Prev, SkipBodyInfo &SkipBody)
Perform ODR-like check for C/ObjC when merging tag types from modules.
static bool mergeAlignedAttrs(Sema &S, NamedDecl *New, Decl *Old)
Merge alignment attributes from Old to New, taking into account the special semantics of C11's _Align...
bool hasAddressSpace() const
TagDecl * getAnonDeclWithTypedefName(bool AnyRedecl=false) const
Retrieves the tag declaration for which this is the typedef name for linkage purposes, if any.
Keeps track of the mangled names of lambda expressions and block literals within a particular context...
Wrapper for source info for functions.
static void RebuildLambdaScopeInfo(CXXMethodDecl *CallOperator, Sema &S)
void ActOnInitializerError(Decl *Dcl)
ActOnInitializerError - Given that there was an error parsing an initializer for the given declaratio...
SCS
storage-class-specifier
static EnumConstantDecl * Create(ASTContext &C, EnumDecl *DC, SourceLocation L, IdentifierInfo *Id, QualType T, Expr *E, const llvm::APSInt &V)
FunctionTemplateDecl * getDescribedFunctionTemplate() const
Retrieves the function template that is described by this function declaration.
bool hasPrototype() const
Whether this function has a prototype, either because one was explicitly written or because it was "i...
DeclGroupPtrTy BuildDeclaratorGroup(MutableArrayRef< Decl *> Group)
BuildDeclaratorGroup - convert a list of declarations into a declaration group, performing any necess...
Decl * getObjCDeclContext() const
Visibility
Describes the different kinds of visibility that a declaration may have.
Decl * ActOnObjCContainerStartDefinition(Decl *IDecl)
static ParsedType recoverFromTypeInKnownDependentBase(Sema &S, const IdentifierInfo &II, SourceLocation NameLoc)
A friend of a previously-undeclared entity.
unsigned getNumTypeObjects() const
Return the number of types applied to this declarator.
SourceLocation getBeginLoc() const LLVM_READONLY
Concrete class used by the front-end to report problems and issues.
TemplateDecl * getAsTypeTemplateDecl(Decl *D)
bool isConstWithoutErrno(unsigned ID) const
Return true if this function has no side effects and doesn't read memory, except for possibly errno...
const clang::PrintingPolicy & getPrintingPolicy() const
static bool isRecordType(QualType T)
TemplateSpecializationKind getTemplateSpecializationKind() const
If this variable is an instantiation of a variable template or a static data member of a class templa...
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Represents a declaration of a type.
A builtin binary operation expression such as "x + y" or "x <= y".
void setRedeclaration(bool Val)
void setHasObjectMember(bool val)
bool isVolatileQualified() const
Determine whether this type is volatile-qualified.
bool isShadowed() const
Determine whether the lookup result was shadowed by some other declaration that lookup ignored...
unsigned getNumPositiveBits() const
Returns the width in bits required to store all the non-negative enumerators of this enum...
static void checkIsValidOpenCLKernelParameter(Sema &S, Declarator &D, ParmVarDecl *Param, llvm::SmallPtrSetImpl< const Type *> &ValidTypes)
bool hasNonTrivialToPrimitiveDestructCUnion() const
Check if this is or contains a C union that is non-trivial to destruct, which is a union that has a m...
static void checkDLLAttributeRedeclaration(Sema &S, NamedDecl *OldDecl, NamedDecl *NewDecl, bool IsSpecialization, bool IsDefinition)
SourceLocation getLParenLoc() const
static SourceLocation getCaptureLocation(const LambdaScopeInfo *LSI, const VarDecl *VD)
Return the location of the capture if the given lambda captures the given variable VD...
QualType CheckDestructorDeclarator(Declarator &D, QualType R, StorageClass &SC)
CheckDestructorDeclarator - Called by ActOnDeclarator to check the well-formednes of the destructor d...
GVALinkage GetGVALinkageForFunction(const FunctionDecl *FD) const
void setHasImplicitReturnZero(bool IRZ)
State that falling off this function implicitly returns null/zero.
ParsedTemplateArgument * getTemplateArgs()
Retrieves a pointer to the template arguments.
MutableArrayRef< TemplateParameterList * > MultiTemplateParamsArg
FormatAttr * mergeFormatAttr(Decl *D, SourceRange Range, IdentifierInfo *Format, int FormatIdx, int FirstArg, unsigned AttrSpellingListIndex)
Module * Parent
The parent of this module.
static bool isAcceptableTagRedeclContext(Sema &S, DeclContext *OldDC, DeclContext *NewDC)
Determine whether a tag originally declared in context OldDC can be redeclared with an unqualified na...
unsigned getShortWidth() const
Return the size of 'signed short' and 'unsigned short' for this target, in bits.
unsigned getMSLastManglingNumber() const
The argument of this type cannot be passed directly in registers.
bool isConstexpr() const
Whether this variable is (C++11) constexpr.
FunctionTemplateSpecializationInfo * getTemplateSpecializationInfo() const
If this function is actually a function template specialization, retrieve information about this func...
CharUnits getDeclAlign(const Decl *D, bool ForAlignof=false) const
Return a conservative estimate of the alignment of the specified decl D.
DeclContextLookupResult slice(size_t N) const
DeclContext * getLambdaAwareParentOfDeclContext(DeclContext *DC)
Expr * getSizeExpr() const
Scope - A scope is a transient data structure that is used while parsing the program.
ExprResult Perform(Sema &S, const InitializedEntity &Entity, const InitializationKind &Kind, MultiExprArg Args, QualType *ResultType=nullptr)
Perform the actual initialization of the given entity based on the computed initialization sequence...
Decl * ActOnFileScopeAsmDecl(Expr *expr, SourceLocation AsmLoc, SourceLocation RParenLoc)
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
CXXRecordDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
field_iterator field_begin() const
bool declaresSameEntity(const Decl *D1, const Decl *D2)
Determine whether two declarations declare the same entity.
NonTagKind
Common ways to introduce type names without a tag for use in diagnostics.
void ActOnLastBitfield(SourceLocation DeclStart, SmallVectorImpl< Decl *> &AllIvarDecls)
ActOnLastBitfield - This routine handles synthesized bitfields rules for class and class extensions...
bool DeduceVariableDeclarationType(VarDecl *VDecl, bool DirectInit, Expr *Init)
static unsigned getNumAddressingBits(const ASTContext &Context, QualType ElementType, const llvm::APInt &NumElements)
Determine the number of bits required to address a member of.
void DiagnoseUnusedDecl(const NamedDecl *ND)
DiagnoseUnusedDecl - Emit warnings about declarations that are not used unless they are marked attr(u...
const Expr * getInitExpr() const
bool hasNameForLinkage() const
Is this tag type named, either directly or via being defined in a typedef of this type...
Represents a C++ nested-name-specifier or a global scope specifier.
const T * getAsAdjusted() const
Member-template getAsAdjusted<specific type>.
int hasAttribute(AttrSyntax Syntax, const IdentifierInfo *Scope, const IdentifierInfo *Attr, const TargetInfo &Target, const LangOptions &LangOpts)
Return the version number associated with the attribute if we recognize and implement the attribute s...
bool IsValueInFlagEnum(const EnumDecl *ED, const llvm::APInt &Val, bool AllowMask) const
IsValueInFlagEnum - Determine if a value is allowed as part of a flag enum.
bool isNoreturnSpecified() const
void setRedeclarationKind(Sema::RedeclarationKind RK)
Change this lookup's redeclaration kind.
DeclContext * getLexicalDeclContext()
getLexicalDeclContext - The declaration context where this Decl was lexically declared (LexicalDC)...
static bool mergeDeclAttribute(Sema &S, NamedDecl *D, const InheritableAttr *Attr, Sema::AvailabilityMergeKind AMK)
static Scope * getTagInjectionScope(Scope *S, const LangOptions &LangOpts)
Find the Scope in which a tag is implicitly declared if we see an elaborated type specifier in the sp...
SourceLocation getSpellingLoc(SourceLocation Loc) const
Given a SourceLocation object, return the spelling location referenced by the ID. ...
bool isIncompatibleTypedef(TypeDecl *Old, TypedefNameDecl *New)
void UpdateExprRep(Expr *Rep)
void CheckVariableDeclarationType(VarDecl *NewVD)
bool performsCallback(unsigned ID, llvm::SmallVectorImpl< int > &Encoding) const
Determine whether this builtin has callback behavior (see llvm::AbstractCallSites for details)...
bool hasTrivialDestructor() const
Determine whether this class has a trivial destructor (C++ [class.dtor]p3)
static VarDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo, StorageClass S)
const LangOptions & getLangOpts() const
static IntegerLiteral * Create(const ASTContext &C, const llvm::APInt &V, QualType type, SourceLocation l)
Returns a new integer literal with value 'V' and type 'type'.
void AdjustDestructorExceptionSpec(CXXDestructorDecl *Destructor)
Build an exception spec for destructors that don't have one.
SourceLocation getConstSpecLoc() const
void setLocalOwningModule(Module *M)
bool isTypeDependent() const
isTypeDependent - Determines whether this expression is type-dependent (C++ [temp.dep.expr]), which means that its type could change from one template instantiation to the next.
const CXXScopeSpec & getCXXScopeSpec() const
getCXXScopeSpec - Return the C++ scope specifier (global scope or nested-name-specifier) that is part...
bool isScalarType() const
SourceLocation getLSquareLoc() const
FunctionDecl * getInstantiatedFromMemberFunction() const
If this function is an instantiation of a member function of a class template specialization, retrieves the function from which it was instantiated.
bool isLambdaCallOperator(const CXXMethodDecl *MD)
static CXXConstructorDecl * Create(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc, const DeclarationNameInfo &NameInfo, QualType T, TypeSourceInfo *TInfo, ExplicitSpecifier ES, bool isInline, bool isImplicitlyDeclared, ConstexprSpecKind ConstexprKind, InheritedConstructor Inherited=InheritedConstructor())
void CheckMSVCRTEntryPoint(FunctionDecl *FD)
Decl * ActOnFinishFunctionBody(Decl *Decl, Stmt *Body)
Represents an ObjC class declaration.
void DiagnoseUnknownTypeName(IdentifierInfo *&II, SourceLocation IILoc, Scope *S, CXXScopeSpec *SS, ParsedType &SuggestedType, bool IsTemplateName=false)
void revertBuiltin()
Revert the identifier to a non-builtin identifier.
Represents a linkage specification.
static FunctionTemplateDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation L, DeclarationName Name, TemplateParameterList *Params, NamedDecl *Decl)
Create a function template node.
void addDecl(NamedDecl *D)
Add a declaration to these results with its natural access.
unsigned getBuiltinID(bool ConsiderWrapperFunctions=false) const
Returns a value indicating whether this function corresponds to a builtin function.
Member name lookup, which finds the names of class/struct/union members.
SourceLocation getTypeSpecStartLoc() const
SourceRange getSourceRange() const LLVM_READONLY
PrimitiveDefaultInitializeKind
void CheckStaticLocalForDllExport(VarDecl *VD)
Check if VD needs to be dllexport/dllimport due to being in a dllexport/import function.
const T * getTypePtr() const
Retrieve the underlying type pointer, which refers to a canonical type.
MinSizeAttr * mergeMinSizeAttr(Decl *D, SourceRange Range, unsigned AttrSpellingListIndex)
NestedNameSpecifierLoc getWithLocInContext(ASTContext &Context) const
Retrieve a nested-name-specifier with location information, copied into the given AST context...
virtual bool isValidGCCRegisterName(StringRef Name) const
Returns whether the passed in string is a valid register name according to GCC.
The type does not fall into any of the following categories.
IdentifierInfo * getIdentifier() const
static bool isUsingDecl(NamedDecl *D)
CanQualType UnsignedCharTy
unsigned getLength() const
Efficiently return the length of this identifier info.
bool getNoCallerSavedRegs() const
UnionParsedType ConstructorName
When Kind == IK_ConstructorName, the class-name of the type whose constructor is being referenced...
virtual Decl * getCanonicalDecl()
Retrieves the "canonical" declaration of the given declaration.
Expr * IgnoreImpCasts() LLVM_READONLY
Skip past any implicit casts which might surround this expression until reaching a fixed point...
CallingConv getDefaultCallingConvention(bool IsVariadic, bool IsCXXMethod, bool IsBuiltin=false) const
Retrieves the default calling convention for the current target.
TypeSpecTypeLoc pushTypeSpec(QualType T)
Pushes space for a typespec TypeLoc.
bool isAnonymousStructOrUnion() const
Whether this is an anonymous struct or union.
This object can be modified without requiring retains or releases.
TemplateNameKindForDiagnostics
Describes the detailed kind of a template name. Used in diagnostics.
param_iterator param_begin()
void setHasInheritedPrototype(bool P=true)
State that this function inherited its prototype from a previous declaration.
TyLocType push(QualType T)
Pushes space for a new TypeLoc of the given type.
lookup_result lookup(DeclarationName Name) const
lookup - Find the declarations (if any) with the given Name in this context.
Class that aids in the construction of nested-name-specifiers along with source-location information ...
ExtInfo withCallingConv(CallingConv cc) const
ImplicitCaptureStyle ImpCaptureStyle
SourceLocation LAngleLoc
The location of the '<' before the template argument list.
bool isExternInLinkageSpec() const
FunctionTemplateDecl * getPrimaryTemplate() const
Retrieve the primary template that this function template specialization either specializes or was in...
RAII class used to determine whether SFINAE has trapped any errors that occur during template argumen...
CXXSpecialMember
Kinds of C++ special members.
unsigned getFlags() const
getFlags - Return the flags for this scope.
bool isExternC() const
Determines whether this variable is a variable with external, C linkage.
QualType getDeclaredReturnType() const
Get the declared return type, which may differ from the actual return type if the return type is dedu...
void adjustDeducedFunctionResultType(FunctionDecl *FD, QualType ResultType)
Change the result type of a function type once it is deduced.
void completeDefinition(QualType NewType, QualType PromotionType, unsigned NumPositiveBits, unsigned NumNegativeBits)
When created, the EnumDecl corresponds to a forward-declared enum.
ConditionalOperator - The ?: ternary operator.
DeclSpec & getMutableDeclSpec()
getMutableDeclSpec - Return a non-const version of the DeclSpec.
RecordDecl * getAsRecordDecl() const
Retrieves the RecordDecl this type refers to.
Sema - This implements semantic analysis and AST building for C.
StringRef getString() const
Merge availability attributes for an implementation of a protocol requirement.
bool isPromotableIntegerType() const
More type predicates useful for type checking/promotion.
static DeclaratorChunk getFunction(bool HasProto, bool IsAmbiguous, SourceLocation LParenLoc, ParamInfo *Params, unsigned NumParams, SourceLocation EllipsisLoc, SourceLocation RParenLoc, bool RefQualifierIsLvalueRef, SourceLocation RefQualifierLoc, SourceLocation MutableLoc, ExceptionSpecificationType ESpecType, SourceRange ESpecRange, ParsedType *Exceptions, SourceRange *ExceptionRanges, unsigned NumExceptions, Expr *NoexceptExpr, CachedTokens *ExceptionSpecTokens, ArrayRef< NamedDecl *> DeclsInPrototype, SourceLocation LocalRangeBegin, SourceLocation LocalRangeEnd, Declarator &TheDeclarator, TypeResult TrailingReturnType=TypeResult(), DeclSpec *MethodQualifiers=nullptr)
DeclaratorChunk::getFunction - Return a DeclaratorChunk for a function.
bool Mutable
Whether this is a mutable lambda.
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
SmallVector< ReturnStmt *, 4 > Returns
The list of return statements that occur within the function or block, if there is any chance of appl...
SourceLocation getUnalignedSpecLoc() const
Represents a prototype with parameter type info, e.g.
bool isFileVarDecl() const
Returns true for file scoped variable declaration.
void MakeTrivial(ASTContext &Context, NestedNameSpecifier *Qualifier, SourceRange R)
Make a new nested-name-specifier from incomplete source-location information.
bool hasConstexprSpecifier() const
void setImplicitlyInline(bool I=true)
Flag that this function is implicitly inline.
void CheckShadowingDeclModification(Expr *E, SourceLocation Loc)
Warn if 'E', which is an expression that is about to be modified, refers to a shadowing declaration...
static void mergeParamDeclAttributes(ParmVarDecl *newDecl, const ParmVarDecl *oldDecl, Sema &S)
mergeParamDeclAttributes - Copy attributes from the old parameter to the new one. ...
CXXConstructorDecl * getConstructor() const
Get the constructor that this expression will (ultimately) call.
TypeSpecifierType isTagName(IdentifierInfo &II, Scope *S)
isTagName() - This method is called for error recovery purposes only to determine if the specified na...
bool inferObjCARCLifetime(ValueDecl *decl)
Represents a ValueDecl that came out of a declarator.
MSInheritanceAttr * mergeMSInheritanceAttr(Decl *D, SourceRange Range, bool BestCase, unsigned AttrSpellingListIndex, MSInheritanceAttr::Spelling SemanticSpelling)
void SetRangeStart(SourceLocation Loc)
static ImplicitCastExpr * Create(const ASTContext &Context, QualType T, CastKind Kind, Expr *Operand, const CXXCastPath *BasePath, ExprValueKind Cat)
DeclarationNameTable DeclarationNames
unsigned NumParams
NumParams - This is the number of formal parameters specified by the declarator.
bool MergeFunctionDecl(FunctionDecl *New, NamedDecl *&Old, Scope *S, bool MergeTypeWithOld)
MergeFunctionDecl - We just parsed a function 'New' from declarator D which has the same name and sco...
const char * getName(unsigned ID) const
Return the identifier name for the specified builtin, e.g.
const Type * getPointeeOrArrayElementType() const
If this is a pointer type, return the pointee type.
const ParsedAttributesView & getAttrs() const
If there are attributes applied to this declaratorchunk, return them.
bool hasQualifiers() const
Determine whether this type has any qualifiers.
bool shouldLinkDependentDeclWithPrevious(Decl *D, Decl *OldDecl)
Checks if the new declaration declared in dependent context must be put in the same redeclaration cha...
bool isEnabled(llvm::StringRef Ext) const
void ActOnFields(Scope *S, SourceLocation RecLoc, Decl *TagDecl, ArrayRef< Decl *> Fields, SourceLocation LBrac, SourceLocation RBrac, const ParsedAttributesView &AttrList)
A conversion function name, e.g., operator int.
SourceRange getRange() const
QuantityType getQuantity() const
getQuantity - Get the raw integer representation of this quantity.
Captures information about a #pragma weak directive.
TypeSourceInfo * getTrivialTypeSourceInfo(QualType T, SourceLocation Loc=SourceLocation()) const
Allocate a TypeSourceInfo where all locations have been initialized to a given location, which defaults to the empty location.
TypeSourceInfo * getTypeSourceInfo() const
unsigned getEditDistance(bool Normalized=true) const
Gets the "edit distance" of the typo correction from the typo.
TST getTypeSpecType() const
QualType getPromotedIntegerType(QualType PromotableType) const
Return the type that PromotableType will promote to: C99 6.3.1.1p2, assuming that PromotableType is a...
static NamedDecl * DiagnoseInvalidRedeclaration(Sema &SemaRef, LookupResult &Previous, FunctionDecl *NewFD, ActOnFDArgs &ExtraArgs, bool IsLocalFriend, Scope *S)
Generate diagnostics for an invalid function redeclaration.
static bool isDeclRep(TST T)
bool isVariableCapture() const
Exposes information about the current target.
static CXXDestructorDecl * Create(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc, const DeclarationNameInfo &NameInfo, QualType T, TypeSourceInfo *TInfo, bool isInline, bool isImplicitlyDeclared)
bool isCLike() const
True if this class is C-like, without C++-specific features, e.g.
bool isMsStruct(const ASTContext &C) const
Get whether or not this is an ms_struct which can be turned on with an attribute, pragma...
bool canFullyTypeCheckRedeclaration(ValueDecl *NewD, ValueDecl *OldD, QualType NewT, QualType OldT)
Determines if we can perform a correct type check for D as a redeclaration of PrevDecl.
SourceLocation getBeginLoc() const
Get the begin source location.
TemplateParameterList * getTemplateParameters() const
Get the list of template parameters.
static CXXConversionDecl * Create(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc, const DeclarationNameInfo &NameInfo, QualType T, TypeSourceInfo *TInfo, bool isInline, ExplicitSpecifier ES, ConstexprSpecKind ConstexprKind, SourceLocation EndLocation)
DeclContext * getLexicalParent()
getLexicalParent - Returns the containing lexical DeclContext.
CXXMethodDecl * CallOperator
The lambda's compiler-generated operator().
const char * getTypeName(ID Id)
getTypeName - Return the name of the type for Id.
A single parameter index whose accessors require each use to make explicit the parameter index encodi...
bool isInlineSpecified() const
Determine whether the "inline" keyword was specified for this function.
Type source information for an attributed type.
QualType getCXXNameType() const
If this name is one of the C++ names (of a constructor, destructor, or conversion function)...
bool isObjCGCStrong() const
true when Type is objc's strong.
Represents a block literal declaration, which is like an unnamed FunctionDecl.
bool isMultiVersion() const
True if this function is considered a multiversioned function.
bool isDependentType() const
Whether this declaration declares a type that is dependent, i.e., a type that somehow depends on temp...
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
This represents one expression.
LookupNameKind
Describes the kind of name lookup to perform.
Decl * ParsedFreeStandingDeclSpec(Scope *S, AccessSpecifier AS, DeclSpec &DS, RecordDecl *&AnonRecord)
ParsedFreeStandingDeclSpec - This method is invoked when a declspec with no declarator (e...
static bool isResultTypeOrTemplate(LookupResult &R, const Token &NextToken)
Determine whether the given result set contains either a type name or.
known_extensions_range known_extensions() const
The "typename" keyword precedes the qualified type name, e.g., typename T::type.
bool isFunctionNoProtoType() const
bool isVariadic() const
Whether this function is variadic.
bool isDefaulted() const
Whether this function is defaulted per C++0x.
void addTypedefNameForUnnamedTagDecl(TagDecl *TD, TypedefNameDecl *TND)
void ResetObjCLayout(const ObjCContainerDecl *CD)
bool isDeclScope(Decl *D)
isDeclScope - Return true if this is the scope that the specified decl is declared in...
bool isInSystemHeader(SourceLocation Loc) const
Returns if a SourceLocation is in a system header.
bool hasLocalStorage() const
Returns true if a variable with function scope is a non-static local variable.
llvm::SmallPtrSet< const Decl *, 4 > ParsingInitForAutoVars
ParsingInitForAutoVars - a set of declarations with auto types for which we are currently parsing the...
static Kind getNullabilityAttrKind(NullabilityKind kind)
Retrieve the attribute kind corresponding to the given nullability kind.
bool isDecompositionDeclarator() const
Return whether this declarator is a decomposition declarator.
const FileEntry * getFileEntryForID(FileID FID) const
Returns the FileEntry record for the provided FileID.
unsigned getIntWidth() const
getIntWidth/Align - Return the size of 'signed int' and 'unsigned int' for this target, in bits.
bool containsDecl(Decl *D) const
Checks whether a declaration is in this context.
static bool checkForConflictWithNonVisibleExternC(Sema &S, const T *ND, LookupResult &Previous)
Apply special rules for handling extern "C" declarations.
DeclContext * getEntity() const
static SourceLocation findLocationAfterToken(SourceLocation loc, tok::TokenKind TKind, const SourceManager &SM, const LangOptions &LangOpts, bool SkipTrailingWhitespaceAndNewLine)
Checks that the given token is the first token that occurs after the given location (this excludes co...
UnqualTypeLoc getUnqualifiedLoc() const
Skips past any qualifiers, if this is qualified.
unsigned SymbolLocations[3]
The source locations of the individual tokens that name the operator, e.g., the "new", "[", and "]" tokens in operator new [].
const IdentifierInfo * getBaseTypeIdentifier() const
Retrieves a pointer to the name of the base type.
bool getHasRegParm() const
This file defines the classes used to store parsed information about declaration-specifiers and decla...
const T * castAs() const
Member-template castAs<specific type>.
static InitializedEntity InitializeVariable(VarDecl *Var)
Create the initialization entity for a variable.
void DiagnoseShadowingLambdaDecls(const sema::LambdaScopeInfo *LSI)
Diagnose shadowing for variables shadowed in the lambda record LambdaRD when these variables are capt...
static bool ValidDuplicateEnum(EnumConstantDecl *ECD, EnumDecl *Enum)
OpaquePtr< T > get() const
T getAs() const
Convert to the specified TypeLoc type, returning a null TypeLoc if this TypeLoc is not of the desired...
Represents a C++ destructor within a class.
const internal::VariadicAllOfMatcher< Decl > decl
Matches declarations.
QualType getParenType(QualType NamedType) const
bool isThisDeclarationADefinition() const
Returns whether this specific declaration of the function is also a definition that does not contain ...
void setInvalidDecl(bool Invalid=true)
setInvalidDecl - Indicates the Decl had a semantic error.
SourceLocation getVolatileSpecLoc() const
bool isAnonymousNamespace() const
Returns true if this is an anonymous namespace declaration.
SourceLocation getThreadStorageClassSpecLoc() const
bool isImplicit() const
isImplicit - Indicates whether the declaration was implicitly generated by the implementation.
void ClearTypeQualifiers()
Clear out all of the type qualifiers.
QualType getTagDeclType(const TagDecl *Decl) const
Return the unique reference to the type for the specified TagDecl (struct/union/class/enum) decl...
Decl * BuildMicrosoftCAnonymousStruct(Scope *S, DeclSpec &DS, RecordDecl *Record)
BuildMicrosoftCAnonymousStruct - Handle the declaration of an Microsoft C anonymous structure...
SourceLocation getLocation() const
Return a source location identifier for the specified offset in the current file. ...
Defines the clang::Preprocessor interface.
static DelayedDiagnostic makeForbiddenType(SourceLocation loc, unsigned diagnostic, QualType type, unsigned argument)
Decl * getMostRecentDecl()
Retrieve the most recent declaration that declares the same entity as this declaration (which may be ...
bool isPredefinedRuntimeFunction(unsigned ID) const
Determines whether this builtin is a predefined compiler-rt/libgcc function, such as "__clear_cache"...
NestedNameSpecifier * getQualifier() const
Retrieve the nested-name-specifier that qualifies the name of this declaration, if it was present in ...
static void CheckPoppedLabel(LabelDecl *L, Sema &S)
Defines the classes clang::DelayedDiagnostic and clang::AccessedEntity.
field_iterator field_end() const
overridden_method_range overridden_methods() const
ObjCLifetime getObjCLifetime() const
bool isLocalExternDecl()
Determine whether this is a block-scope declaration with linkage.
Name lookup results in an ambiguity because an entity with a tag name was hidden by an entity with an...
bool isFileContext() const
bool supportsVariadicCall(CallingConv CC)
Checks whether the given calling convention supports variadic calls.
bool canDecayToPointerType() const
Determines whether this type can decay to a pointer type.
SourceLocation getBeginLoc() const
DeclContext * getDeclContext()
CXXRecordDecl * getDefinition() const
A parsed C++17 decomposition declarator of the form '[' identifier-list ']'.
This declaration is a tentative definition.
static bool PreviousDeclsHaveMultiVersionAttribute(const FunctionDecl *FD)
void setObjCIdRedefinitionType(QualType RedefType)
Set the user-written type that redefines id.
TLSKind getTLSKind() const
AttributeFactory & getFactory() const
static QualType getNextLargerIntegralType(ASTContext &Context, QualType T)
static TagTypeKind getTagTypeKindForTypeSpec(unsigned TypeSpec)
Converts a type specifier (DeclSpec::TST) into a tag type kind.
NestedNameSpecifierLoc getPrefix() const
Return the prefix of this nested-name-specifier.
void setMemberSpecialization()
Note that this member template is a specialization.
bool wasNotFoundInCurrentInstantiation() const
Determine whether no result was found because we could not search into dependent base classes of the ...
StorageClass getStorageClass() const
Returns the storage class as written in the source.
virtual void AssignInheritanceModel(CXXRecordDecl *RD)
Callback invoked when an MSInheritanceAttr has been attached to a CXXRecordDecl.
bool isTemplateParameter() const
isTemplateParameter - Determines whether this declaration is a template parameter.
Represents a C++ template name within the type system.
NamedDecl * ActOnTypedefNameDecl(Scope *S, DeclContext *DC, TypedefNameDecl *D, LookupResult &Previous, bool &Redeclaration)
ActOnTypedefNameDecl - Perform semantic checking for a declaration which declares a typedef-name...
SourceLocation getStorageClassSpecLoc() const
ParmVarDecl *const * param_iterator
Decl * ActOnField(Scope *S, Decl *TagD, SourceLocation DeclStart, Declarator &D, Expr *BitfieldWidth)
ActOnField - Each field of a C struct/union is passed into this in order to create a FieldDecl object...
UnqualifiedIdKind getKind() const
Determine what kind of name we have.
bool isVisible(const NamedDecl *D)
Determine whether a declaration is visible to name lookup.
unsigned short getMaxTLSAlign() const
Return the maximum alignment (in bits) of a TLS variable.
bool isFunctionTemplateSpecialization() const
Determine whether this function is a function template specialization.
void UpdateTypeRep(ParsedType Rep)
AutoType * getContainedAutoType() const
Get the AutoType whose type will be deduced for a variable with an initializer of this type...
IdentifierInfo * getAsIdentifierInfo() const
Retrieve the IdentifierInfo * stored in this declaration name, or null if this declaration name isn't...
bool shouldInheritEvenIfAlreadyPresent() const
Should this attribute be inherited from a prior declaration even if it's explicitly provided in the c...
void setModulePrivate()
Specify that this declaration was marked as being private to the module in which it was defined...
void setConstexpr(bool IC)
FieldDecl * CheckFieldDecl(DeclarationName Name, QualType T, TypeSourceInfo *TInfo, RecordDecl *Record, SourceLocation Loc, bool Mutable, Expr *BitfieldWidth, InClassInitStyle InitStyle, SourceLocation TSSL, AccessSpecifier AS, NamedDecl *PrevDecl, Declarator *D=nullptr)
Build a new FieldDecl and check its well-formedness.
bool isClassScope() const
isClassScope - Return true if this scope is a class/struct/union scope.
bool hasBody(const FunctionDecl *&Definition) const
Returns true if the function has a body.
static void checkNewAttributesAfterDef(Sema &S, Decl *New, const Decl *Old)
checkNewAttributesAfterDef - If we already have a definition, check that there are no new attributes ...
bool isFunctionOrMethod() const
static StorageClass getFunctionStorageClass(Sema &SemaRef, Declarator &D)
bool CheckEnumRedeclaration(SourceLocation EnumLoc, bool IsScoped, QualType EnumUnderlyingTy, bool IsFixed, const EnumDecl *Prev)
Check whether this is a valid redeclaration of a previous enumeration.
static bool hasSimilarParameters(ASTContext &Context, FunctionDecl *Declaration, FunctionDecl *Definition, SmallVectorImpl< unsigned > &Params)
hasSimilarParameters - Determine whether the C++ functions Declaration and Definition have "nearly" m...
StorageClass
Storage classes.
TagDecl * getAsTagDecl() const
Retrieves the TagDecl that this type refers to, either because the type is a TagType or because it is...
bool hasNonTrivialDestructor() const
Determine whether this class has a non-trivial destructor (C++ [class.dtor]p3)
virtual bool validateCpuSupports(StringRef Name) const
static bool HasNonMultiVersionAttributes(const FunctionDecl *FD, MultiVersionKind MVType)
Direct list-initialization (C++11)
bool isSingleResult() const
Determines if this names a single result which is not an unresolved value using decl.
static bool hasParsedAttr(Scope *S, const Declarator &PD, ParsedAttr::Kind Kind)
InClassInitStyle
In-class initialization styles for non-static data members.
QualType getConstantArrayType(QualType EltTy, const llvm::APInt &ArySize, ArrayType::ArraySizeModifier ASM, unsigned IndexTypeQuals) const
Return the unique reference to the type for a constant array of the specified element type...
DeclContext * getParent()
getParent - Returns the containing DeclContext.
ReturnStmt - This represents a return, optionally of an expression: return; return 4;...
An expression that sends a message to the given Objective-C object or class.
QualType getRecordType(const RecordDecl *Decl) const
void MarkTypoCorrectedFunctionDefinition(const NamedDecl *F)
QualType getObjCInterfaceType(const ObjCInterfaceDecl *Decl, ObjCInterfaceDecl *PrevDecl=nullptr) const
getObjCInterfaceType - Return the unique reference to the type for the specified ObjC interface decl...
void setModedTypeSourceInfo(TypeSourceInfo *unmodedTSI, QualType modedTy)
SourceLocation getEnd() const
static bool hasDefinition(const ObjCObjectPointerType *ObjPtr)
UnaryOperator - This represents the unary-expression's (except sizeof and alignof), the postinc/postdec operators from postfix-expression, and various extensions.
QualType getFunctionType(QualType ResultTy, ArrayRef< QualType > Args, const FunctionProtoType::ExtProtoInfo &EPI) const
Return a normal function type with a typed argument list.
struct CXXOpName CXXOperatorName
void addDeclaratorForUnnamedTagDecl(TagDecl *TD, DeclaratorDecl *DD)
bool isDependentContext() const
Determines whether this context is dependent on a template parameter.
DeclContext * getContainingDC(DeclContext *DC)
bool isFriendSpecified() const
Common base class for placeholders for types that get replaced by placeholder type deduction: C++11 a...
const Type * getBaseElementTypeUnsafe() const
Get the base element type of this type, potentially discarding type qualifiers.
APValue * evaluateValue() const
Attempt to evaluate the value of the initializer attached to this declaration, and produce notes expl...
void PushOnScopeChains(NamedDecl *D, Scope *S, bool AddToContext=true)
Add this decl to the scope shadowed decl chains.
bool isCompoundStmtScope() const
Determine whether this scope is a compound statement scope.
void setDescribedClassTemplate(ClassTemplateDecl *Template)
void setStorageClass(StorageClass SC)
Represents a C++ conversion function within a class.
sema::LambdaScopeInfo * PushLambdaScope()
QualType getTypeDeclType(const TypeDecl *Decl, const TypeDecl *PrevDecl=nullptr) const
Return the unique reference to the type for the specified type declaration.
This template specialization was implicitly instantiated from a template.
bool isTrivial() const
Whether this function is "trivial" in some specialized C++ senses.
bool hasNonTrivialToPrimitiveDefaultInitializeCUnion() const
Check if this is or contains a C union that is non-trivial to default-initialize, which is a union th...
NamedDecl * LookupSingleName(Scope *S, DeclarationName Name, SourceLocation Loc, LookupNameKind NameKind, RedeclarationKind Redecl=NotForRedeclaration)
Look up a name, looking for a single declaration.
VisibilityAttr * mergeVisibilityAttr(Decl *D, SourceRange Range, VisibilityAttr::VisibilityType Vis, unsigned AttrSpellingListIndex)
void setQualifierLoc(NestedNameSpecifierLoc QualifierLoc)
SourceLocation getLocation() const
Retrieve the location at which this variable was captured.
QualType withoutLocalFastQualifiers() const
bool isNull() const
Return true if this QualType doesn't point to a type yet.
static bool shouldConsiderLinkage(const VarDecl *VD)
bool hasAutoForTrailingReturnType() const
Determine whether this type was written with a leading 'auto' corresponding to a trailing return type...
bool isTemplateInstantiation(TemplateSpecializationKind Kind)
Determine whether this template specialization kind refers to an instantiation of an entity (as oppos...
static StringRef getIdentifier(const Token &Tok)
static void ReportOverrides(Sema &S, unsigned DiagID, const CXXMethodDecl *MD, OverrideErrorKind OEK=OEK_All)
Report an error regarding overriding, along with any relevant overridden methods. ...
ObjCKeywordKind
Provides a namespace for Objective-C keywords which start with an '@'.
void setTemplateParameterListsInfo(ASTContext &Context, ArrayRef< TemplateParameterList *> TPLists)
void setDeclContext(DeclContext *DC)
setDeclContext - Set both the semantic and lexical DeclContext to DC.
CallingConv
CallingConv - Specifies the calling convention that a function uses.
T getAsAdjusted() const
Convert to the specified TypeLoc type, returning a null TypeLoc if this TypeLoc is not of the desired...
VarDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
SmallVector< Attr *, 4 > AttrVec
AttrVec - A vector of Attr, which is how they are stored on the AST.
FriendObjectKind getFriendObjectKind() const
Determines whether this declaration is the object of a friend declaration and, if so...
decl_type * getFirstDecl()
Return the first declaration of this declaration or itself if this is the only declaration.
static CXXRecordDecl * Create(const ASTContext &C, TagKind TK, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, CXXRecordDecl *PrevDecl=nullptr, bool DelayTypeCreation=false)
static CharSourceRange getCharRange(SourceRange R)
QualType getAttributedType(attr::Kind attrKind, QualType modifiedType, QualType equivalentType)
ExtInfo withNoReturn(bool noReturn) const
bool isConstQualified() const
Determine whether this type is const-qualified.
bool isVoidPointerType() const
static bool checkGlobalOrExternCConflict(Sema &S, const T *ND, bool IsGlobal, LookupResult &Previous)
Check for conflict between this global or extern "C" declaration and previous global or extern "C" de...
bool CheckRedeclarationModuleOwnership(NamedDecl *New, NamedDecl *Old)
We've determined that New is a redeclaration of Old.
static UnqualifiedTypeNameLookupResult lookupUnqualifiedTypeNameInBase(Sema &S, const IdentifierInfo &II, SourceLocation NameLoc, const CXXRecordDecl *RD)
Tries to perform unqualified lookup of the type decls in bases for dependent class.
RecordDecl * getDecl() const
ConstexprSpecKind getConstexprSpecifier() const
static bool CheckMultiVersionValue(Sema &S, const FunctionDecl *FD)
Check the target attribute of the function for MultiVersion validity.
SourceLocation getNoreturnSpecLoc() const
void CheckForFunctionRedefinition(FunctionDecl *FD, const FunctionDecl *EffectiveDefinition=nullptr, SkipBodyInfo *SkipBody=nullptr)
NestedNameSpecifier * getScopeRep() const
Retrieve the representation of the nested-name-specifier.
Decl * ActOnSkippedFunctionBody(Decl *Decl)
InternalLinkageAttr * mergeInternalLinkageAttr(Decl *D, const ParsedAttr &AL)
UnqualifiedTypeNameLookupResult
NamedDecl * ImplicitlyDefineFunction(SourceLocation Loc, IdentifierInfo &II, Scope *S)
ImplicitlyDefineFunction - An undeclared identifier was used in a function call, forming a call to an...
static bool isIncompleteDeclExternC(Sema &S, const T *D)
Determine whether a variable is extern "C" prior to attaching an initializer.
bool isInjectedClassName() const
Determines whether this declaration represents the injected class name.
bool isCtorOrDtor()
Returns true if this declares a constructor or a destructor.
void setTypeForDecl(const Type *TD)
char * location_data() const
Retrieve the data associated with the source-location information.
StringRef getFilename(SourceLocation SpellingLoc) const
Return the filename of the file containing a SourceLocation.
bool isAuxBuiltinID(unsigned ID) const
Return true if builtin ID belongs to AuxTarget.
Wrapper for source info for arrays.
static unsigned getMSManglingNumber(const LangOptions &LO, Scope *S)
There is no lifetime qualification on this type.
Decl::Kind getDeclKind() const
OpaqueValueExpr - An expression referring to an opaque object of a fixed type and value class...
UnqualifiedIdKind Kind
Describes the kind of unqualified-id parsed.
void makeDeclVisibleInContext(NamedDecl *D)
Makes a declaration visible within this context.
void ActOnFinishKNRParamDeclarations(Scope *S, Declarator &D, SourceLocation LocAfterDecls)
Tag name lookup, which finds the names of enums, classes, structs, and unions.
Assigning into this object requires the old value to be released and the new value to be retained...
QualType getCanonicalType() const
ActionResult - This structure is used while parsing/acting on expressions, stmts, etc...
TypeLoc IgnoreParens() const
decl_type * getPreviousDecl()
Return the previous declaration of this declaration or NULL if this is the first declaration.
VarDecl * getVariable() const
static DeclaratorChunk getReference(unsigned TypeQuals, SourceLocation Loc, bool lvalue)
Return a DeclaratorChunk for a reference.
ExtProtoInfo getExtProtoInfo() const
FunctionDecl * getAsFunction() LLVM_READONLY
Returns the function itself, or the templated function if this is a function template.
SCS getStorageClassSpec() const
ASTContext & getASTContext() const
Expr * getAsmLabel() const
redecl_range redecls() const
Returns an iterator range for all the redeclarations of the same decl.
unsigned getMSCurManglingNumber() const
unsigned getNumExprs() const
Return the number of expressions in this paren list.
static bool AllowOverloadingOfFunction(LookupResult &Previous, ASTContext &Context, const FunctionDecl *New)
Determine whether we allow overloading of the function PrevDecl with another declaration.
FunctionDecl * getTemplatedDecl() const
Get the underlying function declaration of the template.
Encodes a location in the source.
bool isTypeSpecOwned() const
Sugar for parentheses used when specifying types.
void setTopLevelDeclInObjCContainer(bool V=true)
QualType getReturnType() const
IdentifierInfo & get(StringRef Name)
Return the identifier token info for the specified named identifier.
bool isPure() const
Whether this virtual function is pure, i.e.
bool CheckForConstantInitializer(Expr *e, QualType t)
type checking declaration initializers (C99 6.7.8)
void ActOnTagFinishDefinition(Scope *S, Decl *TagDecl, SourceRange BraceRange)
ActOnTagFinishDefinition - Invoked once we have finished parsing the definition of a tag (enumeration...
void ActOnDocumentableDecls(ArrayRef< Decl *> Group)
SourceLocation CurrentPragmaLocation
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of enums...
LangAS getAddressSpace() const
Return the address space of this type.
QualType getSingleStepDesugaredType(const ASTContext &Context) const
Return the specified type with one level of "sugar" removed from the type.
Expr * getSubExpr() const
FunctionDefinitionKind getFunctionDefinitionKind() const
bool isVariablyModifiedType() const
Whether this type is a variably-modified type (C99 6.7.5).
CXXRecordDecl * Lambda
The class that describes the lambda.
void setBraceRange(SourceRange R)
std::pair< NullabilityKind, bool > DiagNullabilityKind
A nullability kind paired with a bit indicating whether it used a context-sensitive keyword...
Attr * clone(ASTContext &C) const
UnqualifiedId & getName()
Retrieve the name specified by this declarator.
CastKind getCastKind() const
void FinalizeDeclaration(Decl *D)
FinalizeDeclaration - called by ParseDeclarationAfterDeclarator to perform any semantic actions neces...
bool isLiteralType(const ASTContext &Ctx) const
Return true if this is a literal type (C++11 [basic.types]p10)
void AddKnownFunctionAttributes(FunctionDecl *FD)
Adds any function attributes that we know a priori based on the declaration of this function...
void ActOnPragmaWeakID(IdentifierInfo *WeakName, SourceLocation PragmaLoc, SourceLocation WeakNameLoc)
ActOnPragmaWeakID - Called on well formed #pragma weak ident.
void setFreeStanding(bool isFreeStanding=true)
True if this tag is free standing, e.g. "struct foo;".
void disableCheckFallThrough()
DeclarationName getName() const
getName - Returns the embedded declaration name.
void ExitDeclaratorContext(Scope *S)
The nullability qualifier is set when the nullability of the result or parameter was expressed via a ...
Represents the declaration of a struct/union/class/enum.
LanguageLinkage
Describes the different kinds of language linkage (C++ [dcl.link]) that an entity may have...
MutableArrayRef< Expr * > MultiExprArg
unsigned getLongLongWidth() const
getLongLongWidth/Align - Return the size of 'signed long long' and 'unsigned long long' for this targ...
bool isModulePrivateSpecified() const
static const TST TST_union
CallingConv getCC() const
bool declarationReplaces(NamedDecl *OldD, bool IsKnownNewer=true) const
Determine whether this declaration, if known to be well-formed within its context, will replace the declaration OldD if introduced into scope.
InheritableAttr * getDLLAttr(Decl *D)
Return a DLL attribute from the declaration.
unsigned getSpellingListIndex() const
ExitFunctionBodyRAII(Sema &S, bool IsLambda)
void setTemplateParameterListsInfo(ASTContext &Context, ArrayRef< TemplateParameterList *> TPLists)
QualType getObjCSelType() const
Retrieve the type that corresponds to the predefined Objective-C 'SEL' type.
Represents the declaration of a label.
ParsedAttr - Represents a syntactic attribute.
bool SetStorageClassSpec(Sema &S, SCS SC, SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID, const PrintingPolicy &Policy)
These methods set the specified attribute of the DeclSpec and return false if there was no error...
const DecompositionDeclarator & getDecompositionDeclarator() const
QualType getBaseElementType(const ArrayType *VAT) const
Return the innermost element type of an array type.
bool isIntegralType(const ASTContext &Ctx) const
Determine whether this type is an integral type.
Represents a static or instance method of a struct/union/class.
void setDefaulted(bool D=true)
void setHasFlexibleArrayMember(bool V)
SourceLocation getStrTokenLoc(unsigned TokNum) const
Get one of the string literal token.
bool shouldDelayDiagnostics()
Determines whether diagnostics should be delayed.
DeclarationNameInfo getNameForTemplate(TemplateName Name, SourceLocation NameLoc) const
bool canDelayFunctionBody(const Declarator &D)
Determine whether we can delay parsing the body of a function or function template until it is used...
void notePreviousDefinition(const NamedDecl *Old, SourceLocation New)
bool isConst(unsigned ID) const
Return true if this function has no side effects and doesn't read memory.
bool hasGlobalStorage() const
Returns true for all variables that do not have local storage.
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
void addOverriddenMethod(const CXXMethodDecl *MD)
static ParsedType buildNestedType(Sema &S, CXXScopeSpec &SS, QualType T, SourceLocation NameLoc)
Build a ParsedType for a simple-type-specifier with a nested-name-specifier.
void setEntity(DeclContext *E)
SectionAttr * mergeSectionAttr(Decl *D, SourceRange Range, StringRef Name, unsigned AttrSpellingListIndex)
const ParmVarDecl * getParamDecl(unsigned i) const
NameClassification ClassifyName(Scope *S, CXXScopeSpec &SS, IdentifierInfo *&Name, SourceLocation NameLoc, const Token &NextToken, bool IsAddressOfOperand, CorrectionCandidateCallback *CCC=nullptr)
Perform name lookup on the given name, classifying it based on the results of name lookup and the fol...
void demoteThisDefinitionToDeclaration()
This is a definition which should be demoted to a declaration.
bool isFirstDecl() const
True if this is the first declaration in its redeclaration chain.
SourceLocation getLocation() const
A friend of a previously-declared entity.
Name lookup found an unresolvable value declaration and cannot yet complete.
MemberPointerTypeInfo Mem
const ArrayType * getAsArrayType(QualType T) const
Type Query functions.
static bool CheckMultiVersionAdditionalRules(Sema &S, const FunctionDecl *OldFD, const FunctionDecl *NewFD, bool CausesMV, MultiVersionKind MVType)
ObjCCategoryDecl - Represents a category declaration.
bool MergeCompatibleFunctionDecls(FunctionDecl *New, FunctionDecl *Old, Scope *S, bool MergeTypeWithOld)
Completes the merge of two function declarations that are known to be compatible. ...
bool isSignedIntegerOrEnumerationType() const
Determines whether this is an integer type that is signed or an enumeration types whose underlying ty...
bool isScoped() const
Returns true if this is a C++11 scoped enumeration.
TokenKind
Provides a simple uniform namespace for tokens from all C languages.
bool isInMainFile(SourceLocation Loc) const
Returns whether the PresumedLoc for a given SourceLocation is in the main file.
Describes the kind of initialization being performed, along with location information for tokens rela...
bool isValueDependent() const
isValueDependent - Determines whether this expression is value-dependent (C++ [temp.dep.constexpr]).
TypoCorrection CorrectTypo(const DeclarationNameInfo &Typo, Sema::LookupNameKind LookupKind, Scope *S, CXXScopeSpec *SS, CorrectionCandidateCallback &CCC, CorrectTypoKind Mode, DeclContext *MemberContext=nullptr, bool EnteringContext=false, const ObjCObjectPointerType *OPT=nullptr, bool RecordFailure=true)
Try to "correct" a typo in the source code by finding visible declarations whose names are similar to...
bool isObjCObjectPointerType() const
Decl * getRepAsDecl() const
FunctionTemplateDecl * getPreviousDecl()
Retrieve the previous declaration of this function template, or nullptr if no such declaration exists...
A class for iterating through a result set and possibly filtering out results.
This declaration is only a declaration.
SmallVector< Capture, 4 > Captures
Captures - The captures.
bool isMSAsmLabel() const
bool isSimpleTypeSpecifier(tok::TokenKind Kind) const
Determine whether the token kind starts a simple-type-specifier.
ImplicitCastExpr - Allows us to explicitly represent implicit type conversions, which have no direct ...
uint32_t TypeID
An ID number that refers to a type in an AST file.
bool isFunctionProtoType() const
DestructionKind isDestructedType() const
Returns a nonzero value if objects of this type require non-trivial work to clean up after...
static const TST TST_typeofType
bool hasLinkageBeenComputed() const
True if something has required us to compute the linkage of this declaration.
No entity found met the criteria.
bool isHeaderDependentFunction(unsigned ID) const
Returns true if this builtin requires appropriate header in other compilers.
bool isUsed(bool CheckUsedAttr=true) const
Whether any (re-)declaration of the entity was used, meaning that a definition is required...
FunctionTemplateDecl * getInstantiatedFromMemberTemplate() const
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
PrimitiveCopyKind isNonTrivialToPrimitiveCopy() const
Check if this is a non-trivial type that would cause a C struct transitively containing this type to ...
SourceLocation getRAngleLoc() const
bool isExplicitlyDefaulted() const
Whether this function is explicitly defaulted per C++0x.
AlwaysInlineAttr * mergeAlwaysInlineAttr(Decl *D, SourceRange Range, IdentifierInfo *Ident, unsigned AttrSpellingListIndex)
DeclarationNameInfo getNameInfo() const
bool isStaticMember()
Returns true if this declares a static member.
virtual bool validateCpuIs(StringRef Name) const
SourceLocation getInlineSpecLoc() const
static void diagnoseVarDeclTypeMismatch(Sema &S, VarDecl *New, VarDecl *Old)
Assigning into this object requires a lifetime extension.
void checkNonTrivialCUnionInInitializer(const Expr *Init, SourceLocation Loc)
Emit diagnostics if the initializer or any of its explicit or implicitly-generated subexpressions req...
static bool isExternC(T *D)
void ActOnFinishInlineFunctionDef(FunctionDecl *D)
bool isScanfLike(unsigned ID, unsigned &FormatIdx, bool &HasVAListArg)
Determine whether this builtin is like scanf in its formatting rules and, if so, set the index to the...
bool hasImplicitReturnZero() const
Whether falling off this function implicitly returns null/zero.
void setObjCSuperType(QualType ST)
comments::FullComment * getCommentForDecl(const Decl *D, const Preprocessor *PP) const
Return parsed documentation comment attached to a given declaration.
bool hasFlexibleArrayMember() const
void setLAngleLoc(SourceLocation Loc)
bool isInvalid() const
An error occurred during parsing of the scope specifier.
static bool isRepresentableIntegerValue(ASTContext &Context, llvm::APSInt &Value, QualType T)
Determine whether the given integral value is representable within the given type T...
void setFunctionDefinitionKind(FunctionDefinitionKind Val)
bool hasSameUnqualifiedType(QualType T1, QualType T2) const
Determine whether the given types are equivalent after cvr-qualifiers have been removed.
virtual bool isOutOfLine() const
Determine whether this declaration is declared out of line (outside its semantic context).
UuidAttr * mergeUuidAttr(Decl *D, SourceRange Range, unsigned AttrSpellingListIndex, StringRef Uuid)
static unsigned isEnabled(DiagnosticsEngine &D, unsigned diag)
static void LookupPredefedObjCSuperType(Sema &ThisSema, Scope *S, IdentifierInfo *II)
Looks up the declaration of "struct objc_super" and saves it for later use in building builtin declar...
static unsigned getRedeclDiagFromTagKind(TagTypeKind Tag)
Get diagnostic select index for tag kind for redeclaration diagnostic message.
bool isDesignatedInitializerForTheInterface(const ObjCMethodDecl **InitMethod=nullptr) const
Returns true if the method selector resolves to a designated initializer in the class's interface...
DLLImportAttr * mergeDLLImportAttr(Decl *D, SourceRange Range, unsigned AttrSpellingListIndex)
Sema & getSema() const
Get the Sema object that this lookup result is searching with.
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
MultiVersionKind getMultiVersionKind() const
Gets the kind of multiversioning attribute this declaration has.
void setVirtualAsWritten(bool V)
State that this function is marked as virtual explicitly.
TypeLoc getElementLoc() const
bool hasInClassInitializer() const
Whether this class has any in-class initializers for non-static data members (including those in anon...
CXXSpecialMember getSpecialMember(const CXXMethodDecl *MD)
getSpecialMember - get the special member enum for a method.
SourceLocation getModulePrivateSpecLoc() const
ObjCDeclQualifier getObjCDeclQualifier() const
StringRef getName() const
Return the actual identifier string.
static bool isOutOfScopePreviousDeclaration(NamedDecl *, DeclContext *, ASTContext &)
Determines whether the given declaration is an out-of-scope previous declaration. ...
SourceRange getSourceRange() const LLVM_READONLY
Get the source range that spans this declarator.
void takeAttributes(ParsedAttributes &attrs, SourceLocation lastLoc)
takeAttributes - Takes attributes from the given parsed-attributes set and add them to this declarato...
NamedDecl * getShadowedDeclaration(const TypedefNameDecl *D, const LookupResult &R)
Return the declaration shadowed by the given typedef D, or null if it doesn't shadow any declaration ...
CanQualType UnsignedShortTy
static unsigned getMaxSizeBits(const ASTContext &Context)
Determine the maximum number of active bits that an array's size can require, which limits the maximu...
bool isObjCGCWeak() const
true when Type is objc's weak.
void diagnoseTypo(const TypoCorrection &Correction, const PartialDiagnostic &TypoDiag, bool ErrorRecovery=true)
Base class for declarations which introduce a typedef-name.
TLS with a dynamic initializer.
void ActOnReenterFunctionContext(Scope *S, Decl *D)
Push the parameters of D, which must be a function, into scope.
LabelStmt * getStmt() const
bool isScopedEnumeralType() const
Determine whether this type is a scoped enumeration type.
Represents a type which was implicitly adjusted by the semantic engine for arbitrary reasons...
NonTagKind getNonTagTypeDeclKind(const Decl *D, TagTypeKind TTK)
Given a non-tag type declaration, returns an enum useful for indicating what kind of non-tag type thi...
static DeclGroupRef Create(ASTContext &C, Decl **Decls, unsigned NumDecls)
Expr * getFalseExpr() const
getFalseExpr - Return the subexpression which will be evaluated if the condnition evaluates to false;...
TagTypeKind
The kind of a tag type.
static ParmVarDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo, StorageClass S, Expr *DefArg)
static LinkageSpecDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation ExternLoc, SourceLocation LangLoc, LanguageIDs Lang, bool HasBraces)
Dataflow Directional Tag Classes.
ConstexprSpecKind
Define the kind of constexpr specifier.
static void FixInvalidVariablyModifiedTypeLoc(TypeLoc SrcTL, TypeLoc DstTL)
bool isValid() const
Return true if this is a valid SourceLocation object.
DeducedType * getContainedDeducedType() const
Get the DeducedType whose type will be deduced for a variable with an initializer of this type...
ExtInfo getExtInfo() const
void setHasVolatileMember(bool val)
ParmVarDecl * BuildParmVarDeclForTypedef(DeclContext *DC, SourceLocation Loc, QualType T)
Synthesizes a variable for a parameter arising from a typedef.
A qualifier set is used to build a set of qualifiers.
QualType mergeTypes(QualType, QualType, bool OfBlockPointer=false, bool Unqualified=false, bool BlockReturnType=false)
bool isLateTemplateParsed() const
Whether this templated function will be late parsed.
static const CXXRecordDecl * findRecordWithDependentBasesOfEnclosingMethod(const DeclContext *DC)
Find the parent class with dependent bases of the innermost enclosing method context.
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
EvalResult is a struct with detailed info about an evaluated expression.
The base class of all kinds of template declarations (e.g., class, function, etc.).
void EnterDeclaratorContext(Scope *S, DeclContext *DC)
EnterDeclaratorContext - Used when we must lookup names in the context of a declarator's nested name ...
static const TST TST_decltype
llvm::SmallVector< std::pair< SourceLocation, const BlockDecl * >, 1 > ImplicitlyRetainedSelfLocs
List of SourceLocations where 'self' is implicitly retained inside a block.
static const TST TST_auto
const Scope * getParent() const
getParent - Return the scope that this is nested in.
static bool CheckAnonMemberRedeclaration(Sema &SemaRef, Scope *S, DeclContext *Owner, DeclarationName Name, SourceLocation NameLoc, bool IsUnion)
We are trying to inject an anonymous member into the given scope; check if there's an existing declar...
QualType getType() const
Get the type for which this source info wrapper provides information.
bool isFunctionOrFunctionTemplate() const
Whether this declaration is a function or function template.
SourceLocation RAngleLoc
The location of the '>' after the template argument list.
Qualifiers getMethodQualifiers() const
Represents a field injected from an anonymous union/struct into the parent scope. ...
bool isCopyConstructor(unsigned &TypeQuals) const
Whether this constructor is a copy constructor (C++ [class.copy]p2, which can be used to copy the cla...
bool isDependentAddressSpaceType() const
bool ShouldWarnIfUnusedFileScopedDecl(const DeclaratorDecl *D) const
QualType getUnderlyingType() const
bool DiagRuntimeBehavior(SourceLocation Loc, const Stmt *Statement, const PartialDiagnostic &PD)
Conditionally issue a diagnostic based on the current evaluation context.
unsigned getNextFunctionPrototypeIndex()
Return the number of parameters declared in this function prototype, increasing it by one for the nex...
CanQualType UnsignedLongLongTy
bool isDependent() const
Whether this nested name specifier refers to a dependent type or not.
bool isMissingDeclaratorOk()
Checks if this DeclSpec can stand alone, without a Declarator.
SourceLocation getIncludeLoc(FileID FID) const
Returns the include location if FID is a #include'd file otherwise it returns an invalid location...
static FixItHint CreateRemoval(CharSourceRange RemoveRange)
Create a code modification hint that removes the given source range.
const Expr * getInit() const
AccessSpecifier getAccess() const
ObjCInterfaceDecl * getDefinition()
Retrieve the definition of this class, or NULL if this class has been forward-declared (with @class) ...
A decomposition declaration.
MapType::iterator iterator
This is a scope that corresponds to the template parameters of a C++ template.
void setShadowed()
Note that we found and ignored a declaration while performing lookup.
void setWillHaveBody(bool V=true)
NamedDecl * getCorrectionDecl() const
Gets the pointer to the declaration of the typo correction.
The name of a declaration.
NamedDecl * getFoundDecl() const
Fetch the unique decl found by this lookup.
static ObjCIvarDecl::AccessControl TranslateIvarVisibility(tok::ObjCKeywordKind ivarVisibility)
TranslateIvarVisibility - Translate visibility from a token ID to an AST enum value.
static std::string getAsString(SplitQualType split, const PrintingPolicy &Policy)
bool isCXXClassMember() const
Determine whether this declaration is a C++ class member.
const CXXRecordDecl * getParent() const
Return the parent of this method declaration, which is the class in which this method is defined...
bool isBooleanType() const
const Type * strip(QualType type)
Collect any qualifiers on the given type and return an unqualified type.
void handleTagNumbering(const TagDecl *Tag, Scope *TagScope)
QualType getFunctionNoProtoType(QualType ResultTy, const FunctionType::ExtInfo &Info) const
Return a K&R style C function type like 'int()'.
bool isOneOf(tok::TokenKind K1, tok::TokenKind K2) const
void PushDeclContext(Scope *S, DeclContext *DC)
Set the current declaration context until it gets popped.
static FunctionDecl * CreateNewFunctionDecl(Sema &SemaRef, Declarator &D, DeclContext *DC, QualType &R, TypeSourceInfo *TInfo, StorageClass SC, bool &IsVirtualOkay)
MangleNumberingContext & getManglingNumberContext(const DeclContext *DC)
Retrieve the context for computing mangling numbers in the given DeclContext.
bool isMSVCRTEntryPoint() const
Determines whether this function is a MSVCRT user defined entry point.
A mapping from each virtual member function to its set of final overriders.
unsigned getNumTemplateParameterLists() const
redecl_iterator redecls_end() const
void setInlineSpecified()
void mergeNRVOIntoParent()
ObjCIvarDecl * getIvarDecl(IdentifierInfo *Id) const
getIvarDecl - This method looks up an ivar in this ContextDecl.
A pointer to member type per C++ 8.3.3 - Pointers to members.
bool isIntegerConstantExpr(llvm::APSInt &Result, const ASTContext &Ctx, SourceLocation *Loc=nullptr, bool isEvaluated=true) const
isIntegerConstantExpr - Return true if this expression is a valid integer constant expression...
bool isCopyAssignmentOperator() const
Determine whether this is a copy-assignment operator, regardless of whether it was declared implicitl...
static bool isTagTypeWithMissingTag(Sema &SemaRef, LookupResult &Result, Scope *S, CXXScopeSpec &SS, IdentifierInfo *&Name, SourceLocation NameLoc)
const FunctionType * adjustFunctionType(const FunctionType *Fn, FunctionType::ExtInfo EInfo)
Change the ExtInfo on a function type.
static bool ShouldDiagnoseUnusedDecl(const NamedDecl *D)
bool isAggregateType() const
Determines whether the type is a C++ aggregate type or C aggregate or union type. ...
void ActOnStartCXXMemberDeclarations(Scope *S, Decl *TagDecl, SourceLocation FinalLoc, bool IsFinalSpelledSealed, SourceLocation LBraceLoc)
ActOnStartCXXMemberDeclarations - Invoked when we have parsed a C++ record definition's base-specifie...
bool isInitCapture() const
Whether this variable is the implicit variable for a lambda init-capture.
TypeLoc getModifiedLoc() const
The modified type, which is generally canonically different from the attribute type.
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspnd...
QualType apply(const ASTContext &Context, QualType QT) const
Apply the collected qualifiers to the given type.
void setPreviousDeclInSameBlockScope(bool Same)
bool isTemplateInstantiation() const
Determines if the given function was instantiated from a function template.
static EnumDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, EnumDecl *PrevDecl, bool IsScoped, bool IsScopedUsingClassTag, bool IsFixed)
ParmVarDecl * CheckParameter(DeclContext *DC, SourceLocation StartLoc, SourceLocation NameLoc, IdentifierInfo *Name, QualType T, TypeSourceInfo *TSInfo, StorageClass SC)
The name refers to a template whose specialization produces a type.
SourceLocation getBeginLoc() const LLVM_READONLY
static const TST TST_unspecified
static bool ShouldWarnAboutMissingPrototype(const FunctionDecl *FD, const FunctionDecl *&PossiblePrototype)
static FileScopeAsmDecl * Create(ASTContext &C, DeclContext *DC, StringLiteral *Str, SourceLocation AsmLoc, SourceLocation RParenLoc)
IdentifierInfo * getCorrectionAsIdentifierInfo() const
specific_decl_iterator - Iterates over a subrange of declarations stored in a DeclContext, providing only those that are of type SpecificDecl (or a class derived from it).
void AddInitializerToDecl(Decl *dcl, Expr *init, bool DirectInit)
AddInitializerToDecl - Adds the initializer Init to the declaration dcl.
bool isUndeducedType() const
Determine whether this type is an undeduced type, meaning that it somehow involves a C++11 'auto' typ...
bool DeclAttrsMatchCUDAMode(const LangOptions &LangOpts, Decl *D)
bool hasNonTrivialCopyAssignment() const
Determine whether this class has a non-trivial copy assignment operator (C++ [class.copy]p11, C++11 [class.copy]p25)
static std::pair< diag::kind, SourceLocation > getNoteDiagForInvalidRedeclaration(const T *Old, const T *New)
void setObjectOfFriendDecl(bool PerformFriendInjection=false)
Changes the namespace of this declaration to reflect that it's the object of a friend declaration...
Expr * IgnoreParenImpCasts() LLVM_READONLY
Skip past any parentheses and implicit casts which might surround this expression until reaching a fi...
TemplateNameKindForDiagnostics getTemplateNameKindForDiagnostics(TemplateName Name)
llvm::APInt getValue() const
QualType getModifiedType() const
void setLocalExternDecl()
Changes the namespace of this declaration to reflect that it's a function-local extern declaration...
void setNameLoc(SourceLocation Loc)
SourceLocation getRBracketLoc() const
AvailabilityMergeKind
Describes the kind of merge to perform for availability attributes (including "deprecated", "unavailable", and "availability").
NamedDecl * ActOnTypedefDeclarator(Scope *S, Declarator &D, DeclContext *DC, TypeSourceInfo *TInfo, LookupResult &Previous)
SourceRange getSourceRange() const LLVM_READONLY
Get the full source range.
SourceLocation DefinitionLoc
The location of the module definition.
UsingDecl * getUsingDecl() const
Gets the using declaration to which this declaration is tied.
Name lookup found a single declaration that met the criteria.
void setImplicitlyInline()
static ObjCIvarDecl * Create(ASTContext &C, ObjCContainerDecl *DC, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo, AccessControl ac, Expr *BW=nullptr, bool synthesized=false)
TypeLoc getPointeeLoc() const
unsigned getIntWidth(QualType T) const
ObjCImplementationDecl - Represents a class definition - this is where method definitions are specifi...
bool isIncompleteArrayType() const
bool isClosedFlag() const
Returns true if this enum is annotated with flag_enum and isn't annotated with enum_extensibility(ope...
bool lookupInBases(BaseMatchesCallback BaseMatches, CXXBasePaths &Paths, bool LookupInDependent=false) const
Look for entities within the base classes of this C++ class, transitively searching all base class su...
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
bool isModulePurview() const
Does this Module scope describe part of the purview of a named C++ module?
void setIsUsed()
Set whether the declaration is used, in the sense of odr-use.
void DiagnoseUnusedParameters(ArrayRef< ParmVarDecl *> Parameters)
Diagnose any unused parameters in the given sequence of ParmVarDecl pointers.
void setQualifierInfo(NestedNameSpecifierLoc QualifierLoc)
void addThisCapture(bool isNested, SourceLocation Loc, QualType CaptureType, bool ByCopy)
void ActOnTagDefinitionError(Scope *S, Decl *TagDecl)
ActOnTagDefinitionError - Invoked when there was an unrecoverable error parsing the definition of a t...
bool checkInitIsICE() const
Determine whether the value of the initializer attached to this declaration is an integral constant e...
unsigned getTypeQualifiers() const
getTypeQualifiers - Return a set of TQs.
TemplateName getAssumedTemplateName(DeclarationName Name) const
Retrieve a template name representing an unqualified-id that has been assumed to name a template for ...
static void GenerateFixForUnusedDecl(const NamedDecl *D, ASTContext &Ctx, FixItHint &Hint)
void add(const sema::DelayedDiagnostic &diag)
Adds a delayed diagnostic.
SourceLocation getVirtualSpecLoc() const
bool isReserveIDT() const
unsigned hasPrototype
hasPrototype - This is true if the function had at least one typed parameter.
This template specialization was declared or defined by an explicit specialization (C++ [temp...
bool isConstantInitializer(ASTContext &Ctx, bool ForRef, const Expr **Culprit=nullptr) const
isConstantInitializer - Returns true if this expression can be emitted to IR as a constant...
CanQualType UnsignedLongTy
void setConstexprKind(ConstexprSpecKind CSK)
void setNonMemberOperator()
Specifies that this declaration is a C++ overloaded non-member.
void setQualifierInfo(NestedNameSpecifierLoc QualifierLoc)
void ActOnEnumBody(SourceLocation EnumLoc, SourceRange BraceRange, Decl *EnumDecl, ArrayRef< Decl *> Elements, Scope *S, const ParsedAttributesView &Attr)
bool isDeclInScope(NamedDecl *D, DeclContext *Ctx, Scope *S=nullptr, bool AllowInlineNamespace=false)
isDeclInScope - If 'Ctx' is a function/method, isDeclInScope returns true if 'D' is in Scope 'S'...
EnumConstantDecl * CheckEnumConstant(EnumDecl *Enum, EnumConstantDecl *LastEnumConst, SourceLocation IdLoc, IdentifierInfo *Id, Expr *val)
Expr * getCond() const
getCond - Return the condition expression; this is defined in terms of the opaque value...
static Scope * getScopeForDeclContext(Scope *S, DeclContext *DC)
Finds the scope corresponding to the given decl context, if it happens to be an enclosing scope...
bool isFunctionType() const
void setTypeSourceInfo(TypeSourceInfo *TI)
bool isStaticLocal() const
Returns true if a variable with function scope is a static local variable.
void setNonKeyFunction(const CXXMethodDecl *method)
Observe that the given method cannot be a key function.
TypeSourceInfo * getTypeSourceInfo() const
static const TST TST_typename
Expr * getSizeExpr() const
Expr * getArg(unsigned Arg)
Return the specified argument.
param_const_iterator param_begin() const
Base for LValueReferenceType and RValueReferenceType.
DeclContext * getRedeclContext()
getRedeclContext - Retrieve the context in which an entity conflicts with other entities of the same ...
bool hasSameType(QualType T1, QualType T2) const
Determine whether the given types T1 and T2 are equivalent.
Simple template class for restricting typo correction candidates to ones having a single Decl* of the...
QualType getAutoDeductType() const
C++11 deduction pattern for 'auto' type.
TypeSourceInfo * RebuildTypeInCurrentInstantiation(TypeSourceInfo *T, SourceLocation Loc, DeclarationName Name)
Rebuilds a type within the context of the current instantiation.
SourceLocation getLBracketLoc() const
void ActOnPragmaRedefineExtname(IdentifierInfo *WeakName, IdentifierInfo *AliasName, SourceLocation PragmaLoc, SourceLocation WeakNameLoc, SourceLocation AliasNameLoc)
ActOnPragmaRedefineExtname - Called on well formed #pragma redefine_extname oldname newname...
void setHasNonTrivialToPrimitiveDestructCUnion(bool V)
void setCXXForRangeDecl(bool FRD)
Internal linkage, which indicates that the entity can be referred to from within the translation unit...
void ActOnCXXForRangeDecl(Decl *D)
static bool isOpenCLSizeDependentType(ASTContext &C, QualType Ty)
Decl * BuildAnonymousStructOrUnion(Scope *S, DeclSpec &DS, AccessSpecifier AS, RecordDecl *Record, const PrintingPolicy &Policy)
BuildAnonymousStructOrUnion - Handle the declaration of an anonymous structure or union...
static FixItHint CreateInsertion(SourceLocation InsertionLoc, StringRef Code, bool BeforePreviousInsertions=false)
Create a code modification hint that inserts the given code string at a specific location.
void addDecl(Decl *D)
Add the declaration D into this context.
static SourceLocation findDefaultInitializer(const CXXRecordDecl *Record)
Implements a partial diagnostic that can be emitted anwyhere in a DiagnosticBuilder stream...
void setInherited(bool I)
Sema::LookupNameKind getLookupKind() const
Gets the kind of lookup to perform.
StmtResult ActOnCXXForRangeIdentifier(Scope *S, SourceLocation IdentLoc, IdentifierInfo *Ident, ParsedAttributes &Attrs, SourceLocation AttrEnd)
Optional< NullabilityKind > getNullability(const ASTContext &context) const
Determine the nullability of the given type.
void AddTypeInfo(const DeclaratorChunk &TI, ParsedAttributes &&attrs, SourceLocation EndLoc)
AddTypeInfo - Add a chunk to this declarator.
bool isConstantArrayType() const
APValue - This class implements a discriminated union of [uninitialized] [APSInt] [APFloat]...
Represents a base class of a C++ class.
CXXScopeSpec & getTypeSpecScope()
static QualType GetTypeFromParser(ParsedType Ty, TypeSourceInfo **TInfo=nullptr)
void setNamedTypeInfo(TypeSourceInfo *TInfo)
setNamedTypeInfo - Sets the source type info associated to the name.
uint64_t getTypeSize(QualType T) const
Return the size of the specified (complete) type T, in bits.
This is a scope that can contain a declaration.
SourceManager & getSourceManager()
void * SkippedDefinitionContext
const IdentifierInfo * getLiteralIdentifier() const
getLiteralIdentifier - The literal suffix identifier this function represents, if any...
bool isObjCObjectType() const
bool isIncompleteType(NamedDecl **Def=nullptr) const
Types are partitioned into 3 broad categories (C99 6.2.5p1): object types, function types...
bool SetTypeSpecType(TST T, SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID, const PrintingPolicy &Policy)
NamedDecl * HandleDeclarator(Scope *S, Declarator &D, MultiTemplateParamsArg TemplateParameterLists)
bool isInlined() const
Determine whether this function should be inlined, because it is either marked "inline" or "constexpr...
bool LookupQualifiedName(LookupResult &R, DeclContext *LookupCtx, bool InUnqualifiedLookup=false)
Perform qualified name lookup into a given context.
SourceLocation getIdentifierLoc() const
CanQualType getCanonicalType(QualType T) const
Return the canonical (structural) type corresponding to the specified potentially non-canonical type ...
llvm::iterator_range< specific_attr_iterator< T > > specific_attrs() const
void setPromotionType(QualType T)
Set the promotion type.
ObjCInterfaceDecl * getObjCInterfaceDecl(IdentifierInfo *&Id, SourceLocation IdLoc, bool TypoCorrection=false)
Look for an Objective-C class in the translation unit.
bool isSet() const
Deprecated.
TypeLoc getTypeLoc() const
Return the TypeLoc wrapper for the type source info.
SourceRange getSourceRange() const
bool isNoThrow(unsigned ID) const
Return true if we know this builtin never throws an exception.
ClassTemplateDecl * getDescribedClassTemplate() const
Retrieves the class template that is described by this class declaration.
TypedefNameDecl * getDecl() const
void setLoc(SourceLocation L)
setLoc - Sets the main location of the declaration name.
void setInvalidType(bool Val=true)
CharUnits toCharUnitsFromBits(int64_t BitSize) const
Convert a size in bits to a size in characters.
Reading or writing from this object requires a barrier call.
ExternCContextDecl * getExternCContextDecl() const
QualType deduceVarTypeFromInitializer(VarDecl *VDecl, DeclarationName Name, QualType Type, TypeSourceInfo *TSI, SourceRange Range, bool DirectInit, Expr *Init)
static bool isClassCompatTagKind(TagTypeKind Tag)
Determine if tag kind is a class-key compatible with class for redeclaration (class, struct, or __interface).
static bool isMainFileLoc(const Sema &S, SourceLocation Loc)
bool isResolvedMSAsmLabel() const
An attributed type is a type to which a type attribute has been applied.
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate.h) and friends (in DeclFriend.h).
QualType getParamType(unsigned i) const
Call-style initialization (C++98)
bool EvaluateAsInt(EvalResult &Result, const ASTContext &Ctx, SideEffectsKind AllowSideEffects=SE_NoSideEffects, bool InConstantContext=false) const
EvaluateAsInt - Return true if this is a constant which we can fold and convert to an integer...
bool typesAreCompatible(QualType T1, QualType T2, bool CompareUnqualified=false)
Compatibility predicates used to check assignment expressions.
bool Failed() const
Determine whether the initialization sequence is invalid.
TranslationUnitDecl * getTranslationUnitDecl() const
MemberExpr - [C99 6.5.2.3] Structure and Union Members.
ThreadStorageClassSpecifier
Thread storage-class-specifier.
void addCapture(VarDecl *Var, bool isBlock, bool isByref, bool isNested, SourceLocation Loc, SourceLocation EllipsisLoc, QualType CaptureType, bool Invalid)
Describes the sequence of initializations required to initialize a given object or reference with a s...
static QualType TryToFixInvalidVariablyModifiedType(QualType T, ASTContext &Context, bool &SizeIsNegative, llvm::APSInt &Oversized)
Helper method to turn variable array types into constant array types in certain situations which woul...
NestedNameSpecifierLoc getWithLocInContext(ASTContext &Context) const
Retrieve a nested-name-specifier with location information, copied into the given AST context...
static DeclContext * getTagInjectionContext(DeclContext *DC)
Find the DeclContext in which a tag is implicitly declared if we see an elaborated type specifier in ...
Captures information about "declaration specifiers".
QualType getUnqualifiedType() const
Retrieve the unqualified variant of the given type, removing as little sugar as possible.
SourceLocation getRestrictSpecLoc() const
TypedefNameDecl * getTypedefNameForAnonDecl() const
bool CheckFunctionDeclaration(Scope *S, FunctionDecl *NewFD, LookupResult &Previous, bool IsMemberSpecialization)
Perform semantic checking of a new function declaration.
DeclGroupPtrTy FinalizeDeclaratorGroup(Scope *S, const DeclSpec &DS, ArrayRef< Decl *> Group)
bool isThisDeclarationADefinition() const
Return true if this declaration is a completion definition of the type.
void addModuleInitializer(Module *M, Decl *Init)
Add a declaration to the list of declarations that are initialized for a module.
const CXXMethodDecl * getCurrentKeyFunction(const CXXRecordDecl *RD)
Get our current best idea for the key function of the given record decl, or nullptr if there isn't on...
ShadowedDeclKind
Enum describing the select options in diag::warn_decl_shadow.
Represents a C++ struct/union/class.
A factory, from which one makes pools, from which one creates individual attributes which are dealloc...
static bool isCompoundAssignmentOp(Opcode Opc)
static const TSCS TSCS_thread_local
void setTSCSpec(ThreadStorageClassSpecifier TSC)
static void RemoveUsingDecls(LookupResult &R)
Removes using shadow declarations from the lookup results.
void MergeVarDecl(VarDecl *New, LookupResult &Previous)
MergeVarDecl - We just parsed a variable 'New' which has the same name and scope as a previous declar...
SmallVectorImpl< UniqueVirtualMethod >::iterator overriding_iterator
Represents a C array with an unspecified size.
static bool RebuildDeclaratorInCurrentInstantiation(Sema &S, Declarator &D, DeclarationName Name)
NeedsRebuildingInCurrentInstantiation - Checks whether the given declarator needs to be rebuilt in th...
ExprResult VerifyBitField(SourceLocation FieldLoc, IdentifierInfo *FieldName, QualType FieldTy, bool IsMsStruct, Expr *BitWidth, bool *ZeroWidth=nullptr)
VerifyBitField - verifies that a bit field expression is an ICE and has the correct width...
Missing a type from <stdio.h>
Look up a friend of a local class.
bool isOutOfLine() const override
Determine whether this is or was instantiated from an out-of-line definition of a static data member...
BinaryConditionalOperator - The GNU extension to the conditional operator which allows the middle ope...
static bool hasIdenticalPassObjectSizeAttrs(const FunctionDecl *A, const FunctionDecl *B)
bool isTLSSupported() const
Whether the target supports thread-local storage.
Qualifiers getQualifiers() const
Retrieve the set of qualifiers applied to this type.
unsigned getNumNegativeBits() const
Returns the width in bits required to store all the negative enumerators of this enum.
The parameter type of a method or function.
ObjCIvarDecl - Represents an ObjC instance variable.
static TypedefDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, TypeSourceInfo *TInfo)
bool isNotEmpty() const
A scope specifier is present, but may be valid or invalid.
LambdaCaptureDefault getLambdaCaptureDefault() const
void setLParenLoc(SourceLocation Loc)
const DeclSpec & getDeclSpec() const
getDeclSpec - Return the declaration-specifier that this declarator was declared with.
void setHasNonTrivialToPrimitiveCopyCUnion(bool V)
Builtin::Context & BuiltinInfo
DeclContext * CurContext
CurContext - This is the current declaration context of parsing.
void ActOnPopScope(SourceLocation Loc, Scope *S)
Scope actions.
static VarTemplateDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation L, DeclarationName Name, TemplateParameterList *Params, VarDecl *Decl)
Create a variable template node.
Declaration of a class template.
Qualifiers::ObjCLifetime getObjCARCImplicitLifetime() const
Return the implicit lifetime for this type, which must not be dependent.
DeclContext * getLookupParent()
Find the parent context of this context that will be used for unqualified name lookup.
QualType getPointerType(QualType T) const
Return the uniqued reference to the type for a pointer to the specified type.
bool isVirtualSpecified() const
static StorageClass StorageClassSpecToVarDeclStorageClass(const DeclSpec &DS)
StorageClassSpecToVarDeclStorageClass - Maps a DeclSpec::SCS to a VarDecl::StorageClass.
unsigned kind
All of the diagnostics that can be emitted by the frontend.
static FixItHint CreateReplacement(CharSourceRange RemoveRange, StringRef Code)
Create a code modification hint that replaces the given source range with the given code string...
bool hasExternalStorage() const
Returns true if a variable has extern or private_extern storage.
This class is used for builtin types like 'int'.
unsigned getRegParmType() const
A template-id, e.g., f<int>.
AttributePool & getPool() const
QualType GetBuiltinType(unsigned ID, GetBuiltinTypeError &Error, unsigned *IntegerConstantArgs=nullptr) const
Return the type for the specified builtin.
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
ParsedType getRepAsType() const
TranslationUnitKind TUKind
The kind of translation unit we are processing.
StringLiteral - This represents a string literal expression, e.g.
Defines the clang::TargetInfo interface.
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
bool hasSameFunctionTypeIgnoringExceptionSpec(QualType T, QualType U)
Determine whether two function types are the same, ignoring exception specifications in cases where t...
bool isMicrosoft() const
Is this ABI an MSVC-compatible ABI?
VarTemplateDecl * getInstantiatedFromMemberTemplate() const
bool isInlineSpecified() const
TLS with a known-constant initializer.
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
QualType getIntegerType() const
Return the integer type this enum decl corresponds to.
bool doesThisDeclarationHaveABody() const
Returns whether this specific declaration of the function has a body.
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
SourceLocation getAtomicSpecLoc() const
void setDescribedFunctionTemplate(FunctionTemplateDecl *Template)
The translation unit is a complete translation unit.
static bool CheckMultiVersionAdditionalDecl(Sema &S, FunctionDecl *OldFD, FunctionDecl *NewFD, MultiVersionKind NewMVType, const TargetAttr *NewTA, const CPUDispatchAttr *NewCPUDisp, const CPUSpecificAttr *NewCPUSpec, bool &Redeclaration, NamedDecl *&OldDecl, bool &MergeTypeWithPrevious, LookupResult &Previous)
Check the validity of a new function declaration being added to an existing multiversioned declaratio...
static TagDecl * castFromDeclContext(const DeclContext *DC)
void setObjCSelRedefinitionType(QualType RedefType)
Set the user-written type that redefines 'SEL'.
const VariableArrayType * getAsVariableArrayType(QualType T) const
static bool DeclHasAttr(const Decl *D, const Attr *A)
DeclhasAttr - returns true if decl Declaration already has the target attribute.
static OpaquePtr make(QualType P)
static bool checkUsingShadowRedecl(Sema &S, UsingShadowDecl *OldS, ExpectedDecl *New)
Check whether a redeclaration of an entity introduced by a using-declaration is valid, given that we know it's not an overload (nor a hidden tag declaration).
decl_type * getMostRecentDecl()
Returns the most recent (re)declaration of this declaration.
SourceLocation getExplicitSpecLoc() const
bool isDependentType() const
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
SourceLocation getConstexprSpecLoc() const
bool isEvaluatable(const ASTContext &Ctx, SideEffectsKind AllowSideEffects=SE_NoSideEffects) const
isEvaluatable - Call EvaluateAsRValue to see if this expression can be constant folded without side-e...
A reference to a declared variable, function, enum, etc.
void CheckConversionDeclarator(Declarator &D, QualType &R, StorageClass &SC)
CheckConversionDeclarator - Called by ActOnDeclarator to check the well-formednes of the conversion f...
const Scope * getFnParent() const
getFnParent - Return the closest scope that is a function body.
bool isIgnored(unsigned DiagID, SourceLocation Loc) const
Determine whether the diagnostic is known to be ignored.
Represents a type template specialization; the template must be a class template, a type alias templa...
Visibility getVisibility() const
Determines the visibility of this entity.
static const TST TST_atomic
bool isDeleted() const
Whether this function has been deleted.
OptimizeNoneAttr * mergeOptimizeNoneAttr(Decl *D, SourceRange Range, unsigned AttrSpellingListIndex)
bool isPointerType() const
bool hasObjectMember() const
NamedDecl * findLocallyScopedExternCDecl(DeclarationName Name)
Look for a locally scoped extern "C" declaration by the given name.
DLLExportAttr * mergeDLLExportAttr(Decl *D, SourceRange Range, unsigned AttrSpellingListIndex)
TemplatedKind getTemplatedKind() const
What kind of templated function this is.
DeclContext * getPrimaryContext()
getPrimaryContext - There may be many different declarations of the same entity (including forward de...
ArrayRef< NamedDecl * > getDeclsInPrototype() const
Get the non-parameter decls defined within this function prototype.
void ActOnObjCContainerFinishDefinition()
bool isTSBuiltin(unsigned ID) const
Return true if this function is a target-specific builtin.
SourceManager & SourceMgr
BasePaths - Represents the set of paths from a derived class to one of its (direct or indirect) bases...
static const TST TST_struct
CharUnits getTypeSizeInChars(QualType T) const
Return the size of the specified (complete) type T, in characters.
Annotates a diagnostic with some code that should be inserted, removed, or replaced to fix the proble...
DefinitionKind isThisDeclarationADefinition(ASTContext &) const
Check whether this declaration is a definition.
SkippedDefinitionContext ActOnTagStartSkippedDefinition(Scope *S, Decl *TD)
Invoked when we enter a tag definition that we're skipping.
void initializeFullCopy(TypeLoc Other)
Initializes this by copying its information from another TypeLoc of the same type.
bool isStaticDataMember() const
Determines whether this is a static data member.
SourceLocation getInnerLocStart() const
Return SourceLocation representing start of source range ignoring outer template declarations.
static bool hasDependentAlignment(VarDecl *VD)
Determines if a variable's alignment is dependent.
void suppressDiagnostics()
Suppress the diagnostics that would normally fire because of this lookup.
void setIsMultiVersion(bool V=true)
Sets the multiversion state for this declaration and all of its redeclarations.
static bool CheckMultiVersionFirstFunction(Sema &S, FunctionDecl *FD, MultiVersionKind MVType, const TargetAttr *TA)
Check the validity of a multiversion function declaration that is the first of its kind...
bool isLocalVarDecl() const
Returns true for local variable declarations other than parameters.
static StringRef getNameForCallConv(CallingConv CC)
bool empty() const
Return true if no decls were found.
void setRParenLoc(SourceLocation Loc)
bool isFloatingType() const
A trivial tuple used to represent a source range.
bool hasUnrecoverableErrorOccurred() const
void setIntegerTypeSourceInfo(TypeSourceInfo *TInfo)
Set the underlying integer type source info.
void setLexicalDeclContext(DeclContext *DC)
FunctionDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
void setHasNonTrivialToPrimitiveDefaultInitializeCUnion(bool V)
This represents a decl that may have a name.
void setIdentifier(const IdentifierInfo *Id, SourceLocation IdLoc)
Specify that this unqualified-id was parsed as an identifier.
void setsigjmp_bufDecl(TypeDecl *sigjmp_bufDecl)
Set the type for the C sigjmp_buf type.
void setFILEDecl(TypeDecl *FILEDecl)
Set the type for the C FILE type.
QualType getObjCObjectPointerType(QualType OIT) const
Return a ObjCObjectPointerType type for the given ObjCObjectType.
bool isTranslationUnit() const
Expr * getRepAsExpr() const
void setTypeSourceInfo(TypeSourceInfo *newType)
T castAs() const
Convert to the specified TypeLoc type, asserting that this TypeLoc is of the desired type...
void setAccess(AccessSpecifier AS)
Represents a C array with a specified size that is not an integer-constant-expression.
bool DeclMustBeEmitted(const Decl *D)
Determines if the decl can be CodeGen'ed or deserialized from PCH lazily, only when used; this is onl...
static bool shouldWarnIfShadowedDecl(const DiagnosticsEngine &Diags, const LookupResult &R)
No keyword precedes the qualified type name.
bool isInline() const
Whether this variable is (C++1z) inline.
static bool IsDisallowedCopyOrAssign(const CXXMethodDecl *D)
Check for this common pattern:
static void checkAttributesAfterMerging(Sema &S, NamedDecl &ND)
SourceLocation EndLocation
The location of the last token that describes this unqualified-id.
ParsedType ActOnMSVCUnknownTypeName(const IdentifierInfo &II, SourceLocation NameLoc, bool IsTemplateTypeArg)
Attempt to behave like MSVC in situations where lookup of an unqualified type name has failed in a de...
static bool mergeTypeWithPrevious(Sema &S, VarDecl *NewVD, VarDecl *OldVD, LookupResult &Previous)
SourceLocation getNameLoc() const
Gets the location of the identifier.
Describes an entity that is being initialized.
bool isFunctionPointerType() const
static FieldDecl * Create(const ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo, Expr *BW, bool Mutable, InClassInitStyle InitStyle)
attr::Kind getKind() const
unsigned NumArgs
NumArgs - The number of template arguments.
NamedDecl * getRepresentativeDecl() const
Fetches a representative decl. Useful for lazy diagnostics.
bool isReturnsTwice(unsigned ID) const
Return true if we know this builtin can return twice.
bool isFirstDeclarationOfMember()
Returns true if this declares a real member and not a friend.
void SetRangeEnd(SourceLocation Loc)
void mergeObjCMethodDecls(ObjCMethodDecl *New, ObjCMethodDecl *Old)
bool CheckEquivalentExceptionSpec(FunctionDecl *Old, FunctionDecl *New)
unsigned getNumParams() const
Return the number of parameters this function must have based on its FunctionType.
Missing a type from <setjmp.h>
void setType(QualType newType)
Wrapper for source info for pointers.
SourceLocation getBegin() const
ParsedAttributes - A collection of parsed attributes.
const LangOptions & getLangOpts() const
const BlockDecl * getInnermostBlockDecl() const
Return this DeclContext if it is a BlockDecl.
void setNonTrivialToPrimitiveCopy(bool V)
void setDeletedAsWritten(bool D=true)
static bool isAttributeTargetADefinition(Decl *D)
An implicit 'self' parameter.
SourceRange getExplicitSpecRange() const
DeclarationNameInfo GetNameForDeclarator(Declarator &D)
GetNameForDeclarator - Determine the full declaration name for the given Declarator.
This class handles loading and caching of source files into memory.
bool isGlobal() const
Determines whether this is a global function.
Defines enum values for all the target-independent builtin functions.
A deduction-guide name (a template-name)
Declaration of a template function.
iterator - Iterate over the decls of a specified declaration name.
ExtInfo withRegParm(unsigned RegParm) const
CodeSegAttr * mergeCodeSegAttr(Decl *D, SourceRange Range, StringRef Name, unsigned AttrSpellingListIndex)
A class which abstracts out some details necessary for making a call.
ParamInfo * Params
Params - This is a pointer to a new[]'d array of ParamInfo objects that describe the parameters speci...
bool hasLinkage() const
Determine whether this declaration has linkage.
void setElaboratedKeywordLoc(SourceLocation Loc)
bool isLocalVarDeclOrParm() const
Similar to isLocalVarDecl but also includes parameters.
TemplateName getQualifiedTemplateName(NestedNameSpecifier *NNS, bool TemplateKeyword, TemplateDecl *Template) const
Retrieve the template name that represents a qualified template name such as std::vector.
Attr - This represents one attribute.
ParsedAttributes & getAttributes()
SourceLocation getLocation() const
bool isCXX11ConstantExpr(const ASTContext &Ctx, APValue *Result=nullptr, SourceLocation *Loc=nullptr) const
isCXX11ConstantExpr - Return true if this expression is a constant expression in C++11.
Represents a shadow declaration introduced into a scope by a (resolved) using declaration.
bool isExternallyVisible() const
QualType getType() const
Return the type wrapped by this type source info.
bool isEditorPlaceholder() const
Return true if this identifier is an editor placeholder.
bool isBeingDefined() const
Return true if this decl is currently being defined.
ParsedTemplateTy Template
The declaration of the template corresponding to the template-name.
std::pair< FileID, unsigned > getDecomposedLoc(SourceLocation Loc) const
Decompose the specified location into a raw FileID + Offset pair.
ObjCCompatibleAliasDecl - Represents alias of a class.
Helper class that creates diagnostics with optional template instantiation stacks.
Expr * IgnoreParens() LLVM_READONLY
Skip past any parentheses which might surround this expression until reaching a fixed point...
Decl * ActOnDeclarator(Scope *S, Declarator &D)
CanQualType UnsignedIntTy
bool hasExternalFormalLinkage() const
True if this decl has external linkage.
bool hasErrorOccurred() const
Determine whether any SFINAE errors have been trapped.
Decl * ActOnEnumConstant(Scope *S, Decl *EnumDecl, Decl *LastEnumConstant, SourceLocation IdLoc, IdentifierInfo *Id, const ParsedAttributesView &Attrs, SourceLocation EqualLoc, Expr *Val)
void FilterLookupForScope(LookupResult &R, DeclContext *Ctx, Scope *S, bool ConsiderLinkage, bool AllowInlineNamespace)
Filters out lookup results that don't fall within the given scope as determined by isDeclInScope...
Qualifiers::ObjCLifetime getObjCLifetime() const
Returns lifetime attribute of this type.
bool isTransparentContext() const
isTransparentContext - Determines whether this context is a "transparent" context, meaning that the members declared in this context are semantically declared in the nearest enclosing non-transparent (opaque) context but are lexically declared in this context.
void DiagnoseUnusedNestedTypedefs(const RecordDecl *D)
QualType getType() const
Retrieves the type of the base class.
static NestedNameSpecifier * GlobalSpecifier(const ASTContext &Context)
Returns the nested name specifier representing the global scope.