31#include "llvm/ADT/APInt.h"
32#include "llvm/ADT/FoldingSet.h"
33#include "llvm/ADT/PointerIntPair.h"
34#include "llvm/ADT/SmallString.h"
35#include "llvm/ADT/SmallVector.h"
36#include "llvm/ADT/StringExtras.h"
37#include "llvm/Support/ErrorHandling.h"
38#include "llvm/Support/raw_ostream.h"
74 if (!isa<ConstantArrayType>(AT) && !isa<IncompleteArrayType>(AT))
92 auto IsCharOrUnsignedChar = [](
const QualType &T) {
93 const BuiltinType *BT = dyn_cast<BuiltinType>(T.getTypePtr());
98 case StringLiteralKind::UTF8:
108 case StringLiteralKind::Ordinary:
112 return (SL->
getKind() == StringLiteralKind::UTF8 &&
126 case StringLiteralKind::UTF16:
134 case StringLiteralKind::UTF32:
142 case StringLiteralKind::Wide:
150 case StringLiteralKind::Unevaluated:
151 assert(
false &&
"Unevaluated string literal in initialization");
155 llvm_unreachable(
"missed a StringLiteral kind?");
176 if (isa<StringLiteral>(E) || isa<ObjCEncodeExpr>(E))
187 if (isa<CompoundLiteralExpr>(E))
202 if (
const auto *VD = dyn_cast_if_present<VarDecl>(D); VD && VD->isConstexpr())
212 Sema &S,
bool CheckC23ConstexprInit =
false) {
214 auto *ConstantArrayTy =
216 uint64_t StrLength = ConstantArrayTy->getZExtSize();
218 if (CheckC23ConstexprInit)
225 llvm::APInt ConstVal(32, StrLength);
251 diag::err_initializer_string_for_char_array_too_long)
257 diag::ext_initializer_string_for_char_array_too_long)
305class InitListChecker {
307 bool hadError =
false;
309 bool TreatUnavailableAsInvalid;
310 bool InOverloadResolution;
324 unsigned &StructuredIndex);
328 bool TopLevelObject =
false);
331 bool SubobjectIsDesignatorContext,
334 unsigned &StructuredIndex,
335 bool TopLevelObject =
false);
340 unsigned &StructuredIndex,
341 bool DirectlyDesignated =
false);
346 unsigned &StructuredIndex);
351 unsigned &StructuredIndex);
356 unsigned &StructuredIndex);
360 unsigned &StructuredIndex);
365 bool SubobjectIsDesignatorContext,
unsigned &Index,
367 unsigned &StructuredIndex,
368 bool TopLevelObject =
false);
371 llvm::APSInt elementIndex,
372 bool SubobjectIsDesignatorContext,
unsigned &Index,
374 unsigned &StructuredIndex);
380 llvm::APSInt *NextElementIndex,
383 unsigned &StructuredIndex,
384 bool FinishSubobjectInit,
385 bool TopLevelObject);
389 unsigned StructuredIndex,
391 bool IsFullyOverwritten =
false);
392 void UpdateStructuredListElement(
InitListExpr *StructuredList,
393 unsigned &StructuredIndex,
397 unsigned ExpectedNumInits);
398 int numArrayElements(
QualType DeclType);
399 int numStructUnionElements(
QualType DeclType);
407 bool UnionOverride =
false,
408 bool FullyOverwritten =
true) {
413 ? (UnionOverride ? diag::ext_initializer_union_overrides
414 : diag::ext_initializer_overrides)
415 : diag::warn_initializer_overrides;
417 if (InOverloadResolution && SemaRef.
getLangOpts().CPlusPlus) {
438 DiagID = diag::err_initializer_overrides_destructed;
458 << NewInitRange << FullyOverwritten << OldInit->
getType();
487 bool FillWithNoInit);
488 void FillInEmptyInitForField(
unsigned Init,
FieldDecl *Field,
491 bool FillWithNoInit =
false);
495 bool FillWithNoInit =
false);
498 bool TopLevelObject);
505 bool VerifyOnly,
bool TreatUnavailableAsInvalid,
506 bool InOverloadResolution =
false,
511 : InitListChecker(S, Entity, IL, T,
true,
514 &AggrDeductionCandidateParamTypes){};
516 bool HadError() {
return hadError; }
520 InitListExpr *getFullyStructuredList()
const {
return FullyStructuredList; }
537 bool EmptyInitList = SemaRef.
getLangOpts().CPlusPlus11 &&
550 InitExpr = VerifyOnly
568 if (!InitSeq && EmptyInitList && InitSeq.getFailureKind() ==
572 InitSeq.getFailedCandidateSet()
573 .BestViableFunction(SemaRef,
Kind.getLocation(), Best);
575 assert(O ==
OR_Success &&
"Inconsistent overload resolution");
582 bool IsInStd =
false;
584 ND && !IsInStd; ND = dyn_cast<NamespaceDecl>(ND->getParent())) {
589 if (IsInStd && llvm::StringSwitch<bool>(R->
getName())
590 .Cases(
"basic_string",
"deque",
"forward_list",
true)
591 .Cases(
"list",
"map",
"multimap",
"multiset",
true)
592 .Cases(
"priority_queue",
"queue",
"set",
"stack",
true)
593 .Cases(
"unordered_map",
"unordered_set",
"vector",
true)
595 InitSeq.InitializeFrom(
599 TreatUnavailableAsInvalid);
604 diag::warn_invalid_initializer_from_system_header);
607 diag::note_used_in_initialization_here);
609 SemaRef.
Diag(Loc, diag::note_used_in_initialization_here);
616 InitSeq.Diagnose(SemaRef, Entity, Kind, SubInit);
619 diag::note_in_omitted_aggregate_initializer)
622 bool IsTrailingArrayNewMember =
625 SemaRef.
Diag(Loc, diag::note_in_omitted_aggregate_initializer)
626 << (IsTrailingArrayNewMember ? 2 : 0)
635 : InitSeq.Perform(SemaRef, Entity,
Kind, SubInit);
643 if (FullyStructuredList)
645 PerformEmptyInit(Loc, Entity);
648void InitListChecker::FillInEmptyInitForBase(
651 bool &RequiresSecondPass,
bool FillWithNoInit) {
658 : PerformEmptyInit(ILE->
getEndLoc(), BaseEntity);
665 assert(Init < ILE->getNumInits() &&
"should have been expanded");
670 FillInEmptyInitializations(BaseEntity, InnerILE, RequiresSecondPass,
671 ILE,
Init, FillWithNoInit);
673 dyn_cast<DesignatedInitUpdateExpr>(ILE->
getInit(
Init))) {
674 FillInEmptyInitializations(BaseEntity, InnerDIUE->getUpdater(),
675 RequiresSecondPass, ILE,
Init,
680void InitListChecker::FillInEmptyInitForField(
unsigned Init,
FieldDecl *Field,
683 bool &RequiresSecondPass,
684 bool FillWithNoInit) {
692 if (!RType->getDecl()->isUnion())
693 assert((
Init < NumInits || VerifyOnly) &&
694 "This ILE should have been expanded");
696 if (FillWithNoInit) {
697 assert(!VerifyOnly &&
"should not fill with no-init in verify-only mode");
709 if (
Field->hasInClassInitializer()) {
723 RequiresSecondPass =
true;
728 if (
Field->getType()->isReferenceType()) {
734 SemaRef.
Diag(Loc, diag::err_init_reference_member_uninitialized)
738 SemaRef.
Diag(
Field->getLocation(), diag::note_uninit_reference_member);
744 ExprResult MemberInit = PerformEmptyInit(Loc, MemberEntity);
750 if (hadError || VerifyOnly) {
752 }
else if (
Init < NumInits) {
754 }
else if (!isa<ImplicitValueInitExpr>(MemberInit.
get())) {
760 RequiresSecondPass =
true;
764 FillInEmptyInitializations(MemberEntity, InnerILE,
765 RequiresSecondPass, ILE,
Init, FillWithNoInit);
767 dyn_cast<DesignatedInitUpdateExpr>(ILE->
getInit(
Init))) {
768 FillInEmptyInitializations(MemberEntity, InnerDIUE->getUpdater(),
769 RequiresSecondPass, ILE,
Init,
780 bool &RequiresSecondPass,
783 bool FillWithNoInit) {
785 "Should not have void type");
789 if (FillWithNoInit && VerifyOnly)
799 struct UpdateOuterILEWithUpdatedInit {
802 ~UpdateOuterILEWithUpdatedInit() {
806 } UpdateOuterRAII = {OuterILE, OuterIndex};
817 Entity, ILE, RequiresSecondPass, FillWithNoInit);
818 else if (RDecl->
isUnion() && isa<CXXRecordDecl>(RDecl) &&
819 cast<CXXRecordDecl>(RDecl)->hasInClassInitializer()) {
820 for (
auto *Field : RDecl->
fields()) {
821 if (
Field->hasInClassInitializer()) {
822 FillInEmptyInitForField(0, Field, Entity, ILE, RequiresSecondPass,
831 unsigned NumElems = numStructUnionElements(ILE->
getType());
839 if (
auto *CXXRD = dyn_cast<CXXRecordDecl>(RDecl)) {
840 for (
auto &
Base : CXXRD->bases()) {
844 FillInEmptyInitForBase(
Init,
Base, Entity, ILE, RequiresSecondPass,
850 for (
auto *Field : RDecl->
fields()) {
851 if (
Field->isUnnamedBitfield())
857 FillInEmptyInitForField(
Init, Field, Entity, ILE, RequiresSecondPass,
877 unsigned NumElements = NumInits;
879 ElementType = AType->getElementType();
880 if (
const auto *CAType = dyn_cast<ConstantArrayType>(AType))
881 NumElements = CAType->getZExtSize();
889 ElementType = VType->getElementType();
890 NumElements = VType->getNumElements();
896 bool SkipEmptyInitChecks =
false;
909 if (!InitExpr && Init < NumInits && ILE->hasArrayFiller())
914 if (SkipEmptyInitChecks)
917 Expr *Filler =
nullptr;
923 PerformEmptyInit(ILE->
getEndLoc(), ElementEntity);
934 }
else if (VerifyOnly) {
935 SkipEmptyInitChecks =
true;
936 }
else if (
Init < NumInits) {
951 if (!isa<ImplicitValueInitExpr>(Filler) && !isa<NoInitExpr>(Filler)) {
957 RequiresSecondPass =
true;
961 = dyn_cast_or_null<InitListExpr>(InitExpr)) {
962 FillInEmptyInitializations(ElementEntity, InnerILE, RequiresSecondPass,
963 ILE,
Init, FillWithNoInit);
965 dyn_cast_or_null<DesignatedInitUpdateExpr>(InitExpr)) {
966 FillInEmptyInitializations(ElementEntity, InnerDIUE->getUpdater(),
967 RequiresSecondPass, ILE,
Init,
975 if (isa_and_nonnull<DesignatedInitExpr>(
Init))
980InitListChecker::InitListChecker(
982 bool VerifyOnly,
bool TreatUnavailableAsInvalid,
bool InOverloadResolution,
984 : SemaRef(S), VerifyOnly(VerifyOnly),
985 TreatUnavailableAsInvalid(TreatUnavailableAsInvalid),
986 InOverloadResolution(InOverloadResolution),
987 AggrDeductionCandidateParamTypes(AggrDeductionCandidateParamTypes) {
989 FullyStructuredList =
998 CheckExplicitInitList(Entity, IL, T, FullyStructuredList,
1001 if (!hadError && !AggrDeductionCandidateParamTypes && FullyStructuredList) {
1002 bool RequiresSecondPass =
false;
1003 FillInEmptyInitializations(Entity, FullyStructuredList, RequiresSecondPass,
1005 if (RequiresSecondPass && !hadError)
1006 FillInEmptyInitializations(Entity, FullyStructuredList,
1007 RequiresSecondPass,
nullptr, 0);
1009 if (hadError && FullyStructuredList)
1013int InitListChecker::numArrayElements(
QualType DeclType) {
1015 int maxElements = 0x7FFFFFFF;
1018 maxElements =
static_cast<int>(CAT->getZExtSize());
1023int InitListChecker::numStructUnionElements(
QualType DeclType) {
1025 int InitializableMembers = 0;
1026 if (
auto *CXXRD = dyn_cast<CXXRecordDecl>(structDecl))
1027 InitializableMembers += CXXRD->getNumBases();
1028 for (
const auto *Field : structDecl->
fields())
1029 if (!
Field->isUnnamedBitfield())
1030 ++InitializableMembers;
1033 return std::min(InitializableMembers, 1);
1039 return RT->getDecl();
1041 return Inject->getDecl();
1071 if (
CXXRecordDecl *CXXRD = dyn_cast<CXXRecordDecl>(ParentRD)) {
1072 if (CXXRD->getNumBases()) {
1076 auto FieldIt = ParentRD->field_begin();
1077 assert(FieldIt != ParentRD->field_end() &&
1078 "no fields but have initializer for member?");
1079 return ++FieldIt == ParentRD->field_end();
1095 unsigned &StructuredIndex) {
1096 int maxElements = 0;
1099 maxElements = numArrayElements(T);
1101 maxElements = numStructUnionElements(T);
1105 llvm_unreachable(
"CheckImplicitInitList(): Illegal type");
1107 if (maxElements == 0) {
1110 diag::err_implicit_empty_initializer);
1117 InitListExpr *StructuredSubobjectInitList = getStructuredSubobjectInit(
1118 ParentIList, Index, T, StructuredList, StructuredIndex,
1121 unsigned StructuredSubobjectInitIndex = 0;
1124 unsigned StartIndex = Index;
1125 CheckListElementTypes(Entity, ParentIList, T,
1127 StructuredSubobjectInitList,
1128 StructuredSubobjectInitIndex);
1130 if (StructuredSubobjectInitList) {
1131 StructuredSubobjectInitList->
setType(T);
1133 unsigned EndIndex = (Index == StartIndex? StartIndex : Index - 1);
1136 if (EndIndex < ParentIList->getNumInits() &&
1137 ParentIList->
getInit(EndIndex)) {
1148 diag::warn_missing_braces)
1154 StructuredSubobjectInitList->
getEndLoc()),
1160 if (!VerifyOnly && CXXRD && CXXRD->hasUserDeclaredConstructor()) {
1162 diag::warn_cxx20_compat_aggregate_init_with_ctors)
1178 unsigned DiagID = 0;
1190 DiagID = diag::warn_braces_around_init;
1197 DiagID = diag::warn_braces_around_init;
1223 llvm_unreachable(
"unexpected braced scalar init");
1242 bool TopLevelObject) {
1243 unsigned Index = 0, StructuredIndex = 0;
1244 CheckListElementTypes(Entity, IList, T,
true,
1245 Index, StructuredList, StructuredIndex, TopLevelObject);
1246 if (StructuredList) {
1252 StructuredList->
setType(ExprTy);
1260 bool ExtraInitsIsError = SemaRef.
getLangOpts().CPlusPlus ||
1262 hadError = ExtraInitsIsError;
1265 }
else if (StructuredIndex == 1 &&
1270 ? diag::err_excess_initializers_in_char_array_initializer
1271 : diag::ext_excess_initializers_in_char_array_initializer;
1275 unsigned DK = ExtraInitsIsError
1276 ? diag::err_excess_initializers_for_sizeless_type
1277 : diag::ext_excess_initializers_for_sizeless_type;
1287 unsigned DK = ExtraInitsIsError ? diag::err_excess_initializers
1288 : diag::ext_excess_initializers;
1296 !isa<InitListExpr>(IList->
getInit(0)))
1302 if (CXXRD && CXXRD->hasUserDeclaredConstructor()) {
1305 bool HasEquivCtor =
false;
1311 if (!HasEquivCtor) {
1313 diag::warn_cxx20_compat_aggregate_init_with_ctors)
1323 bool SubobjectIsDesignatorContext,
1326 unsigned &StructuredIndex,
1327 bool TopLevelObject) {
1331 CheckComplexType(Entity, IList, DeclType, Index,
1332 StructuredList, StructuredIndex);
1334 CheckScalarType(Entity, IList, DeclType, Index,
1335 StructuredList, StructuredIndex);
1337 CheckVectorType(Entity, IList, DeclType, Index,
1338 StructuredList, StructuredIndex);
1339 }
else if (
const RecordDecl *RD = getRecordDecl(DeclType)) {
1345 "non-aggregate records should be handed in CheckSubElementType");
1346 if (
auto *CXXRD = dyn_cast<CXXRecordDecl>(RD))
1347 Bases = CXXRD->bases();
1349 Bases = cast<CXXRecordDecl>(RD)->bases();
1351 CheckStructUnionTypes(Entity, IList, DeclType, Bases, RD->field_begin(),
1352 SubobjectIsDesignatorContext, Index, StructuredList,
1353 StructuredIndex, TopLevelObject);
1358 CheckArrayType(Entity, IList, DeclType, Zero,
1359 SubobjectIsDesignatorContext, Index,
1360 StructuredList, StructuredIndex);
1365 SemaRef.
Diag(IList->
getBeginLoc(), diag::err_illegal_initializer_type)
1369 CheckReferenceType(Entity, IList, DeclType, Index,
1370 StructuredList, StructuredIndex);
1373 SemaRef.
Diag(IList->
getBeginLoc(), diag::err_init_objc_class) << DeclType;
1378 CheckScalarType(Entity, IList, DeclType, Index, StructuredList,
1385 assert(AggrDeductionCandidateParamTypes);
1386 AggrDeductionCandidateParamTypes->push_back(DeclType);
1389 SemaRef.
Diag(IList->
getBeginLoc(), diag::err_illegal_initializer_type)
1400 unsigned &StructuredIndex,
1401 bool DirectlyDesignated) {
1405 return CheckReferenceType(Entity, IList, ElemType, Index,
1406 StructuredList, StructuredIndex);
1409 if (SubInitList->getNumInits() == 1 &&
1414 expr = SubInitList->getInit(0);
1417 }
else if (isa<ImplicitValueInitExpr>(
expr)) {
1421 "found implicit initialization for the wrong type");
1422 UpdateStructuredListElement(StructuredList, StructuredIndex,
expr);
1444 if (TmpEntity.getType()->isDependentType()) {
1449 assert(AggrDeductionCandidateParamTypes);
1450 if (!isa_and_nonnull<ConstantArrayType>(
1453 AggrDeductionCandidateParamTypes->push_back(ElemType);
1465 if (
Seq || isa<InitListExpr>(
expr)) {
1468 if (Result.isInvalid())
1471 UpdateStructuredListElement(StructuredList, StructuredIndex,
1472 Result.getAs<
Expr>());
1475 }
else if (StructuredList) {
1476 UpdateStructuredListElement(StructuredList, StructuredIndex,
1480 if (AggrDeductionCandidateParamTypes)
1481 AggrDeductionCandidateParamTypes->push_back(ElemType);
1489 return CheckScalarType(Entity, IList, ElemType, Index,
1490 StructuredList, StructuredIndex);
1504 UpdateStructuredListElement(StructuredList, StructuredIndex,
expr);
1533 UpdateStructuredListElement(StructuredList, StructuredIndex,
1551 CheckImplicitInitList(Entity, IList, ElemType, Index, StructuredList,
1556 if (DirectlyDesignated && SemaRef.
getLangOpts().CPlusPlus && !hadError) {
1557 if (InOverloadResolution)
1561 diag::ext_designated_init_brace_elision)
1562 <<
expr->getSourceRange()
1577 assert(
Copy.isInvalid() &&
1578 "expected non-aggregate initialization to fail");
1590 unsigned &StructuredIndex) {
1591 assert(Index == 0 &&
"Index in explicit init list must be zero");
1601 return CheckScalarType(Entity, IList, DeclType, Index, StructuredList,
1606 if (!SemaRef.
getLangOpts().CPlusPlus && !VerifyOnly)
1615 for (
unsigned i = 0; i < 2; ++i) {
1617 CheckSubElementType(ElementEntity, IList, elementType, Index,
1618 StructuredList, StructuredIndex);
1626 unsigned &StructuredIndex) {
1633 ? diag::warn_cxx98_compat_empty_sizeless_initializer
1634 : diag::err_empty_sizeless_initializer)
1639 ? diag::warn_cxx98_compat_empty_scalar_initializer
1640 : diag::err_empty_scalar_initializer)
1656 SemaRef.
Diag(SubIList->getBeginLoc(), diag::ext_many_braces_around_init)
1659 CheckScalarType(Entity, SubIList, DeclType, Index, StructuredList,
1662 }
else if (isa<DesignatedInitExpr>(
expr)) {
1665 diag::err_designator_for_scalar_or_sizeless_init)
1667 <<
expr->getSourceRange();
1677 Result = getDummyInit();
1686 Expr *ResultExpr =
nullptr;
1688 if (Result.isInvalid())
1691 ResultExpr = Result.getAs<
Expr>();
1693 if (ResultExpr !=
expr && !VerifyOnly) {
1696 IList->
setInit(Index, ResultExpr);
1699 UpdateStructuredListElement(StructuredList, StructuredIndex, ResultExpr);
1701 if (AggrDeductionCandidateParamTypes)
1702 AggrDeductionCandidateParamTypes->push_back(DeclType);
1709 unsigned &StructuredIndex) {
1717 diag::err_init_reference_member_uninitialized)
1739 Result = getDummyInit();
1748 if (Result.isInvalid())
1753 if (!VerifyOnly &&
expr)
1756 UpdateStructuredListElement(StructuredList, StructuredIndex,
expr);
1758 if (AggrDeductionCandidateParamTypes)
1759 AggrDeductionCandidateParamTypes->push_back(DeclType);
1766 unsigned &StructuredIndex) {
1769 unsigned numEltsInit = 0;
1774 CheckEmptyInitializable(
1784 if (!isa<InitListExpr>(
Init) &&
Init->getType()->isVectorType()) {
1788 Result = getDummyInit();
1797 Expr *ResultExpr =
nullptr;
1798 if (Result.isInvalid())
1801 ResultExpr = Result.getAs<
Expr>();
1803 if (ResultExpr !=
Init && !VerifyOnly) {
1806 IList->
setInit(Index, ResultExpr);
1809 UpdateStructuredListElement(StructuredList, StructuredIndex, ResultExpr);
1811 if (AggrDeductionCandidateParamTypes)
1812 AggrDeductionCandidateParamTypes->push_back(elementType);
1819 for (
unsigned i = 0; i < maxElements; ++i, ++numEltsInit) {
1822 CheckEmptyInitializable(ElementEntity, IList->
getEndLoc());
1827 CheckSubElementType(ElementEntity, IList, elementType, Index,
1828 StructuredList, StructuredIndex);
1836 if (isBigEndian && (T->
getVectorKind() == VectorKind::Neon ||
1849 diag::warn_neon_vector_initializer_non_portable);
1851 const char *typeCode;
1861 llvm_unreachable(
"Invalid element type!");
1865 ? diag::note_neon_vector_initializer_non_portable_q
1866 : diag::note_neon_vector_initializer_non_portable)
1867 << typeCode << typeSize;
1877 for (
unsigned i = 0; i < maxElements; ++i) {
1886 CheckSubElementType(ElementEntity, IList, elementType, Index,
1887 StructuredList, StructuredIndex);
1899 CheckSubElementType(ElementEntity, IList, VecType, Index,
1900 StructuredList, StructuredIndex);
1901 numEltsInit += numIElts;
1906 if (numEltsInit != maxElements) {
1909 diag::err_vector_incorrect_num_initializers)
1910 << (numEltsInit < maxElements) << maxElements << numEltsInit;
1933 SemaRef.
PDiag(diag::err_access_dtor_temp)
1941 llvm::APSInt elementIndex,
1942 bool SubobjectIsDesignatorContext,
1945 unsigned &StructuredIndex) {
1957 if (Index < IList->getNumInits()) {
1970 if (StructuredList) {
1971 UpdateStructuredListElement(StructuredList, StructuredIndex,
1976 if (AggrDeductionCandidateParamTypes)
1977 AggrDeductionCandidateParamTypes->push_back(DeclType);
1998 SemaRef.
Diag(VAT->getSizeExpr()->getBeginLoc(),
1999 diag::err_variable_object_no_init)
2000 << VAT->getSizeExpr()->getSourceRange();
2009 llvm::APSInt maxElements(elementIndex.getBitWidth(),
2010 elementIndex.isUnsigned());
2011 bool maxElementsKnown =
false;
2013 maxElements = CAT->getSize();
2014 elementIndex = elementIndex.extOrTrunc(maxElements.getBitWidth());
2015 elementIndex.setIsUnsigned(maxElements.isUnsigned());
2016 maxElementsKnown =
true;
2020 while (Index < IList->getNumInits()) {
2026 if (!SubobjectIsDesignatorContext)
2031 if (CheckDesignatedInitializer(Entity, IList, DIE, 0,
2032 DeclType,
nullptr, &elementIndex, Index,
2033 StructuredList, StructuredIndex,
true,
2039 if (elementIndex.getBitWidth() > maxElements.getBitWidth())
2040 maxElements = maxElements.extend(elementIndex.getBitWidth());
2041 else if (elementIndex.getBitWidth() < maxElements.getBitWidth())
2042 elementIndex = elementIndex.extend(maxElements.getBitWidth());
2043 elementIndex.setIsUnsigned(maxElements.isUnsigned());
2047 if (!maxElementsKnown && elementIndex > maxElements)
2048 maxElements = elementIndex;
2055 if (maxElementsKnown && elementIndex == maxElements)
2062 CheckSubElementType(ElementEntity, IList, elementType, Index,
2063 StructuredList, StructuredIndex);
2068 if (!maxElementsKnown && elementIndex > maxElements)
2069 maxElements = elementIndex;
2074 llvm::APSInt
Zero(maxElements.getBitWidth(), maxElements.isUnsigned());
2078 SemaRef.
Diag(IList->
getBeginLoc(), diag::ext_typecheck_zero_array_size);
2082 elementType, maxElements,
nullptr, ArraySizeModifier::Normal, 0);
2089 if ((maxElementsKnown && elementIndex < maxElements) ||
2091 CheckEmptyInitializable(
2100 bool TopLevelObject) {
2102 unsigned FlexArrayDiag;
2103 if (isa<InitListExpr>(InitExpr) &&
2104 cast<InitListExpr>(InitExpr)->getNumInits() == 0) {
2106 FlexArrayDiag = diag::ext_flexible_array_init;
2107 }
else if (!TopLevelObject) {
2109 FlexArrayDiag = diag::err_flexible_array_init;
2112 FlexArrayDiag = diag::err_flexible_array_init;
2113 }
else if (cast<VarDecl>(Entity.
getDecl())->hasLocalStorage()) {
2115 FlexArrayDiag = diag::err_flexible_array_init;
2118 FlexArrayDiag = diag::ext_flexible_array_init;
2124 SemaRef.
Diag(
Field->getLocation(), diag::note_flexible_array_member)
2128 return FlexArrayDiag != diag::ext_flexible_array_init;
2131void InitListChecker::CheckStructUnionTypes(
2134 bool SubobjectIsDesignatorContext,
unsigned &Index,
2135 InitListExpr *StructuredList,
unsigned &StructuredIndex,
2136 bool TopLevelObject) {
2137 const RecordDecl *RD = getRecordDecl(DeclType);
2159 if (isa<CXXRecordDecl>(RD) &&
2160 cast<CXXRecordDecl>(RD)->hasInClassInitializer()) {
2161 if (!StructuredList)
2164 Field != FieldEnd; ++Field) {
2165 if (
Field->hasInClassInitializer()) {
2176 Field != FieldEnd; ++Field) {
2177 if (!
Field->isUnnamedBitfield()) {
2178 CheckEmptyInitializable(
2189 bool InitializedSomething =
false;
2192 for (
auto I = Bases.begin(), E = Bases.end(); I != E; ++I) {
2198 if (
Init && isa<DesignatedInitExpr>(
Init))
2215 if (AggrDeductionCandidateParamTypes &&
Base.isPackExpansion()) {
2216 AggrDeductionCandidateParamTypes->push_back(
2221 if (Index < IList->getNumInits())
2233 CheckSubElementType(BaseEntity, IList,
Base.getType(), Index,
2234 StructuredList, StructuredIndex);
2235 InitializedSomething =
true;
2237 CheckEmptyInitializable(BaseEntity, InitLoc);
2252 size_t NumRecordDecls = llvm::count_if(RD->
decls(), [&](
const Decl *D) {
2253 return isa<FieldDecl>(D) || isa<RecordDecl>(D);
2255 bool HasDesignatedInit =
false;
2259 while (Index < IList->getNumInits()) {
2267 if (!SubobjectIsDesignatorContext)
2270 HasDesignatedInit =
true;
2274 bool DesignatedInitFailed = CheckDesignatedInitializer(
2275 Entity, IList, DIE, 0, DeclType, &Field,
nullptr, Index,
2276 StructuredList, StructuredIndex,
true, TopLevelObject);
2277 if (DesignatedInitFailed)
2284 InitializedFields.insert(F);
2285 if (!DesignatedInitFailed) {
2294 InitializedSomething =
true;
2311 if (NumRecordDecls == 1)
2313 if (
const auto *IL = dyn_cast<IntegerLiteral>(I))
2314 return IL->getValue().isZero();
2322 SemaRef.
Diag(InitLoc, diag::err_non_designated_init_used);
2327 if (Field == FieldEnd) {
2333 if (InitializedSomething && RD->
isUnion())
2337 if (
Field->getType()->isIncompleteArrayType())
2340 if (
Field->isUnnamedBitfield()) {
2349 InvalidUse = !SemaRef.
CanUseDecl(*Field, TreatUnavailableAsInvalid);
2370 CheckSubElementType(MemberEntity, IList,
Field->getType(), Index,
2371 StructuredList, StructuredIndex);
2372 InitializedSomething =
true;
2373 InitializedFields.insert(*Field);
2375 if (RD->
isUnion() && StructuredList) {
2386 bool IsCDesignatedInitializer =
2387 HasDesignatedInit && !SemaRef.
getLangOpts().CPlusPlus;
2388 if (!VerifyOnly && InitializedSomething && !RD->
isUnion() &&
2390 !IsCDesignatedInitializer) {
2397 if (HasDesignatedInit && InitializedFields.count(*it))
2400 if (!it->isUnnamedBitfield() && !it->hasInClassInitializer() &&
2401 !it->getType()->isIncompleteArrayType()) {
2402 auto Diag = HasDesignatedInit
2403 ? diag::warn_missing_designated_field_initializers
2404 : diag::warn_missing_field_initializers;
2413 if (!StructuredList && Field != FieldEnd && !RD->
isUnion() &&
2414 !
Field->getType()->isIncompleteArrayType()) {
2415 for (;
Field != FieldEnd && !hadError; ++
Field) {
2416 if (!
Field->isUnnamedBitfield() && !
Field->hasInClassInitializer())
2417 CheckEmptyInitializable(
2438 if (Field == FieldEnd || !
Field->getType()->isIncompleteArrayType() ||
2442 if (CheckFlexibleArrayInit(Entity, IList->
getInit(Index), *Field,
2452 if (isa<InitListExpr>(IList->
getInit(Index)) ||
2453 AggrDeductionCandidateParamTypes)
2454 CheckSubElementType(MemberEntity, IList,
Field->getType(), Index,
2455 StructuredList, StructuredIndex);
2457 CheckImplicitInitList(MemberEntity, IList,
Field->getType(), Index,
2458 StructuredList, StructuredIndex);
2474 PE = IndirectField->
chain_end(); PI != PE; ++PI) {
2482 assert(isa<FieldDecl>(*PI));
2483 Replacements.back().setFieldDecl(cast<FieldDecl>(*PI));
2490 &Replacements[0] + Replacements.size());
2497 for (
unsigned I = 0; I < NumIndexExprs; ++I)
2511 explicit FieldInitializerValidatorCCC(
const RecordDecl *RD)
2519 std::unique_ptr<CorrectionCandidateCallback>
clone()
override {
2520 return std::make_unique<FieldInitializerValidatorCCC>(*
this);
2573 llvm::APSInt *NextElementIndex,
2576 unsigned &StructuredIndex,
2577 bool FinishSubobjectInit,
2578 bool TopLevelObject) {
2579 if (DesigIdx == DIE->
size()) {
2586 assert(isa<InitListExpr>(
Init) &&
2587 "designator result in direct non-list initialization?");
2592 if (StructuredList) {
2596 UpdateStructuredListElement(StructuredList, StructuredIndex,
2600 if (AggrDeductionCandidateParamTypes)
2601 AggrDeductionCandidateParamTypes->push_back(CurrentObjectType);
2606 bool prevHadError = hadError;
2611 unsigned OldIndex = Index;
2614 CheckSubElementType(Entity, IList, CurrentObjectType, Index, StructuredList,
2615 StructuredIndex,
true);
2621 IList->
setInit(OldIndex, DIE);
2623 return hadError && !prevHadError;
2627 bool IsFirstDesignator = (DesigIdx == 0);
2628 if (IsFirstDesignator ? FullyStructuredList : StructuredList) {
2631 if (IsFirstDesignator)
2632 StructuredList = FullyStructuredList;
2634 Expr *ExistingInit = StructuredIndex < StructuredList->getNumInits() ?
2635 StructuredList->getInit(StructuredIndex) :
nullptr;
2636 if (!ExistingInit && StructuredList->hasArrayFiller())
2637 ExistingInit = StructuredList->getArrayFiller();
2640 StructuredList = getStructuredSubobjectInit(
2641 IList, Index, CurrentObjectType, StructuredList, StructuredIndex,
2643 else if (
InitListExpr *Result = dyn_cast<InitListExpr>(ExistingInit))
2644 StructuredList = Result;
2657 diagnoseInitOverride(ExistingInit,
2664 dyn_cast<DesignatedInitUpdateExpr>(ExistingInit))
2665 StructuredList = E->getUpdater();
2670 StructuredList->updateInit(SemaRef.
Context, StructuredIndex, DIUE);
2679 StructuredList =
nullptr;
2695 RecordDecl *RD = getRecordDecl(CurrentObjectType);
2701 SemaRef.
Diag(Loc, diag::err_field_designator_non_aggr)
2702 << SemaRef.
getLangOpts().CPlusPlus << CurrentObjectType;
2711 if (
auto *FD = dyn_cast_if_present<FieldDecl>(VD)) {
2713 }
else if (
auto *IFD = dyn_cast_if_present<IndirectFieldDecl>(VD)) {
2719 KnownField = cast<FieldDecl>(*IFD->chain_begin());
2738 SemaRef.
Diag(Lookup.front()->getLocation(),
2739 diag::note_field_designator_found);
2746 FieldInitializerValidatorCCC CCC(RD);
2753 SemaRef.
PDiag(diag::err_field_designator_unknown_suggest)
2754 << FieldName << CurrentObjectType);
2755 KnownField = Corrected.getCorrectionDeclAs<
FieldDecl>();
2766 SemaRef.
Diag(Loc, diag::err_field_designator_unknown)
2774 unsigned NumBases = 0;
2775 if (
auto *CXXRD = dyn_cast<CXXRecordDecl>(RD))
2776 NumBases = CXXRD->getNumBases();
2778 unsigned FieldIndex = NumBases;
2780 for (
auto *FI : RD->
fields()) {
2781 if (FI->isUnnamedBitfield())
2797 if (StructuredList) {
2798 FieldDecl *CurrentField = StructuredList->getInitializedFieldInUnion();
2800 assert(StructuredList->getNumInits() == 1
2801 &&
"A union should never have more than one initializer!");
2803 Expr *ExistingInit = StructuredList->getInit(0);
2806 diagnoseInitOverride(
2814 StructuredList->resizeInits(SemaRef.
Context, 0);
2815 StructuredList->setInitializedFieldInUnion(
nullptr);
2818 StructuredList->setInitializedFieldInUnion(*Field);
2825 InvalidUse = !SemaRef.
CanUseDecl(*Field, TreatUnavailableAsInvalid);
2848 if (IsFirstDesignator && !VerifyOnly && SemaRef.
getLangOpts().CPlusPlus &&
2851 (*NextField)->getFieldIndex() >
Field->getFieldIndex() + 1)) {
2855 if (FI->isUnnamedBitfield())
2866 diag::ext_designated_init_reordered)
2869 unsigned OldIndex = StructuredIndex - 1;
2870 if (StructuredList && OldIndex <= StructuredList->getNumInits()) {
2871 if (
Expr *PrevInit = StructuredList->getInit(OldIndex)) {
2872 SemaRef.
Diag(PrevInit->getBeginLoc(),
2873 diag::note_previous_field_init)
2887 if (StructuredList && FieldIndex >= StructuredList->getNumInits())
2888 StructuredList->resizeInits(SemaRef.
Context, FieldIndex + 1);
2891 if (
Field->getType()->isIncompleteArrayType()) {
2893 if ((DesigIdx + 1) != DIE->
size()) {
2900 diag::err_designator_into_flexible_array_member)
2902 SemaRef.
Diag(
Field->getLocation(), diag::note_flexible_array_member)
2908 if (!hadError && !isa<InitListExpr>(DIE->
getInit()) &&
2909 !isa<StringLiteral>(DIE->
getInit())) {
2913 diag::err_flexible_array_init_needs_braces)
2915 SemaRef.
Diag(
Field->getLocation(), diag::note_flexible_array_member)
2922 if (!
Invalid && CheckFlexibleArrayInit(Entity, DIE->
getInit(), *Field,
2932 bool prevHadError = hadError;
2933 unsigned newStructuredIndex = FieldIndex;
2934 unsigned OldIndex = Index;
2939 CheckSubElementType(MemberEntity, IList,
Field->getType(), Index,
2940 StructuredList, newStructuredIndex);
2942 IList->
setInit(OldIndex, DIE);
2943 if (hadError && !prevHadError) {
2948 StructuredIndex = FieldIndex;
2954 unsigned newStructuredIndex = FieldIndex;
2958 if (CheckDesignatedInitializer(MemberEntity, IList, DIE, DesigIdx + 1,
2959 FieldType,
nullptr,
nullptr, Index,
2960 StructuredList, newStructuredIndex,
2961 FinishSubobjectInit,
false))
2972 if (IsFirstDesignator) {
2979 StructuredIndex = FieldIndex;
2983 if (!FinishSubobjectInit)
2991 bool prevHadError = hadError;
2996 CheckStructUnionTypes(Entity, IList, CurrentObjectType, NoBases, Field,
2997 false, Index, StructuredList, FieldIndex);
2998 return hadError && !prevHadError;
3020 << CurrentObjectType;
3025 Expr *IndexExpr =
nullptr;
3026 llvm::APSInt DesignatedStartIndex, DesignatedEndIndex;
3030 DesignatedEndIndex = DesignatedStartIndex;
3034 DesignatedStartIndex =
3036 DesignatedEndIndex =
3045 if (DesignatedStartIndex.getZExtValue()!=DesignatedEndIndex.getZExtValue()&&
3050 if (isa<ConstantArrayType>(AT)) {
3051 llvm::APSInt MaxElements(cast<ConstantArrayType>(AT)->getSize(),
false);
3052 DesignatedStartIndex
3053 = DesignatedStartIndex.extOrTrunc(MaxElements.getBitWidth());
3054 DesignatedStartIndex.setIsUnsigned(MaxElements.isUnsigned());
3056 = DesignatedEndIndex.extOrTrunc(MaxElements.getBitWidth());
3057 DesignatedEndIndex.setIsUnsigned(MaxElements.isUnsigned());
3058 if (DesignatedEndIndex >= MaxElements) {
3061 diag::err_array_designator_too_large)
3068 unsigned DesignatedIndexBitWidth =
3070 DesignatedStartIndex =
3071 DesignatedStartIndex.extOrTrunc(DesignatedIndexBitWidth);
3072 DesignatedEndIndex =
3073 DesignatedEndIndex.extOrTrunc(DesignatedIndexBitWidth);
3074 DesignatedStartIndex.setIsUnsigned(
true);
3075 DesignatedEndIndex.setIsUnsigned(
true);
3078 bool IsStringLiteralInitUpdate =
3079 StructuredList && StructuredList->isStringLiteralInit();
3080 if (IsStringLiteralInitUpdate && VerifyOnly) {
3083 StructuredList =
nullptr;
3084 }
else if (IsStringLiteralInitUpdate) {
3097 unsigned PromotedCharTyWidth = Context.
getTypeSize(PromotedCharTy);
3102 if (cast<ConstantArrayType>(AT)->getSize().ult(StrLen))
3103 StrLen = cast<ConstantArrayType>(AT)->getZExtSize();
3104 StructuredList->resizeInits(Context, StrLen);
3108 for (
unsigned i = 0, e = StrLen; i != e; ++i) {
3109 llvm::APInt CodeUnit(PromotedCharTyWidth, SL->getCodeUnit(i));
3111 Context, CodeUnit, PromotedCharTy, SubExpr->
getExprLoc());
3112 if (CharTy != PromotedCharTy)
3116 StructuredList->updateInit(Context, i,
Init);
3125 if (cast<ConstantArrayType>(AT)->getSize().ult(StrLen))
3126 StrLen = cast<ConstantArrayType>(AT)->getZExtSize();
3127 StructuredList->resizeInits(Context, StrLen);
3131 for (
unsigned i = 0, e = StrLen; i != e; ++i) {
3132 llvm::APInt CodeUnit(PromotedCharTyWidth, Str[i]);
3134 Context, CodeUnit, PromotedCharTy, SubExpr->
getExprLoc());
3135 if (CharTy != PromotedCharTy)
3139 StructuredList->updateInit(Context, i,
Init);
3146 if (StructuredList &&
3147 DesignatedEndIndex.getZExtValue() >= StructuredList->getNumInits())
3148 StructuredList->resizeInits(SemaRef.
Context,
3149 DesignatedEndIndex.getZExtValue() + 1);
3155 unsigned ElementIndex = DesignatedStartIndex.getZExtValue();
3156 unsigned OldIndex = Index;
3161 while (DesignatedStartIndex <= DesignatedEndIndex) {
3167 if (CheckDesignatedInitializer(
3168 ElementEntity, IList, DIE, DesigIdx + 1, ElementType,
nullptr,
3169 nullptr, Index, StructuredList, ElementIndex,
3170 FinishSubobjectInit && (DesignatedStartIndex == DesignatedEndIndex),
3175 ++DesignatedStartIndex;
3176 ElementIndex = DesignatedStartIndex.getZExtValue();
3181 if (IsFirstDesignator) {
3182 if (NextElementIndex)
3183 *NextElementIndex = DesignatedStartIndex;
3184 StructuredIndex = ElementIndex;
3188 if (!FinishSubobjectInit)
3192 bool prevHadError = hadError;
3193 CheckArrayType(Entity, IList, CurrentObjectType, DesignatedStartIndex,
3195 StructuredList, ElementIndex);
3196 return hadError && !prevHadError;
3202InitListChecker::getStructuredSubobjectInit(
InitListExpr *IList,
unsigned Index,
3205 unsigned StructuredIndex,
3207 bool IsFullyOverwritten) {
3208 if (!StructuredList)
3211 Expr *ExistingInit =
nullptr;
3212 if (StructuredIndex < StructuredList->getNumInits())
3213 ExistingInit = StructuredList->
getInit(StructuredIndex);
3215 if (
InitListExpr *Result = dyn_cast_or_null<InitListExpr>(ExistingInit))
3224 if (!IsFullyOverwritten)
3247 diagnoseInitOverride(ExistingInit, InitRange);
3250 unsigned ExpectedNumInits = 0;
3251 if (Index < IList->getNumInits()) {
3252 if (
auto *
Init = dyn_cast_or_null<InitListExpr>(IList->
getInit(Index)))
3253 ExpectedNumInits =
Init->getNumInits();
3259 createInitListExpr(CurrentObjectType, InitRange, ExpectedNumInits);
3268InitListChecker::createInitListExpr(
QualType CurrentObjectType,
3270 unsigned ExpectedNumInits) {
3274 QualType ResultType = CurrentObjectType;
3277 Result->setType(ResultType);
3280 unsigned NumElements = 0;
3285 NumElements = CAType->getZExtSize();
3288 if (NumElements > ExpectedNumInits)
3292 NumElements = VType->getNumElements();
3294 NumElements = numStructUnionElements(CurrentObjectType);
3299 Result->reserveInits(SemaRef.
Context, NumElements);
3306void InitListChecker::UpdateStructuredListElement(
InitListExpr *StructuredList,
3307 unsigned &StructuredIndex,
3310 if (!StructuredList)
3314 StructuredIndex,
expr)) {
3320 diagnoseInitOverride(PrevInit,
expr->getSourceRange());
3331 InitListChecker Check(*
this, Entity, From,
Type,
true,
3334 return !Check.HadError();
3355 return S.
Diag(Loc, diag::err_array_designator_negative)
3358 Value.setIsUnsigned(
true);
3377 Designators.push_back(ASTDesignator::CreateFieldDesignator(
3381 llvm::APSInt IndexValue;
3382 if (!Index->isTypeDependent() && !Index->isValueDependent())
3387 Designators.push_back(ASTDesignator::CreateArrayDesignator(
3389 InitExpressions.push_back(Index);
3394 llvm::APSInt StartValue;
3395 llvm::APSInt EndValue;
3400 if (!StartDependent)
3406 if (!StartIndex || !EndIndex)
3410 if (StartDependent || EndDependent) {
3412 }
else if (StartValue.getBitWidth() > EndValue.getBitWidth())
3413 EndValue = EndValue.extend(StartValue.getBitWidth());
3414 else if (StartValue.getBitWidth() < EndValue.getBitWidth())
3415 StartValue = StartValue.extend(EndValue.getBitWidth());
3417 if (!StartDependent && !EndDependent && EndValue < StartValue) {
3423 Designators.push_back(ASTDesignator::CreateArrayRangeDesignator(
3426 InitExpressions.push_back(StartIndex);
3427 InitExpressions.push_back(EndIndex);
3437 EqualOrColonLoc, GNUSyntax,
3445InitializedEntity::InitializedEntity(
ASTContext &Context,
unsigned Index,
3450 Kind = EK_ArrayElement;
3453 Kind = EK_VectorElement;
3457 assert(CT &&
"Unexpected type");
3458 Kind = EK_ComplexElement;
3466 bool IsInheritedVirtualBase,
3471 Result.Base = {
Base, IsInheritedVirtualBase};
3489 return Variable.VariableOrMember->getDeclName();
3511 llvm_unreachable(
"Invalid EntityKind!");
3545 llvm_unreachable(
"Invalid EntityKind!");
3580unsigned InitializedEntity::dumpImpl(raw_ostream &OS)
const {
3583 for (
unsigned I = 0; I != Depth; ++I)
3600 case EK_New: OS <<
"New";
break;
3604 case EK_Base: OS <<
"Base";
break;
3611 OS <<
"Block (lambda)";
3614 OS <<
"LambdaCapture ";
3621 D->printQualifiedName(OS);
3624 OS <<
" '" <<
getType() <<
"'\n";
3630 dumpImpl(llvm::errs());
3685 for (
const Step &S : llvm::reverse(Steps)) {
3745 llvm_unreachable(
"Invalid EntityKind!");
3753InitializationSequence
3756 bool HadMultipleCandidates) {
3760 S.Function.HadMultipleCandidates = HadMultipleCandidates;
3762 S.Function.FoundDecl = Found;
3781 bool BindingTemporary) {
3806 bool HadMultipleCandidates) {
3810 S.Function.HadMultipleCandidates = HadMultipleCandidates;
3812 S.Function.FoundDecl = FoundDecl;
3851 bool TopLevelOfInitList) {
3869 bool HadMultipleCandidates,
bool FromInitList,
bool AsInitList) {
3875 S.Function.HadMultipleCandidates = HadMultipleCandidates;
3876 S.Function.Function = Constructor;
3877 S.Function.FoundDecl = FoundDecl;
3920 Steps.insert(Steps.begin(), S);
3981 "Can only rewrap trivial init lists.");
3985 Steps.insert(Steps.begin(), S);
3989 S.WrappingSyntacticList = Syntactic;
3996 this->Failure = Failure;
3997 this->FailedOverloadResult =
Result;
4018 if (!
Init.empty()) {
4038 "consuming an object of unretainable type?");
4059 bool TreatUnavailableAsInvalid);
4070 bool TreatUnavailableAsInvalid) {
4084 List->getNumInits()),
4089 List->getExprLoc(), List->getBeginLoc(), List->getEndLoc());
4091 TreatUnavailableAsInvalid);
4118 bool CopyInitializing,
bool AllowExplicit,
bool OnlyListConstructors,
4119 bool IsListInit,
bool RequireActualConstructor,
4120 bool SecondStepOfCopyInit =
false) {
4126 if (!Info.Constructor || Info.Constructor->isInvalidDecl())
4143 bool SuppressUserConversions =
4144 SecondStepOfCopyInit ||
4145 (IsListInit && Args.size() == 1 && isa<InitListExpr>(Args[0]) &&
4148 if (Info.ConstructorTmpl)
4150 Info.ConstructorTmpl, Info.FoundDecl,
4151 nullptr, Args, CandidateSet, SuppressUserConversions,
4152 false, AllowExplicit);
4161 bool AllowExplicitConv = AllowExplicit && !CopyInitializing &&
4165 CandidateSet, SuppressUserConversions,
4166 false, AllowExplicit,
4182 if (S.
getLangOpts().CPlusPlus17 && Args.size() == 1 &&
4183 !RequireActualConstructor && !SecondStepOfCopyInit) {
4185 auto *SourceRD =
Initializer->getType()->getAsCXXRecordDecl();
4187 const auto &Conversions = SourceRD->getVisibleConversionFunctions();
4188 for (
auto I = Conversions.begin(), E = Conversions.end(); I != E; ++I) {
4198 Conv = cast<CXXConversionDecl>(D);
4202 ConvTemplate, I.getPair(), ActingDC,
Initializer, DestType,
4203 CandidateSet, AllowExplicit, AllowExplicit,
4207 DestType, CandidateSet, AllowExplicit,
4234 bool IsListInit =
false,
4235 bool IsInitListCopy =
false) {
4236 assert(((!IsListInit && !IsInitListCopy) ||
4237 (Args.size() == 1 && isa<InitListExpr>(Args[0]))) &&
4238 "IsListInit/IsInitListCopy must come with a single initializer list "
4241 (IsListInit || IsInitListCopy) ? cast<InitListExpr>(Args[0]) :
nullptr;
4251 bool RequireActualConstructor =
4266 if (S.
getLangOpts().CPlusPlus17 && !RequireActualConstructor &&
4267 UnwrappedArgs.size() == 1 && UnwrappedArgs[0]->isPRValue() &&
4277 assert(DestRecordType &&
"Constructor initialization requires record type");
4279 = cast<CXXRecordDecl>(DestRecordType->
getDecl());
4287 bool AllowExplicit = Kind.AllowExplicit() || IsListInit;
4297 bool AsInitializerList =
false;
4309 AsInitializerList =
true;
4315 S, Kind.getLocation(), Args, CandidateSet, DestType, Ctors, Best,
4316 CopyInitialization, AllowExplicit,
4317 true, IsListInit, RequireActualConstructor);
4326 AsInitializerList =
false;
4328 S, Kind.getLocation(), UnwrappedArgs, CandidateSet, DestType, Ctors,
4329 Best, CopyInitialization, AllowExplicit,
4330 false, IsListInit, RequireActualConstructor);
4342 bool HadMultipleCandidates = (CandidateSet.
size() > 1);
4346 if (
auto *CD = dyn_cast<CXXConversionDecl>(Best->Function)) {
4348 QualType ConvType = CD->getConversionType();
4350 "should not have selected this conversion function");
4352 HadMultipleCandidates);
4383 if (IsListInit && !Kind.AllowExplicit() && CtorDecl->
isExplicit()) {
4403 Best->FoundDecl, CtorDecl, DestArrayType, HadMultipleCandidates,
4404 IsListInit | IsInitListCopy, AsInitializerList);
4417 bool HadMultipleCandidates =
false;
4420 UnqualifiedTargetType,
4422 &HadMultipleCandidates)) {
4424 HadMultipleCandidates);
4425 SourceType = Fn->getType();
4444 bool TopLevelOfInitList);
4458 bool TreatUnavailableAsInvalid) {
4498 T1Quals, cv2T2, T2, T2Quals, Sequence,
4529 TreatUnavailableAsInvalid);
4561 bool TreatUnavailableAsInvalid) {
4573 TreatUnavailableAsInvalid);
4611 !IsDesignatedInit) {
4616 Expr *InitListAsExpr = InitList;
4626 if (!isa<VariableArrayType>(DestAT) &&
4636 TreatUnavailableAsInvalid);
4669 TreatUnavailableAsInvalid))
4673 Expr *InitListAsExpr = InitList;
4675 DestType, Sequence,
true);
4693 ET && ET->getDecl()->isFixed() &&
4742 if (
Init->getType()->isRecordType() ||
4753 TreatUnavailableAsInvalid);
4760 InitListChecker CheckInitList(S, Entity, InitList,
4761 DestType,
true, TreatUnavailableAsInvalid);
4762 if (CheckInitList.HadError()) {
4784 "Must have incompatible references when binding via conversion");
4795 bool AllowExplicitCtors =
false;
4796 bool AllowExplicitConvs = Kind.allowExplicitConversionFunctionsInRefBinding();
4807 if (!Info.Constructor)
4810 if (!Info.Constructor->isInvalidDecl() &&
4811 Info.Constructor->isConvertingConstructor(
true)) {
4812 if (Info.ConstructorTmpl)
4814 Info.ConstructorTmpl, Info.FoundDecl,
4817 false, AllowExplicitCtors);
4820 Info.Constructor, Info.FoundDecl,
Initializer, CandidateSet,
4822 false, AllowExplicitCtors);
4837 for (
auto I = Conversions.begin(), E = Conversions.end(); I != E; ++I) {
4840 if (isa<UsingShadowDecl>(D))
4841 D = cast<UsingShadowDecl>(D)->getTargetDecl();
4848 Conv = cast<CXXConversionDecl>(D);
4856 if ((AllowRValues ||
4860 ConvTemplate, I.getPair(), ActingDC,
Initializer, DestType,
4862 false, AllowExplicitConvs);
4865 Conv, I.getPair(), ActingDC,
Initializer, DestType, CandidateSet,
4866 false, AllowExplicitConvs);
4888 if (isa<CXXConversionDecl>(
Function))
4901 bool HadMultipleCandidates = (CandidateSet.
size() > 1);
4903 HadMultipleCandidates);
4913 assert(!isa<CXXConstructorDecl>(
Function) &&
4914 "should not have conversion after constructor");
4918 ICS.
Standard = Best->FinalConversion;
4939 if (RefConv & Sema::ReferenceConversions::DerivedToBase)
4941 else if (RefConv & Sema::ReferenceConversions::ObjC)
4943 else if (RefConv & Sema::ReferenceConversions::Function)
4945 else if (RefConv & Sema::ReferenceConversions::Qualification) {
4962 bool TopLevelOfInitList) {
4980 T1Quals, cv2T2, T2, T2Quals, Sequence,
4981 TopLevelOfInitList);
5005 bool TopLevelOfInitList) {
5029 if (isLValueRef || T1Function) {
5032 (Kind.isCStyleOrFunctionalCast() &&
5036 if (RefConv & (Sema::ReferenceConversions::DerivedToBase |
5037 Sema::ReferenceConversions::ObjC)) {
5040 if (RefConv & (Sema::ReferenceConversions::Qualification))
5044 if (RefConv & Sema::ReferenceConversions::DerivedToBase)
5048 }
else if (RefConv & Sema::ReferenceConversions::Qualification) {
5052 }
else if (RefConv & Sema::ReferenceConversions::Function) {
5072 (isLValueRef || InitCategory.
isRValue())) {
5077 isLValueRef, Sequence);
5111 switch (RefRelationship) {
5123 llvm_unreachable(
"unexpected kind of compatible initializer");
5147 (Kind.isCStyleOrFunctionalCast() &&
5176 auto T1QualsIgnoreAS = T1Quals;
5177 auto T2QualsIgnoreAS = T2Quals;
5180 T2QualsIgnoreAS.removeAddressSpace();
5183 if (T1QualsIgnoreAS != T2QualsIgnoreAS)
5193 cv1T4 = cv1T4WithAS;
5198 if (RefConv & Sema::ReferenceConversions::DerivedToBase)
5200 else if (RefConv & Sema::ReferenceConversions::ObjC)
5202 else if (RefConv & Sema::ReferenceConversions::Qualification) {
5219 isLValueRef, Sequence);
5259 Sema::AllowedExplicit::None,
5261 Kind.isCStyleOrFunctionalCast(),
5280 TopLevelOfInitList);
5289 ((T1CVRQuals | T2CVRQuals) != T1CVRQuals ||
5334 assert((!InitList || InitList->
getNumInits() == 0) &&
5335 "Shouldn't use value-init for non-empty init lists");
5346 if (
CXXRecordDecl *ClassDecl = dyn_cast<CXXRecordDecl>(RT->getDecl())) {
5347 bool NeedZeroInitialization =
true;
5362 NeedZeroInitialization =
false;
5370 if (NeedZeroInitialization)
5384 ClassDecl->hasUninitializedReferenceMember()) {
5392 Expr *InitListAsExpr = InitList;
5394 bool InitListSyntax = InitList;
5399 S, Entity, Kind, Args, T, Entity.
getType(), Sequence, InitListSyntax);
5449 unsigned EntityIndexToProcess = 0;
5452 Expr *ArrayFiller =
nullptr;
5453 FieldDecl *InitializedFieldInUnion =
nullptr;
5457 Expr *Arg,
Expr **InitExpr =
nullptr) {
5459 S, SubEntity, SubKind, Arg ?
MultiExprArg(Arg) : std::nullopt);
5473 ER = IS.
Perform(S, SubEntity, SubKind,
5476 *InitExpr = ER.
get();
5478 InitExprs.push_back(ER.
get());
5486 uint64_t ArrayLength;
5494 ArrayLength = CAT->getZExtSize();
5495 ResultType = Entity.
getType();
5502 const Expr *SE = VAT->getSizeExpr();
5507 assert(isa<IncompleteArrayType>(Entity.
getType()));
5508 ArrayLength = Args.size();
5510 EntityIndexToProcess = ArrayLength;
5514 for (
Expr *E : Args) {
5519 if (!HandleInitializedEntity(SubEntity, SubKind, E))
5527 Kind.getLocation(), Kind.getLocation(), Kind.getLocation(),
true);
5528 if (!HandleInitializedEntity(SubEntity, SubKind,
nullptr, &ArrayFiller))
5532 if (ResultType.
isNull()) {
5539 const CXXRecordDecl *RD = cast<CXXRecordDecl>(RT->getDecl());
5553 if (EntityIndexToProcess < Args.size()) {
5559 Expr *E = Args[EntityIndexToProcess];
5562 if (!HandleInitializedEntity(SubEntity, SubKind, E))
5570 Kind.getLocation(), Kind.getLocation(), Kind.getLocation(),
5572 if (!HandleInitializedEntity(SubEntity, SubKind,
nullptr))
5575 EntityIndexToProcess++;
5588 if (EntityIndexToProcess < Args.size()) {
5590 Expr *E = Args[EntityIndexToProcess];
5608 if (!HandleInitializedEntity(SubEntity, SubKind, E))
5616 InitializedFieldInUnion = FD;
5617 EntityIndexToProcess = 1;
5629 Kind.getParenOrBraceRange().getEnd(), FD);
5633 InitExprs.push_back(DIE.
get());
5643 S.
Diag(SR.
getEnd(), diag::err_init_reference_member_uninitialized)
5650 Kind.getLocation(), Kind.getLocation(), Kind.getLocation(),
true);
5651 if (!HandleInitializedEntity(SubEntity, SubKind,
nullptr))
5655 EntityIndexToProcess++;
5657 ResultType = Entity.
getType();
5662 if (EntityIndexToProcess < Args.size()) {
5667 SourceRange ExcessInitSR(Args[EntityIndexToProcess]->getBeginLoc(),
5668 Args.back()->getEndLoc());
5669 S.
Diag(Kind.getLocation(), diag::err_excess_initializers)
5670 << InitKind << ExcessInitSR;
5684 CPLIE->setArrayFiller(ArrayFiller);
5685 if (InitializedFieldInUnion)
5686 CPLIE->setInitializedFieldInUnion(InitializedFieldInUnion);
5688 S.
Diag(Kind.getLocation(),
5689 diag::warn_cxx17_compat_aggregate_init_paren_list)
5690 << Kind.getLocation() << SR << ResultType;
5702 bool TopLevelOfInitList) {
5703 assert(!DestType->
isReferenceType() &&
"References are handled elsewhere");
5706 "Must have a class type to perform a user-defined conversion");
5716 bool AllowExplicit = Kind.AllowExplicit();
5722 = cast<CXXRecordDecl>(DestRecordType->getDecl());
5728 if (!Info.Constructor)
5731 if (!Info.Constructor->isInvalidDecl() &&
5732 Info.Constructor->isConvertingConstructor(
true)) {
5733 if (Info.ConstructorTmpl)
5735 Info.ConstructorTmpl, Info.FoundDecl,
5738 false, AllowExplicit);
5743 false, AllowExplicit);
5759 = cast<CXXRecordDecl>(SourceRecordType->getDecl());
5761 const auto &Conversions =
5763 for (
auto I = Conversions.begin(), E = Conversions.end(); I != E; ++I) {
5766 if (isa<UsingShadowDecl>(D))
5767 D = cast<UsingShadowDecl>(D)->getTargetDecl();
5774 Conv = cast<CXXConversionDecl>(D);
5778 ConvTemplate, I.getPair(), ActingDC,
Initializer, DestType,
5779 CandidateSet, AllowExplicit, AllowExplicit);
5782 DestType, CandidateSet, AllowExplicit,
5808 bool HadMultipleCandidates = (CandidateSet.
size() > 1);
5810 if (isa<CXXConstructorDecl>(
Function)) {
5816 HadMultipleCandidates);
5845 HadMultipleCandidates);
5858 Function->getReturnType()->isReferenceType() ||
5868 if (Best->FinalConversion.First || Best->FinalConversion.Second ||
5869 Best->FinalConversion.Third) {
5872 ICS.
Standard = Best->FinalConversion;
5890 isa<CXXBoolLiteralExpr>(
Init) &&
5891 !cast<CXXBoolLiteralExpr>(
Init)->getValue() &&
5900 bool isAddressOf,
bool &isWeakAccess) {
5906 if (op->getOpcode() == UO_AddrOf)
5911 }
else if (
CastExpr *ce = dyn_cast<CastExpr>(e)) {
5912 switch (ce->getCastKind()) {
5915 case CK_LValueBitCast:
5919 case CK_ArrayToPointerDecay:
5922 case CK_NullToPointer:
5930 }
else if (isa<DeclRefExpr>(e)) {
5934 isWeakAccess =
true;
5938 VarDecl *var = dyn_cast<VarDecl>(cast<DeclRefExpr>(e)->getDecl());
5952 }
else if (isa<ArraySubscriptExpr>(e)) {
5968 bool isWeakAccess =
false;
5972 if (S.
getLangOpts().ObjCAutoRefCount && isWeakAccess)
6004 bool ArrayDecay =
false;
6009 ArgPointee = ArgArrayType->getElementType();
6021 bool ShouldCopy =
true;
6092 "cl_intel_device_side_avc_motion_estimation", S.
getLangOpts()) &&
6094 if (DestType->isOCLIntelSubgroupAVCMcePayloadType() ||
6095 DestType->isOCLIntelSubgroupAVCMceResultType())
6109 MultiExprArg Args,
bool TopLevelOfInitList,
bool TreatUnavailableAsInvalid)
6113 TreatUnavailableAsInvalid);
6119 auto *DRE = dyn_cast<DeclRefExpr>(E);
6120 if (!DRE || !isa<FunctionDecl>(DRE->getDecl()))
6124 cast<FunctionDecl>(DRE->getDecl()));
6141 return isa<DecompositionDecl>(Entity.
getDecl());
6167 bool TopLevelOfInitList,
6168 bool TreatUnavailableAsInvalid) {
6175 for (
unsigned I = 0, E = Args.size(); I != E; ++I)
6176 if (Args[I]->getType()->isNonOverloadPlaceholderType()) {
6183 Args[I] = result.
get();
6205 if (Args.size() == 1) {
6223 TreatUnavailableAsInvalid);
6235 if (Args.size() != 1)
6241 else if (isa<InitListExpr>(Args[0]))
6245 TopLevelOfInitList);
6268 if (
Initializer && isa<VariableArrayType>(DestAT)) {
6300 if (
Initializer && isa<ConstantArrayType>(DestAT) &&
6318 Expr *OVEAsExpr = &OVE;
6320 TreatUnavailableAsInvalid);
6330 isa<CompoundLiteralExpr>(
Initializer->IgnoreParens()) &&
6348 *
this, TreatUnavailableAsInvalid);
6350 }
else if (S.
getLangOpts().CPlusPlus20 && !TopLevelOfInitList &&
6354 else if (DestAT->getElementType()->isCharType())
6366 bool allowObjCWritebackConversion = S.
getLangOpts().ObjCAutoRefCount &&
6375 assert(
Initializer &&
"Initializer must be non-null");
6377 if (allowObjCWritebackConversion &&
6403 SourceType, DestType))))) {
6410 if (
const auto *RD =
6415 S.
getLangOpts().CPlusPlus20 && RD && RD->hasDefinition() &&
6416 RD->isAggregate() &&
Failed() &&
6429 S, Kind.getLocation(), Best);
6447 assert(
Initializer &&
"Initializer must be non-null");
6449 TopLevelOfInitList);
6454 assert(Args.size() >= 1 &&
"Zero-argument case handled above");
6464 for (
auto *Arg : Args) {
6465 if (Arg->getType()->isExtVectorType()) {
6468 for (
unsigned Idx = 0; Idx < Elm; ++Idx) {
6474 VTy->getElementType(), Arg->
getValueKind(), Arg->getObjectKind(),
6478 InitArgs.emplace_back(Arg);
6488 if (Args.size() > 1) {
6491 }
else if (isa<InitListExpr>(Args[0])) {
6499 assert(
Initializer &&
"Initializer must be non-null");
6502 bool NeedAtomicConversion =
false;
6506 Atomic->getValueType())) {
6507 DestType =
Atomic->getValueType();
6508 NeedAtomicConversion =
true;
6513 TopLevelOfInitList);
6515 if (!
Failed() && NeedAtomicConversion)
6542 Sema::AllowedExplicit::None,
6544 Kind.isCStyleOrFunctionalCast(),
6545 allowObjCWritebackConversion);
6553 bool ShouldCopy =
true;
6569 }
else if (ICS.
isBad()) {
6577 else if (
Initializer->getType()->isFunctionType() &&
6590 for (
auto &S : Steps)
6648 llvm_unreachable(
"Invalid EntityKind!");
6682 llvm_unreachable(
"missed an InitializedEntity kind?");
6716 llvm_unreachable(
"missed an InitializedEntity kind?");
6755 llvm_unreachable(
"missed an InitializedEntity kind?");
6782 bool IsExtraneousCopy) {
6807 S, Loc, CurInitExpr, CandidateSet, T, Ctors, Best,
6819 ? diag::ext_rvalue_to_reference_temp_copy_no_viable
6820 : diag::err_temp_copy_no_viable)
6838 S.
Diag(Loc, diag::err_temp_copy_deleted)
6845 bool HadMultipleCandidates = CandidateSet.
size() > 1;
6854 if (IsExtraneousCopy) {
6865 for (
unsigned I = 1, N = Constructor->getNumParams(); I != N; ++I) {
6868 diag::err_call_incomplete_argument))
6909 Best->Function->getParamDecl(0)->getType().getNonReferenceType(),
6914 Loc, T, Best->FoundDecl, Constructor, Elidable, ConstructorArgs,
6915 HadMultipleCandidates,
6931 Expr *CurInitExpr) {
6950 S, Loc, CurInitExpr, CandidateSet, CurInitExpr->
getType(), Ctors, Best,
6963 Best->FoundDecl, Entity,
Diag);
6984void InitializationSequence::PrintInitLocationNote(
Sema &S,
6999 diag::note_method_return_type_change)
7017 switch (Kind.getKind()) {
7023 return NumArgs != 1;
7035 bool &ConstructorInitRequiresZeroInit,
7036 bool IsListInitialization,
7037 bool IsStdInitListInitialization,
7040 unsigned NumArgs = Args.size();
7047 SourceLocation Loc = (Kind.isCopyInit() && Kind.getEqualLoc().isValid())
7048 ? Kind.getEqualLoc()
7049 : Kind.getLocation();
7055 assert(Constructor->getParent() &&
"No parent class for constructor.");
7056 if (Constructor->isDefaulted() && Constructor->isDefaultConstructor() &&
7057 Constructor->isTrivial() && !Constructor->isUsed(
false)) {
7072 bool AllowExplicitConv =
7073 Kind.AllowExplicit() && !Kind.isCopyInit() && Args.size() == 1 &&
7080 ConstructorArgs, AllowExplicitConv,
7081 IsListInitialization))
7095 : Kind.getParenOrBraceRange();
7098 if (
auto *Shadow = dyn_cast<ConstructorUsingShadowDecl>(
7108 ConstructorArgs, ParenOrBraceRange, HadMultipleCandidates,
7109 IsListInitialization, IsStdInitListInitialization,
7110 ConstructorInitRequiresZeroInit),
7126 if (IsListInitialization)
7127 ParenOrBraceRange =
SourceRange(LBraceLoc, RBraceLoc);
7129 ParenOrBraceRange = Kind.getParenOrBraceRange();
7138 HadMultipleCandidates,
7139 IsListInitialization,
7140 IsStdInitListInitialization,
7141 ConstructorInitRequiresZeroInit,
7149 HadMultipleCandidates,
7150 IsListInitialization,
7151 IsStdInitListInitialization,
7152 ConstructorInitRequiresZeroInit,
7200using LifetimeResult =
7201 llvm::PointerIntPair<const InitializedEntity *, 3, LifetimeKind>;
7214 return {Entity, LK_Extended};
7234 : LK_MemInitializer};
7239 return {Entity, LK_Extended};
7246 return {
nullptr, LK_FullExpression};
7250 return {
nullptr, LK_FullExpression};
7256 return {
nullptr, LK_Return};
7261 return {
nullptr, LK_StmtExprResult};
7267 return {
nullptr, LK_New};
7275 return {
nullptr, LK_FullExpression};
7285 return {InitField, LK_MemInitializer};
7292 return {InitField, LK_MemInitializer};
7299 return {
nullptr, LK_FullExpression};
7303 return {
nullptr, LK_FullExpression};
7310 return {
nullptr, LK_FullExpression};
7313 llvm_unreachable(
"unknown entity kind");
7319 RK_ReferenceBinding,
7322 RK_StdInitializerList,
7335struct IndirectLocalPathEntry {
7349 const Decl *D =
nullptr;
7352 IndirectLocalPathEntry() {}
7353 IndirectLocalPathEntry(EntryKind K,
Expr *E) :
Kind(K), E(E) {}
7354 IndirectLocalPathEntry(EntryKind K,
Expr *E,
const Decl *D)
7355 :
Kind(K), E(E), D(D) {}
7362struct RevertToOldSizeRAII {
7363 IndirectLocalPath &Path;
7364 unsigned OldSize = Path.size();
7365 RevertToOldSizeRAII(IndirectLocalPath &Path) : Path(Path) {}
7366 ~RevertToOldSizeRAII() { Path.resize(OldSize); }
7369using LocalVisitor = llvm::function_ref<
bool(IndirectLocalPath &Path, Local L,
7375 if (E.Kind == IndirectLocalPathEntry::VarInit && E.D == VD)
7381 return llvm::any_of(Path, [=](IndirectLocalPathEntry E) {
7382 return E.Kind == IndirectLocalPathEntry::DefaultInit ||
7383 E.Kind == IndirectLocalPathEntry::VarInit;
7389 bool RevisitSubinits,
7390 bool EnableLifetimeWarnings);
7395 bool EnableLifetimeWarnings);
7410 if (
const auto *ND = dyn_cast<NamespaceDecl>(DC))
7412 StringRef Name = II->getName();
7413 if (Name.size() >= 2 && Name.front() ==
'_' &&
7422 if (
auto *Conv = dyn_cast_or_null<CXXConversionDecl>(Callee))
7423 if (isRecordWithAttr<PointerAttr>(Conv->getConversionType()))
7427 if (!isRecordWithAttr<PointerAttr>(
7428 Callee->getFunctionObjectParameterType()) &&
7429 !isRecordWithAttr<OwnerAttr>(Callee->getFunctionObjectParameterType()))
7431 if (Callee->getReturnType()->isPointerType() ||
7432 isRecordWithAttr<PointerAttr>(Callee->getReturnType())) {
7433 if (!Callee->getIdentifier())
7435 return llvm::StringSwitch<bool>(Callee->getName())
7436 .Cases(
"begin",
"rbegin",
"cbegin",
"crbegin",
true)
7437 .Cases(
"end",
"rend",
"cend",
"crend",
true)
7438 .Cases(
"c_str",
"data",
"get",
true)
7440 .Cases(
"find",
"equal_range",
"lower_bound",
"upper_bound",
true)
7442 }
else if (Callee->getReturnType()->isReferenceType()) {
7443 if (!Callee->getIdentifier()) {
7444 auto OO = Callee->getOverloadedOperator();
7445 return OO == OverloadedOperatorKind::OO_Subscript ||
7446 OO == OverloadedOperatorKind::OO_Star;
7448 return llvm::StringSwitch<bool>(Callee->getName())
7449 .Cases(
"front",
"back",
"at",
"top",
"value",
true)
7466 return llvm::StringSwitch<bool>(FD->
getName())
7467 .Cases(
"begin",
"rbegin",
"cbegin",
"crbegin",
true)
7468 .Cases(
"end",
"rend",
"cend",
"crend",
true)
7472 return llvm::StringSwitch<bool>(FD->
getName())
7473 .Cases(
"get",
"any_cast",
true)
7480 LocalVisitor Visit) {
7481 auto VisitPointerArg = [&](
const Decl *D,
Expr *Arg,
bool Value) {
7484 if (isa<MemberExpr>(Arg->IgnoreImpCasts()))
7488 for (
const IndirectLocalPathEntry &PE : llvm::reverse(Path)) {
7489 if (PE.Kind == IndirectLocalPathEntry::GslReferenceInit)
7491 if (PE.Kind == IndirectLocalPathEntry::GslPointerInit)
7496 Path.push_back({
Value ? IndirectLocalPathEntry::GslPointerInit
7497 : IndirectLocalPathEntry::GslReferenceInit,
7499 if (Arg->isGLValue())
7509 if (
auto *MCE = dyn_cast<CXXMemberCallExpr>(
Call)) {
7510 const auto *MD = cast_or_null<CXXMethodDecl>(MCE->getDirectCallee());
7512 VisitPointerArg(MD, MCE->getImplicitObjectArgument(),
7513 !MD->getReturnType()->isReferenceType());
7515 }
else if (
auto *OCE = dyn_cast<CXXOperatorCallExpr>(
Call)) {
7517 if (Callee && Callee->isCXXInstanceMember() &&
7519 VisitPointerArg(Callee, OCE->getArg(0),
7520 !Callee->getReturnType()->isReferenceType());
7522 }
else if (
auto *CE = dyn_cast<CallExpr>(
Call)) {
7525 VisitPointerArg(Callee, CE->getArg(0),
7526 !Callee->getReturnType()->isReferenceType());
7530 if (
auto *CCE = dyn_cast<CXXConstructExpr>(
Call)) {
7531 const auto *Ctor = CCE->getConstructor();
7533 if (CCE->getNumArgs() > 0 && RD->
hasAttr<PointerAttr>())
7534 VisitPointerArg(Ctor->getParamDecl(0), CCE->getArgs()[0],
true);
7562 auto *MD = dyn_cast<CXXMethodDecl>(FD);
7563 if (MD && MD->isCXXInstanceMember())
7566 LHST = MD->getParamDecl(0)->getType();
7576 LocalVisitor Visit) {
7580 if (
auto *CE = dyn_cast<CallExpr>(
Call)) {
7581 Callee = CE->getDirectCallee();
7584 auto *CCE = cast<CXXConstructExpr>(
Call);
7585 Callee = CCE->getConstructor();
7591 Expr *ObjectArg =
nullptr;
7592 if (isa<CXXOperatorCallExpr>(
Call) && Callee->isCXXInstanceMember()) {
7593 ObjectArg = Args[0];
7594 Args = Args.slice(1);
7595 }
else if (
auto *MCE = dyn_cast<CXXMemberCallExpr>(
Call)) {
7596 ObjectArg = MCE->getImplicitObjectArgument();
7599 auto VisitLifetimeBoundArg = [&](
const Decl *D,
Expr *Arg) {
7600 Path.push_back({IndirectLocalPathEntry::LifetimeBoundCall, Arg, D});
7601 if (Arg->isGLValue())
7611 bool CheckCoroCall =
false;
7612 if (
const auto *RD = Callee->getReturnType()->getAsRecordDecl()) {
7613 CheckCoroCall = RD->
hasAttr<CoroLifetimeBoundAttr>() &&
7614 RD->
hasAttr<CoroReturnTypeAttr>() &&
7615 !Callee->hasAttr<CoroDisableLifetimeBoundAttr>();
7619 bool CheckCoroObjArg = CheckCoroCall;
7621 if (
auto *LE = dyn_cast<LambdaExpr>(ObjectArg->
IgnoreImplicit());
7622 LE && LE->captures().empty())
7623 CheckCoroObjArg =
false;
7627 CheckCoroObjArg =
false;
7629 VisitLifetimeBoundArg(Callee, ObjectArg);
7632 for (
unsigned I = 0,
7633 N = std::min<unsigned>(Callee->getNumParams(), Args.size());
7635 if (CheckCoroCall || Callee->getParamDecl(I)->hasAttr<LifetimeBoundAttr>())
7636 VisitLifetimeBoundArg(Callee->getParamDecl(I), Args[I]);
7645 bool EnableLifetimeWarnings) {
7646 RevertToOldSizeRAII RAII(Path);
7653 if (
auto *FE = dyn_cast<FullExpr>(
Init))
7654 Init = FE->getSubExpr();
7664 Init =
const_cast<Expr *
>(
Init->skipRValueSubobjectAdjustments());
7669 if (CE->getSubExpr()->isGLValue())
7670 Init = CE->getSubExpr();
7674 if (
auto *ASE = dyn_cast<ArraySubscriptExpr>(
Init)) {
7675 Init = ASE->getBase();
7676 auto *ICE = dyn_cast<ImplicitCastExpr>(
Init);
7677 if (ICE && ICE->getCastKind() == CK_ArrayToPointerDecay)
7678 Init = ICE->getSubExpr();
7683 EnableLifetimeWarnings);
7688 if (
auto *DIE = dyn_cast<CXXDefaultInitExpr>(
Init)) {
7690 {IndirectLocalPathEntry::DefaultInit, DIE, DIE->getField()});
7691 Init = DIE->getExpr();
7693 }
while (
Init != Old);
7695 if (
auto *MTE = dyn_cast<MaterializeTemporaryExpr>(
Init)) {
7696 if (Visit(Path, Local(MTE), RK))
7698 EnableLifetimeWarnings);
7701 if (isa<CallExpr>(
Init)) {
7702 if (EnableLifetimeWarnings)
7707 switch (
Init->getStmtClass()) {
7708 case Stmt::DeclRefExprClass: {
7711 auto *DRE = cast<DeclRefExpr>(
Init);
7712 auto *VD = dyn_cast<VarDecl>(DRE->getDecl());
7713 if (VD && VD->hasLocalStorage() &&
7714 !DRE->refersToEnclosingVariableOrCapture()) {
7716 Visit(Path, Local(DRE), RK);
7717 }
else if (isa<ParmVarDecl>(DRE->getDecl())) {
7721 }
else if (VD->getInit() && !
isVarOnPath(Path, VD)) {
7722 Path.push_back({IndirectLocalPathEntry::VarInit, DRE, VD});
7724 RK_ReferenceBinding, Visit,
7725 EnableLifetimeWarnings);
7731 case Stmt::UnaryOperatorClass: {
7736 if (
U->getOpcode() == UO_Deref)
7738 EnableLifetimeWarnings);
7742 case Stmt::OMPArraySectionExprClass: {
7744 cast<OMPArraySectionExpr>(
Init)->getBase(),
7745 Visit,
true, EnableLifetimeWarnings);
7749 case Stmt::ConditionalOperatorClass:
7750 case Stmt::BinaryConditionalOperatorClass: {
7751 auto *
C = cast<AbstractConditionalOperator>(
Init);
7752 if (!
C->getTrueExpr()->getType()->isVoidType())
7754 EnableLifetimeWarnings);
7755 if (!
C->getFalseExpr()->getType()->isVoidType())
7757 EnableLifetimeWarnings);
7761 case Stmt::CompoundLiteralExprClass: {
7762 if (
auto *CLE = dyn_cast<CompoundLiteralExpr>(
Init)) {
7763 if (!CLE->isFileScope())
7764 Visit(Path, Local(CLE), RK);
7780 bool RevisitSubinits,
7781 bool EnableLifetimeWarnings) {
7782 RevertToOldSizeRAII RAII(Path);
7790 if (
auto *DIE = dyn_cast<CXXDefaultInitExpr>(
Init)) {
7791 Path.push_back({IndirectLocalPathEntry::DefaultInit, DIE, DIE->getField()});
7792 Init = DIE->getExpr();
7795 if (
auto *FE = dyn_cast<FullExpr>(
Init))
7796 Init = FE->getSubExpr();
7799 Init =
const_cast<Expr *
>(
Init->skipRValueSubobjectAdjustments());
7802 Init = BTE->getSubExpr();
7807 if (
auto *CE = dyn_cast<CastExpr>(
Init)) {
7808 switch (CE->getCastKind()) {
7809 case CK_LValueToRValue:
7812 Path.push_back({IndirectLocalPathEntry::LValToRVal, CE});
7814 Path,
Init, RK_ReferenceBinding,
7815 [&](IndirectLocalPath &Path, Local L, ReferenceKind RK) ->
bool {
7816 if (
auto *DRE = dyn_cast<DeclRefExpr>(L)) {
7817 auto *VD = dyn_cast<VarDecl>(DRE->getDecl());
7820 Path.push_back({IndirectLocalPathEntry::VarInit, DRE, VD});
7822 EnableLifetimeWarnings);
7824 }
else if (
auto *MTE = dyn_cast<MaterializeTemporaryExpr>(L)) {
7825 if (MTE->getType().isConstQualified())
7827 true, EnableLifetimeWarnings);
7830 }, EnableLifetimeWarnings);
7838 case CK_BaseToDerived:
7839 case CK_DerivedToBase:
7840 case CK_UncheckedDerivedToBase:
7843 case CK_UserDefinedConversion:
7844 case CK_ConstructorConversion:
7845 case CK_IntegralToPointer:
7846 case CK_PointerToIntegral:
7847 case CK_VectorSplat:
7848 case CK_IntegralCast:
7849 case CK_CPointerToObjCPointerCast:
7850 case CK_BlockPointerToObjCPointerCast:
7851 case CK_AnyPointerToBlockPointerCast:
7852 case CK_AddressSpaceConversion:
7855 case CK_ArrayToPointerDecay:
7858 Path.push_back({IndirectLocalPathEntry::AddressOf, CE});
7860 RK_ReferenceBinding, Visit,
7861 EnableLifetimeWarnings);
7867 Init = CE->getSubExpr();
7869 }
while (Old !=
Init);
7874 if (
auto *ILE = dyn_cast<CXXStdInitializerListExpr>(
Init))
7876 RK_StdInitializerList, Visit,
7877 EnableLifetimeWarnings);
7883 if (!RevisitSubinits)
7889 EnableLifetimeWarnings);
7892 for (
unsigned I = 0, N = ILE->
getNumInits(); I != N; ++I)
7895 EnableLifetimeWarnings);
7900 assert(RD->isAggregate() &&
"aggregate init on non-aggregate");
7908 RK_ReferenceBinding, Visit,
7909 EnableLifetimeWarnings);
7912 for (; Index < RD->getNumBases() && Index < ILE->getNumInits(); ++Index)
7915 EnableLifetimeWarnings);
7916 for (
const auto *I : RD->
fields()) {
7919 if (I->isUnnamedBitfield())
7922 if (I->getType()->isReferenceType())
7924 RK_ReferenceBinding, Visit,
7925 EnableLifetimeWarnings);
7932 EnableLifetimeWarnings);
7942 if (
auto *LE = dyn_cast<LambdaExpr>(
Init)) {
7944 for (
Expr *E : LE->capture_inits()) {
7945 assert(CapI != LE->capture_end());
7950 Path.push_back({IndirectLocalPathEntry::LambdaCaptureInit, E, &Cap});
7953 Visit, EnableLifetimeWarnings);
7956 EnableLifetimeWarnings);
7964 if (
auto *CCE = dyn_cast<CXXConstructExpr>(
Init)) {
7965 if (CCE->getConstructor()->isCopyOrMoveConstructor()) {
7966 if (
auto *MTE = dyn_cast<MaterializeTemporaryExpr>(CCE->getArg(0))) {
7967 Expr *Arg = MTE->getSubExpr();
7968 Path.push_back({IndirectLocalPathEntry::TemporaryCopy, Arg,
7969 CCE->getConstructor()});
7977 if (isa<CallExpr>(
Init) || isa<CXXConstructExpr>(
Init)) {
7978 if (EnableLifetimeWarnings)
7983 switch (
Init->getStmtClass()) {
7984 case Stmt::UnaryOperatorClass: {
7985 auto *UO = cast<UnaryOperator>(
Init);
7988 if (UO->getOpcode() == UO_AddrOf) {
7992 if (isa<MaterializeTemporaryExpr>(UO->getSubExpr()))
7995 Path.push_back({IndirectLocalPathEntry::AddressOf, UO});
7997 RK_ReferenceBinding, Visit,
7998 EnableLifetimeWarnings);
8003 case Stmt::BinaryOperatorClass: {
8005 auto *BO = cast<BinaryOperator>(
Init);
8007 if (!BO->getType()->isPointerType() || (BOK != BO_Add && BOK != BO_Sub))
8010 if (BO->getLHS()->getType()->isPointerType())
8012 EnableLifetimeWarnings);
8013 else if (BO->getRHS()->getType()->isPointerType())
8015 EnableLifetimeWarnings);
8019 case Stmt::ConditionalOperatorClass:
8020 case Stmt::BinaryConditionalOperatorClass: {
8021 auto *
C = cast<AbstractConditionalOperator>(
Init);
8024 if (!
C->getTrueExpr()->getType()->isVoidType())
8026 EnableLifetimeWarnings);
8027 if (!
C->getFalseExpr()->getType()->isVoidType())
8029 EnableLifetimeWarnings);
8033 case Stmt::BlockExprClass:
8034 if (cast<BlockExpr>(
Init)->getBlockDecl()->hasCaptures()) {
8036 Visit(Path, Local(cast<BlockExpr>(
Init)), RK_ReferenceBinding);
8040 case Stmt::AddrLabelExprClass:
8042 Visit(Path, Local(cast<AddrLabelExpr>(
Init)), RK_ReferenceBinding);
8068 for (
auto Elem : Path) {
8069 if (Elem.Kind == IndirectLocalPathEntry::DefaultInit)
8070 Kind = PathLifetimeKind::ShouldExtend;
8071 else if (Elem.Kind != IndirectLocalPathEntry::LambdaCaptureInit)
8072 return PathLifetimeKind::NoExtend;
8080 for (
unsigned N = Path.size(); I != N; ++I) {
8081 switch (Path[I].Kind) {
8082 case IndirectLocalPathEntry::AddressOf:
8083 case IndirectLocalPathEntry::LValToRVal:
8084 case IndirectLocalPathEntry::LifetimeBoundCall:
8085 case IndirectLocalPathEntry::TemporaryCopy:
8086 case IndirectLocalPathEntry::GslReferenceInit:
8087 case IndirectLocalPathEntry::GslPointerInit:
8092 case IndirectLocalPathEntry::VarInit:
8093 if (cast<VarDecl>(Path[I].D)->isImplicit())
8096 case IndirectLocalPathEntry::DefaultInit:
8097 return Path[I].E->getSourceRange();
8099 case IndirectLocalPathEntry::LambdaCaptureInit:
8100 if (!Path[I].
Capture->capturesVariable())
8102 return Path[I].E->getSourceRange();
8109 for (
const auto &It : llvm::reverse(Path)) {
8110 if (It.Kind == IndirectLocalPathEntry::VarInit)
8112 if (It.Kind == IndirectLocalPathEntry::AddressOf)
8114 if (It.Kind == IndirectLocalPathEntry::LifetimeBoundCall)
8116 return It.Kind == IndirectLocalPathEntry::GslPointerInit ||
8117 It.Kind == IndirectLocalPathEntry::GslReferenceInit;
8125 LifetimeKind LK = LR.getInt();
8130 if (LK == LK_FullExpression)
8133 auto TemporaryVisitor = [&](IndirectLocalPath &Path, Local L,
8134 ReferenceKind RK) ->
bool {
8138 auto *MTE = dyn_cast<MaterializeTemporaryExpr>(L);
8140 bool IsGslPtrInitWithGslTempOwner =
false;
8141 bool IsLocalGslOwner =
false;
8143 if (isa<DeclRefExpr>(L)) {
8149 IsLocalGslOwner = isRecordWithAttr<OwnerAttr>(L->getType());
8153 IsGslPtrInitWithGslTempOwner = MTE && !MTE->getExtendingDecl() &&
8154 isRecordWithAttr<OwnerAttr>(MTE->getType());
8158 if (!IsGslPtrInitWithGslTempOwner)
8164 case LK_FullExpression:
8165 llvm_unreachable(
"already handled this");
8177 if (IsGslPtrInitWithGslTempOwner && DiagLoc.
isValid()) {
8178 Diag(DiagLoc, diag::warn_dangling_lifetime_pointer) << DiagRange;
8183 case PathLifetimeKind::Extend:
8186 MTE->setExtendingDecl(ExtendingEntity->
getDecl(),
8191 case PathLifetimeKind::ShouldExtend:
8198 Diag(DiagLoc, diag::warn_unsupported_lifetime_extension)
8202 case PathLifetimeKind::NoExtend:
8209 Diag(DiagLoc, diag::warn_dangling_variable)
8212 << ExtendingEntity->
getDecl() <<
Init->isGLValue() << DiagRange;
8218 case LK_MemInitializer: {
8219 if (isa<MaterializeTemporaryExpr>(L)) {
8223 if (
auto *ExtendingDecl =
8224 ExtendingEntity ? ExtendingEntity->
getDecl() :
nullptr) {
8225 if (IsGslPtrInitWithGslTempOwner) {
8226 Diag(DiagLoc, diag::warn_dangling_lifetime_pointer_member)
8227 << ExtendingDecl << DiagRange;
8228 Diag(ExtendingDecl->getLocation(),
8229 diag::note_ref_or_ptr_member_declared_here)
8233 bool IsSubobjectMember = ExtendingEntity != &Entity;
8235 PathLifetimeKind::NoExtend
8236 ? diag::err_dangling_member
8237 : diag::warn_dangling_member)
8238 << ExtendingDecl << IsSubobjectMember << RK << DiagRange;
8243 Path.back().Kind != IndirectLocalPathEntry::DefaultInit) {
8244 Diag(ExtendingDecl->getLocation(),
8245 diag::note_lifetime_extending_member_declared_here)
8246 << RK << IsSubobjectMember;
8269 auto *DRE = dyn_cast<DeclRefExpr>(L);
8270 auto *VD = DRE ? dyn_cast<VarDecl>(DRE->getDecl()) :
nullptr;
8278 ExtendingEntity ? ExtendingEntity->
getDecl() :
nullptr) {
8279 bool IsPointer = !
Member->getType()->isReferenceType();
8280 Diag(DiagLoc, IsPointer ? diag::warn_init_ptr_member_to_parameter_addr
8281 : diag::warn_bind_ref_member_to_parameter)
8282 << Member << VD << isa<ParmVarDecl>(VD) << DiagRange;
8284 diag::note_ref_or_ptr_member_declared_here)
8292 if (isa<MaterializeTemporaryExpr>(L)) {
8293 if (IsGslPtrInitWithGslTempOwner)
8294 Diag(DiagLoc, diag::warn_dangling_lifetime_pointer) << DiagRange;
8296 Diag(DiagLoc, RK == RK_ReferenceBinding
8297 ? diag::warn_new_dangling_reference
8298 : diag::warn_new_dangling_initializer_list)
8307 case LK_StmtExprResult:
8308 if (
auto *DRE = dyn_cast<DeclRefExpr>(L)) {
8311 if (LK == LK_StmtExprResult)
8313 Diag(DiagLoc, diag::warn_ret_stack_addr_ref)
8315 << isa<ParmVarDecl>(DRE->getDecl()) << DiagRange;
8316 }
else if (isa<BlockExpr>(L)) {
8317 Diag(DiagLoc, diag::err_ret_local_block) << DiagRange;
8318 }
else if (isa<AddrLabelExpr>(L)) {
8321 if (LK == LK_StmtExprResult)
8323 Diag(DiagLoc, diag::warn_ret_addr_label) << DiagRange;
8324 }
else if (
auto *CLE = dyn_cast<CompoundLiteralExpr>(L)) {
8325 Diag(DiagLoc, diag::warn_ret_stack_addr_ref)
8329 Diag(DiagLoc, diag::warn_ret_local_temp_addr_ref)
8335 for (
unsigned I = 0; I != Path.size(); ++I) {
8336 auto Elem = Path[I];
8338 switch (Elem.Kind) {
8339 case IndirectLocalPathEntry::AddressOf:
8340 case IndirectLocalPathEntry::LValToRVal:
8345 case IndirectLocalPathEntry::LifetimeBoundCall:
8346 case IndirectLocalPathEntry::TemporaryCopy:
8347 case IndirectLocalPathEntry::GslPointerInit:
8348 case IndirectLocalPathEntry::GslReferenceInit:
8352 case IndirectLocalPathEntry::DefaultInit: {
8353 auto *FD = cast<FieldDecl>(Elem.D);
8354 Diag(FD->
getLocation(), diag::note_init_with_default_member_initializer)
8359 case IndirectLocalPathEntry::VarInit: {
8360 const VarDecl *VD = cast<VarDecl>(Elem.D);
8368 case IndirectLocalPathEntry::LambdaCaptureInit:
8369 if (!Elem.Capture->capturesVariable())
8373 const ValueDecl *VD = Elem.Capture->getCapturedVar();
8374 Diag(Elem.Capture->getLocation(), diag::note_lambda_capture_initializer)
8376 << (Elem.Capture->getCaptureKind() ==
LCK_ByRef) << VD
8390 if (
Init->isGLValue())
8393 EnableLifetimeWarnings);
8396 EnableLifetimeWarnings);
8403 const Expr *PostInit);
8410 bool IsReturnStmt) {
8421 unsigned DiagID = 0;
8451 if (VD->
hasAttr<BlocksAttr>())
8464 if (isa<ParmVarDecl>(VD))
8465 DiagID = diag::warn_redundant_move_on_return;
8467 DiagID = diag::warn_pessimizing_move_on_return;
8469 DiagID = diag::warn_pessimizing_move_on_initialization;
8511 if (UO->getOpcode() == UO_Deref &&
8512 UO->getSubExpr()->IgnoreParenCasts()->
8515 S.
PDiag(diag::warn_binding_null_to_reference)
8516 << UO->getSubExpr()->getSourceRange());
8522 bool BoundToLvalueReference) {
8535 Record.ForRangeLifetimeExtendTemps.push_back(MTE);
8567 if (!PointeeTy.isNull() &&
8568 PointeeTy.getAddressSpace() != ExprPointeeTy.getAddressSpace())
8569 CK = CK_AddressSpaceConversion;
8571 CK = CK_AddressSpaceConversion;
8586 if (!ZeroInitializationFixit.empty()) {
8588 const auto *VD = dyn_cast_or_null<VarDecl>(D);
8594 if (!DestType->
isRecordType() && VD && VD->isConstexpr()) {
8596 S.
Diag(Kind.getLocation(), diag::err_constexpr_var_requires_const_init)
8599 ZeroInitializationFixit);
8601 unsigned DiagID = diag::err_default_init_const;
8603 DiagID = diag::ext_default_init_const;
8605 S.
Diag(Kind.getLocation(), DiagID)
8608 ZeroInitializationFixit);
8628 if (isa<InitListExpr>((
Expr *)Args[0])) {
8632 if (
auto *DD = dyn_cast_or_null<DeclaratorDecl>(Entity.
getDecl())) {
8634 TypeLoc TL = TInfo->getTypeLoc();
8637 Brackets = ArrayLoc.getBracketsRange();
8644 ArrayT->getSizeModifier(),
8645 ArrayT->getIndexTypeCVRQualifiers(),
8652 !Kind.isExplicitCast()) {
8654 SourceRange ParenRange = Kind.getParenOrBraceRange();
8659 Kind.isExplicitCast() ||
8669 Args.size() == 1 && isa<InitListExpr>(Args[0]) &&
8675 S.
Diag(
Init->getBeginLoc(), diag::warn_cxx98_compat_reference_list_init)
8676 <<
Init->getSourceRange();
8679 if (S.
getLangOpts().MicrosoftExt && Args.size() == 1 &&
8685 S.
Diag(
Init->getBeginLoc(), diag::ext_init_from_predefined) <<
Init;
8696 S.
Diag(Args[0]->getBeginLoc(), diag::err_opencl_atomic_init)
8716 isa<InitListExpr>(Args[0]);
8717 (void)IsHLSLVectorInit;
8722 switch (Steps.front().Kind) {
8756 assert(Args.size() == 1 || IsHLSLVectorInit);
8775 CurInit.
get() && isa<InitListExpr>(CurInit.
get()));
8780 auto checkAbstractType = [&](
QualType T) ->
bool {
8785 diag::err_allocation_of_abstract_type);
8790 bool ConstructorInitRequiresZeroInit =
false;
8823 bool IgnoreBaseAccess = Kind.isCStyleOrFunctionalCast();
8835 CK_DerivedToBase, CurInit.
get(),
8851 if (
auto *DRE = dyn_cast<DeclRefExpr>(CurInit.
get()->
IgnoreParens())) {
8852 if (
auto *FD = dyn_cast<FunctionDecl>(DRE->getDecl())) {
8865 assert(CurInit.
get()->
isPRValue() &&
"not a temporary");
8923 bool CreatedObject =
false;
8939 Loc,
Step->
Type, FoundFn, Constructor, ConstructorArgs,
8940 HadMultipleCandidates,
8952 CastKind = CK_ConstructorConversion;
8953 CreatedObject =
true;
8963 HadMultipleCandidates);
8967 CastKind = CK_UserDefinedConversion;
8971 if (CreatedObject && checkAbstractType(CurInit.
get()->
getType()))
8992 S.
PDiag(diag::err_access_dtor_temp) << T);
9016 "function reference should be lvalue");
9022 assert(CurInit.
get()->
isPRValue() &&
"cannot convert glvalue to atomic");
9030 if (
const auto *FromPtrType =
9033 if (FromPtrType->getPointeeType()->hasAttr(attr::NoDeref) &&
9034 !ToPtrType->getPointeeType()->hasAttr(attr::NoDeref)) {
9037 if (!Kind.isStaticCast()) {
9039 diag::warn_noderef_to_dereferenceable_pointer)
9059 CurInit = CurInitExprRes;
9080 InitListChecker PerformInitList(S, InitEntity,
9081 InitList, Ty,
false,
9083 if (PerformInitList.HadError())
9091 if ((*ResultType)->isRValueReferenceType())
9093 else if ((*ResultType)->isLValueReferenceType())
9100 PerformInitList.getFullyStructuredList();
9104 : StructuredInitList;
9121 assert(Args.size() == 1 &&
"expected a single argument for list init");
9123 S.
Diag(InitList->
getExprLoc(), diag::warn_cxx98_compat_ctor_list_init)
9129 ConstructorInitRequiresZeroInit,
9138 CurInit = cast<InitListExpr>(CurInit.
get())->getInit(0);
9167 bool IsStdInitListInit =
9171 ? Kind.getParenOrBraceRange()
9174 S, UseTemporary ? TempEntity : Entity, Kind,
9176 ConstructorInitRequiresZeroInit,
9187 if (NextStep != StepEnd &&
9192 ConstructorInitRequiresZeroInit =
true;
9195 !Kind.isImplicitValueInit()) {
9199 Kind.getRange().getBegin());
9203 Kind.getRange().getEnd());
9232 CurInit = CurInitExprRes;
9247 S.
Diag(Kind.getLocation(), diag::err_c23_constexpr_pointer_not_null);
9254 InitialCurInit.
get(),
9257 PrintInitLocationNote(S, Entity);
9259 }
else if (Complained)
9260 PrintInitLocationNote(S, Entity);
9276 CK_ObjCObjectLValueCast,
9288 BaseExpr, Kind.getLocation(), IndexExpr, Kind.getLocation());
9289 ArrayLoopCommonExprs.push_back(BaseExpr);
9294 assert(!ArrayLoopCommonExprs.empty() &&
9295 "mismatched SK_ArrayLoopIndex and SK_ArrayLoopInit");
9296 Expr *Common = ArrayLoopCommonExprs.pop_back_val();
9305 S.
Diag(Kind.getLocation(), diag::ext_array_init_copy)
9319 IncompleteDest->getElementType(), ConstantSource->getSize(),
9329 S.
Diag(Kind.getLocation(), diag::ext_array_init_parens)
9349 diag::warn_cxx98_compat_initializer_list_init)
9384 "Sampler initialization on non-sampler type.");
9390 S.
Diag(Kind.getLocation(), diag::err_sampler_argument_required)
9394 auto Var = cast<VarDecl>(DRE->getDecl());
9397 if (!Var->hasGlobalStorage()) {
9409 if (!Var->getInit() || !isa<ImplicitCastExpr>(Var->getInit()))
9411 Init = cast<ImplicitCastExpr>(
const_cast<Expr*
>(
9412 Var->getInit()))->getSubExpr();
9413 SourceType =
Init->getType();
9420 if (!
Init->isConstantInitializer(S.
Context,
false))
9425 S.
Diag(Kind.getLocation(), diag::err_sampler_initializer_not_integer)
9433 const uint64_t SamplerValue =
Result.getLimitedValue();
9440 unsigned AddressingMode = (0x0E & SamplerValue) >> 1;
9441 unsigned FilterMode = (0x30 & SamplerValue) >> 4;
9442 if (FilterMode != 1 && FilterMode != 2 &&
9444 "cl_intel_device_side_avc_motion_estimation", S.
getLangOpts()))
9445 S.
Diag(Kind.getLocation(),
9446 diag::warn_sampler_initializer_invalid_bits)
9448 if (AddressingMode > 4)
9449 S.
Diag(Kind.getLocation(),
9450 diag::warn_sampler_initializer_invalid_bits)
9451 <<
"Addressing Mode";
9457 CK_IntToOCLSampler);
9463 "Wrong type for initialization of OpenCL opaque type.");
9466 CK_ZeroToOCLOpaqueType,
9474 if (CurInit.
get() && ResultType)
9495 cast<FieldDecl>(Entity.
getDecl())->isBitField())
9496 S.CheckBitFieldInitialization(Kind.getLocation(),
9511 S.
Diag(Loc, diag::err_reference_without_init)
9520 for (
const auto *FI : RD->
fields()) {
9521 if (FI->isUnnamedBitfield())
9525 S.
Diag(Loc, diag::note_value_initialization_here) << RD;
9530 for (
const auto &BI : RD->
bases()) {
9532 S.
Diag(Loc, diag::note_value_initialization_here) << RD;
9567 if (fromDecl && destDecl && fromDecl->getDeclKind() == Decl::CXXRecord &&
9568 destDecl->getDeclKind() == Decl::CXXRecord &&
9569 !fromDecl->isInvalidDecl() && !destDecl->isInvalidDecl() &&
9570 !fromDecl->hasDefinition() &&
9573 S.
Diag(fromDecl->getLocation(), diag::note_forward_class_conversion)
9601 if (
auto *D = Entity.
getDecl())
9602 Loc = D->getLocation();
9603 S.
Diag(Loc, diag::note_in_reference_temporary_list_initializer) << T;
9607 InitListChecker DiagnoseInitList(S, Entity, InitList, DestType,
9610 assert(DiagnoseInitList.HadError() &&
9611 "Inconsistent init list check result.");
9624 if (Args.size() == 1) {
9625 auto *List = dyn_cast<InitListExpr>(Args[0]);
9626 if (List && List->getNumInits() == 1)
9627 OnlyArg = List->getInit(0);
9646 assert(Diagnosed &&
"couldn't find uninitialized reference to diagnose");
9649 S.
Diag(Kind.getLocation(), diag::err_reference_has_multiple_inits)
9650 <<
SourceRange(Args.front()->getBeginLoc(), Args.back()->getEndLoc());
9653 S.
Diag(Kind.getLocation(), diag::err_list_init_in_parens)
9654 << 1 << Entity.
getType() << Args[0]->getSourceRange();
9658 S.
Diag(Kind.getLocation(), diag::err_array_init_not_init_list) << 0;
9661 S.
Diag(Kind.getLocation(), diag::err_array_init_not_init_list) << 1;
9664 S.
Diag(Kind.getLocation(), diag::err_array_init_not_init_list) << 2;
9667 S.
Diag(Kind.getLocation(), diag::err_array_init_narrow_string_into_wchar);
9670 S.
Diag(Kind.getLocation(), diag::err_array_init_wide_string_into_char);
9673 S.
Diag(Kind.getLocation(),
9674 diag::err_array_init_incompat_wide_string_into_wchar);
9677 S.
Diag(Kind.getLocation(),
9678 diag::err_array_init_plain_string_into_char8_t);
9679 S.
Diag(Args.front()->getBeginLoc(),
9680 diag::note_array_init_plain_string_into_char8_t)
9684 S.
Diag(Kind.getLocation(), diag::err_array_init_utf8_string_into_char)
9689 S.
Diag(Kind.getLocation(),
9691 ? diag::err_array_init_different_type
9692 : diag::err_array_init_non_constant_array))
9695 << Args[0]->getSourceRange();
9699 S.
Diag(Kind.getLocation(), diag::err_variable_object_no_init)
9700 << Args[0]->getSourceRange();
9713 auto *FD = cast<FunctionDecl>(cast<DeclRefExpr>(OnlyArg)->getDecl());
9721 switch (FailedOverloadResult) {
9728 ? (S.
PDiag(diag::err_typecheck_ambiguous_condition)
9729 << OnlyArg->
getType() << DestType
9730 << Args[0]->getSourceRange())
9731 : (S.
PDiag(diag::err_ref_init_ambiguous)
9732 << DestType << OnlyArg->
getType()
9733 << Args[0]->getSourceRange())),
9741 diag::err_typecheck_nonviable_condition_incomplete,
9742 OnlyArg->
getType(), Args[0]->getSourceRange()))
9743 S.
Diag(Kind.getLocation(), diag::err_typecheck_nonviable_condition)
9745 << OnlyArg->
getType() << Args[0]->getSourceRange()
9752 S.
Diag(Kind.getLocation(), diag::err_typecheck_deleted_function)
9754 << Args[0]->getSourceRange();
9761 llvm_unreachable(
"Inconsistent overload resolution?");
9767 llvm_unreachable(
"Conversion did not fail!");
9772 if (isa<InitListExpr>(Args[0])) {
9773 S.
Diag(Kind.getLocation(),
9774 diag::err_lvalue_reference_bind_to_initlist)
9777 << Args[0]->getSourceRange();
9783 S.
Diag(Kind.getLocation(),
9785 ? diag::err_lvalue_reference_bind_to_temporary
9786 : diag::err_lvalue_reference_bind_to_unrelated)
9790 << Args[0]->getSourceRange();
9795 FieldDecl *BitField = Args[0]->getSourceBitField();
9796 S.
Diag(Kind.getLocation(), diag::err_reference_bind_to_bitfield)
9799 << (BitField !=
nullptr)
9800 << Args[0]->getSourceRange();
9807 S.
Diag(Kind.getLocation(), diag::err_reference_bind_to_vector_element)
9809 << Args[0]->getSourceRange();
9813 S.
Diag(Kind.getLocation(), diag::err_reference_bind_to_matrix_element)
9818 S.
Diag(Kind.getLocation(), diag::err_lvalue_to_rvalue_ref)
9820 << Args[0]->getSourceRange();
9824 S.
Diag(Kind.getLocation(), diag::err_reference_bind_temporary_addrspace)
9825 << DestType << Args[0]->getSourceRange();
9836 S.
Diag(Kind.getLocation(), diag::err_reference_bind_drops_quals)
9837 << NonRefType << SourceType << 1
9838 << Args[0]->getSourceRange();
9840 S.
Diag(Kind.getLocation(), diag::err_reference_bind_drops_quals)
9841 << NonRefType << SourceType << 0
9847 S.
Diag(Kind.getLocation(), diag::err_reference_bind_drops_quals)
9848 << NonRefType << SourceType << 2
9849 << Args[0]->getSourceRange();
9854 S.
Diag(Kind.getLocation(), diag::err_reference_bind_failed)
9859 << Args[0]->getSourceRange();
9870 << Args[0]->getSourceRange();
9872 S.
Diag(Kind.getLocation(), PDiag);
9884 auto *InitList = dyn_cast<InitListExpr>(Args[0]);
9885 if (InitList && InitList->getNumInits() >= 1) {
9886 R =
SourceRange(InitList->getInit(0)->getEndLoc(), InitList->getEndLoc());
9888 assert(Args.size() > 1 &&
"Expected multiple initializers!");
9889 R =
SourceRange(Args.front()->getEndLoc(), Args.back()->getEndLoc());
9893 if (Kind.isCStyleOrFunctionalCast())
9894 S.
Diag(Kind.getLocation(), diag::err_builtin_func_cast_more_than_one_arg)
9897 S.
Diag(Kind.getLocation(), diag::err_excess_initializers)
9903 S.
Diag(Kind.getLocation(), diag::err_list_init_in_parens)
9904 << 0 << Entity.
getType() << Args[0]->getSourceRange();
9908 S.
Diag(Kind.getLocation(), diag::err_reference_bind_init_list)
9913 S.
Diag(Kind.getLocation(), diag::err_init_list_bad_dest_type)
9914 << (DestType->
isRecordType()) << DestType << Args[0]->getSourceRange();
9922 SourceRange(Args.front()->getBeginLoc(), Args.back()->getEndLoc());
9925 assert(Args.size() == 1 &&
9926 "List construction from other than 1 argument.");
9933 switch (FailedOverloadResult) {
9937 S.
PDiag(diag::err_ovl_ambiguous_init)
9938 << DestType << ArgsRange),
9955 if (
auto Inherited = Constructor->getInheritedConstructor())
9956 InheritedFrom = Inherited.getShadowDecl()->getNominatedBaseClass();
9958 S.
Diag(Kind.getLocation(), diag::err_missing_default_ctor)
9959 << (InheritedFrom ? 2 : Constructor->isImplicit() ? 1 : 0)
9971 S.
Diag(Kind.getLocation(), diag::err_missing_default_ctor)
9972 << (InheritedFrom ? 2 : Constructor->isImplicit() ? 1 : 0)
9978 diag::note_member_declared_at);
9983 diag::note_previous_decl)
9992 S.
PDiag(diag::err_ovl_no_viable_function_in_init)
9993 << DestType << ArgsRange),
10002 S.
Diag(Kind.getLocation(), diag::err_ovl_deleted_init)
10003 << DestType << ArgsRange;
10004 llvm_unreachable(
"Inconsistent overload resolution?");
10012 S.
Diag(Kind.getLocation(), diag::err_ovl_deleted_special_init)
10014 << DestType << ArgsRange;
10016 S.
Diag(Kind.getLocation(), diag::err_ovl_deleted_init)
10017 << DestType << ArgsRange;
10024 llvm_unreachable(
"Conversion did not fail!");
10036 S.
Diag(Kind.getLocation(), diag::err_uninitialized_member_in_ctor)
10037 << (Constructor->getInheritedConstructor() ? 2 :
10038 Constructor->isImplicit() ? 1 : 0)
10044 }
else if (
const auto *VD = dyn_cast_if_present<VarDecl>(Entity.
getDecl());
10045 VD && VD->isConstexpr()) {
10046 S.
Diag(Kind.getLocation(), diag::err_constexpr_var_requires_const_init)
10049 S.
Diag(Kind.getLocation(), diag::err_default_init_const)
10056 diag::err_init_incomplete_type);
10072 S.
Diag(Kind.getLocation(), diag::err_selected_explicit_constructor)
10073 << Args[0]->getSourceRange();
10078 assert(Ovl ==
OR_Success &&
"Inconsistent overload resolution");
10081 diag::note_explicit_ctor_deduction_guide_here) <<
false;
10092 S.
Diag(Kind.getLocation(), diag::err_designated_init_for_non_aggregate)
10097 PrintInitLocationNote(S, Entity);
10104 OS <<
"Failed sequence: ";
10107 OS <<
"too many initializers for reference";
10111 OS <<
"parenthesized list init for reference";
10115 OS <<
"array requires initializer list";
10119 OS <<
"address of unaddressable function was taken";
10123 OS <<
"array requires initializer list or string literal";
10127 OS <<
"array requires initializer list or wide string literal";
10131 OS <<
"narrow string into wide char array";
10135 OS <<
"wide string into char array";
10139 OS <<
"incompatible wide string into wide char array";
10143 OS <<
"plain string literal into char8_t array";
10147 OS <<
"u8 string literal into char array";
10151 OS <<
"array type mismatch";
10155 OS <<
"non-constant array initializer";
10159 OS <<
"address of overloaded function failed";
10163 OS <<
"overload resolution for reference initialization failed";
10167 OS <<
"non-const lvalue reference bound to temporary";
10171 OS <<
"non-const lvalue reference bound to bit-field";
10175 OS <<
"non-const lvalue reference bound to vector element";
10179 OS <<
"non-const lvalue reference bound to matrix element";
10183 OS <<
"non-const lvalue reference bound to unrelated type";
10187 OS <<
"rvalue reference bound to an lvalue";
10191 OS <<
"reference initialization drops qualifiers";
10195 OS <<
"reference with mismatching address space bound to temporary";
10199 OS <<
"reference initialization failed";
10203 OS <<
"conversion failed";
10207 OS <<
"conversion from property failed";
10211 OS <<
"too many initializers for scalar";
10215 OS <<
"parenthesized list init for reference";
10219 OS <<
"referencing binding to initializer list";
10223 OS <<
"initializer list for non-aggregate, non-scalar type";
10227 OS <<
"overloading failed for user-defined conversion";
10231 OS <<
"constructor overloading failed";
10235 OS <<
"default initialization of a const variable";
10239 OS <<
"initialization of incomplete type";
10243 OS <<
"list initialization checker failure";
10247 OS <<
"variable length array has an initializer";
10251 OS <<
"initializer expression isn't contextually valid";
10255 OS <<
"list constructor overloading failed";
10259 OS <<
"list copy initialization chose explicit constructor";
10263 OS <<
"parenthesized list initialization failed";
10267 OS <<
"designated initializer for non-aggregate type";
10275 OS <<
"Dependent sequence\n";
10279 OS <<
"Normal sequence: ";
10290 OS <<
"resolve address of overloaded function";
10294 OS <<
"derived-to-base (prvalue)";
10298 OS <<
"derived-to-base (xvalue)";
10302 OS <<
"derived-to-base (lvalue)";
10306 OS <<
"bind reference to lvalue";
10310 OS <<
"bind reference to a temporary";
10314 OS <<
"final copy in class direct-initialization";
10318 OS <<
"extraneous C++03 copy to temporary";
10322 OS <<
"user-defined conversion via " << *S->Function.Function;
10326 OS <<
"qualification conversion (prvalue)";
10330 OS <<
"qualification conversion (xvalue)";
10334 OS <<
"qualification conversion (lvalue)";
10338 OS <<
"function reference conversion";
10342 OS <<
"non-atomic-to-atomic conversion";
10346 OS <<
"implicit conversion sequence (";
10352 OS <<
"implicit conversion sequence with narrowing prohibited (";
10358 OS <<
"list aggregate initialization";
10362 OS <<
"unwrap reference initializer list";
10366 OS <<
"rewrap reference initializer list";
10370 OS <<
"constructor initialization";
10374 OS <<
"list initialization via constructor";
10378 OS <<
"zero initialization";
10382 OS <<
"C assignment";
10386 OS <<
"string initialization";
10390 OS <<
"Objective-C object conversion";
10394 OS <<
"indexing for array initialization loop";
10398 OS <<
"array initialization loop";
10402 OS <<
"array initialization";
10406 OS <<
"array initialization (GNU extension)";
10410 OS <<
"parenthesized array initialization";
10414 OS <<
"pass by indirect copy and restore";
10418 OS <<
"pass by indirect restore";
10422 OS <<
"Objective-C object retension";
10426 OS <<
"std::initializer_list from initializer list";
10430 OS <<
"list initialization from std::initializer_list";
10434 OS <<
"OpenCL sampler_t from integer constant";
10438 OS <<
"OpenCL opaque type from zero";
10441 OS <<
"initialization from a parenthesized list of values";
10445 OS <<
" [" << S->Type <<
']';
10452 dump(llvm::errs());
10459 const Expr *PostInit) {
10475 auto MakeDiag = [&](
bool IsConstRef,
unsigned DefaultDiagID,
10476 unsigned ConstRefDiagID,
unsigned WarnDiagID) {
10479 if (L.CPlusPlus11 &&
10481 DiagID = IsConstRef ? ConstRefDiagID : DefaultDiagID;
10483 DiagID = WarnDiagID;
10503 MakeDiag(T != EntityType, diag::ext_init_list_type_narrowing,
10504 diag::ext_init_list_type_narrowing_const_reference,
10505 diag::warn_init_list_type_narrowing)
10514 diag::ext_init_list_constant_narrowing,
10515 diag::ext_init_list_constant_narrowing_const_reference,
10516 diag::warn_init_list_constant_narrowing)
10525 diag::ext_init_list_variable_narrowing,
10526 diag::ext_init_list_variable_narrowing_const_reference,
10527 diag::warn_init_list_variable_narrowing)
10535 llvm::raw_svector_ostream OS(StaticCast);
10536 OS <<
"static_cast<";
10543 OS << *TT->getDecl();
10552 S.
Diag(PostInit->
getBeginLoc(), diag::note_init_list_narrowing_silence)
10563 Init->IgnoreParenImpCasts(), ToType,
false,
10564 Sema::AllowedExplicit::None,
10580 S.
Diag(
Init->getBeginLoc(), diag::err_c23_constexpr_init_not_representable)
10581 <<
Value.getAsString(S.
Context, PreNarrowingType) << ToType;
10586 S.
Diag(
Init->getBeginLoc(), diag::err_c23_constexpr_init_type_mismatch)
10587 << ToType << FromType;
10597 llvm_unreachable(
"unhandled case in switch");
10609 for (
unsigned I = 0, N = SE->
getLength(); I != N; ++I) {
10614 diag::err_c23_constexpr_init_not_representable)
10628 if (
Init.isInvalid())
10632 assert(InitE &&
"No initialization expression");
10637 return !
Seq.Failed();
10644 bool TopLevelOfInitList,
10645 bool AllowExplicit) {
10646 if (
Init.isInvalid())
10650 assert(InitE &&
"No initialization expression?");
10660 const bool ShouldTrackCopy =
10662 if (ShouldTrackCopy) {
10664 Seq.SetOverloadFailure(
10670 const auto LastStep =
Seq.step_end() - 1;
10671 assert(LastStep->Kind ==
10675 llvm::find_if(
Seq.getFailedCandidateSet(),
10677 return Candidate.Viable &&
10678 Candidate.Function == Function &&
10679 Candidate.Conversions.size() > 0;
10681 if (Candidate !=
Seq.getFailedCandidateSet().end() &&
10683 Candidate->
Viable =
false;
10687 Function->getParamDecl(0)->getType());
10695 if (ShouldTrackCopy)
10704 auto NotSpecialization = [&] (
const CXXRecordDecl *Candidate) {
10705 auto *CTSD = dyn_cast<ClassTemplateSpecializationDecl>(Candidate);
10708 return !(NotSpecialization(RD) && RD->
forallBases(NotSpecialization));
10714 auto *DeducedTST = dyn_cast<DeducedTemplateSpecializationType>(
10716 assert(DeducedTST &&
"not a deduced template specialization type");
10727 if (
auto *
AliasTemplate = dyn_cast_or_null<TypeAliasTemplateDecl>(
10729 Diag(Kind.getLocation(),
10730 diag::warn_cxx17_compat_ctad_for_alias_templates);
10733 ->getUnderlyingType()
10734 .getCanonicalType();
10738 if (
const auto *TST =
10740 Template = dyn_cast_or_null<ClassTemplateDecl>(
10741 TST->getTemplateName().getAsTemplateDecl());
10742 }
else if (
const auto *RT = UnderlyingType->getAs<
RecordType>()) {
10746 if (
const auto *CTSD = llvm::dyn_cast<ClassTemplateSpecializationDecl>(
10747 RT->getAsCXXRecordDecl()))
10748 Template = CTSD->getSpecializedTemplate();
10753 Diag(Kind.getLocation(),
10754 diag::err_deduced_non_class_or_alias_template_specialization_type)
10764 diag::warn_cxx14_compat_class_template_argument_deduction)
10794 ? dyn_cast<InitListExpr>(Inits[0])
10810 bool AllowExplicit = !Kind.isCopyInit() ||
ListInit;
10816 bool OnlyListConstructors,
10817 bool AllowAggregateDeductionCandidate) {
10823 if (!AllowExplicit) {
10830 if (GD->getMinRequiredArguments() > 1 ||
10831 (GD->getNumParams() == 0 && !GD->isVariadic()))
10841 if (!AllowAggregateDeductionCandidate &&
10857 bool SuppressUserConversions = Kind.isCopyInit();
10861 for (
Expr *E : Inits)
10862 if (
auto *DI = dyn_cast<DesignatedInitExpr>(E))
10863 TmpInits.push_back(DI->getInit());
10865 TmpInits.push_back(E);
10867 TD, FoundDecl,
nullptr, TmpInits, Candidates,
10868 SuppressUserConversions,
10869 false, AllowExplicit, ADLCallKind::NotADL,
10870 {}, AllowAggregateDeductionCandidate);
10873 SuppressUserConversions,
10874 false, AllowExplicit);
10878 bool FoundDeductionGuide =
false;
10880 auto TryToResolveOverload =
10883 bool HasAnyDeductionGuide =
false;
10886 auto *Pattern = Template;
10887 while (Pattern->getInstantiatedFromMemberTemplate()) {
10888 if (Pattern->isMemberSpecialization())
10890 Pattern = Pattern->getInstantiatedFromMemberTemplate();
10893 auto *RD = cast<CXXRecordDecl>(Pattern->getTemplatedDecl());
10899 InitListChecker CheckInitList(*
this, Entity,
ListInit, Ty, ElementTypes);
10900 if (!CheckInitList.HadError()) {
10909 for (
int I = 0, E =
ListInit->getNumInits();
10910 I < E && !isa<PackExpansionType>(ElementTypes[I]); ++I)
10911 if (ElementTypes[I]->isArrayType()) {
10912 if (isa<InitListExpr>(
ListInit->getInit(I)))
10914 else if (isa<StringLiteral>(
10915 ListInit->getInit(I)->IgnoreParenImpCasts()))
10920 llvm::FoldingSetNodeID ID;
10921 ID.AddPointer(Template);
10922 for (
auto &T : ElementTypes)
10923 T.getCanonicalType().
Profile(ID);
10924 unsigned Hash = ID.ComputeHash();
10928 Template, ElementTypes,
10934 OnlyListConstructors,
10940 assert(TD &&
"aggregate deduction candidate is function template");
10942 OnlyListConstructors,
10945 HasAnyDeductionGuide =
true;
10949 for (
auto I = Guides.
begin(), E = Guides.
end(); I != E; ++I) {
10950 NamedDecl *D = (*I)->getUnderlyingDecl();
10954 auto *TD = dyn_cast<FunctionTemplateDecl>(D);
10955 auto *GD = dyn_cast_if_present<CXXDeductionGuideDecl>(
10960 if (!GD->isImplicit())
10961 HasAnyDeductionGuide =
true;
10963 addDeductionCandidate(TD, GD, I.getPair(), OnlyListConstructors,
10978 }
else if (Inits.size()) {
10983 Inits, Inits.back()->getEndLoc());
10984 SynthesizeAggrGuide(&TempListInit);
10988 FoundDeductionGuide = FoundDeductionGuide || HasAnyDeductionGuide;
10998 bool TryListConstructors =
true;
11004 auto *FD = dyn_cast<FunctionDecl>(D->getUnderlyingDecl());
11005 if (FD && FD->getMinRequiredArguments() == 0) {
11006 TryListConstructors =
false;
11010 }
else if (
ListInit->getNumInits() == 1) {
11018 if (!isa<InitListExpr>(E) && RD &&
11021 TryListConstructors =
false;
11024 if (TryListConstructors)
11025 Result = TryToResolveOverload(
true);
11034 Result = TryToResolveOverload(
false);
11043 Kind.getLocation(),
11044 PDiag(diag::err_deduced_class_template_ctor_ambiguous)
11051 cast<ClassTemplateDecl>(Template)->getTemplatedDecl();
11056 Kind.getLocation(),
11057 PDiag(
Complete ? diag::err_deduced_class_template_ctor_no_viable
11058 : diag::err_deduced_class_template_incomplete)
11065 Diag(Kind.getLocation(), diag::err_deduced_class_template_deleted)
11075 if (Kind.isCopyInit() &&
ListInit &&
11076 cast<CXXDeductionGuideDecl>(Best->Function)->isExplicit()) {
11077 bool IsDeductionGuide = !Best->Function->isImplicit();
11078 Diag(Kind.getLocation(), diag::err_deduced_class_template_explicit)
11080 Diag(Best->Function->getLocation(),
11081 diag::note_explicit_ctor_deduction_guide_here)
11082 << IsDeductionGuide;
11099 diag::warn_cxx14_compat_class_template_argument_deduction)
11104 if (!FoundDeductionGuide) {
11106 diag::warn_ctad_maybe_unsupported)
11108 Diag(Template->getLocation(), diag::note_suppress_ctad_maybe_unsupported);
Defines the clang::ASTContext interface.
static bool isUnsigned(SValBuilder &SVB, NonLoc Value)
static bool isRValueRef(QualType ParamType)
Defines the clang::Expr interface and subclasses for C++ expressions.
static DiagnosticBuilder Diag(DiagnosticsEngine *Diags, const LangOptions &Features, FullSourceLoc TokLoc, const char *TokBegin, const char *TokRangeBegin, const char *TokRangeEnd, unsigned DiagID)
Produce a diagnostic highlighting some portion of a literal.
llvm::MachO::Record Record
static std::string toString(const clang::SanitizerSet &Sanitizers)
Produce a string containing comma-separated names of sanitizers in Sanitizers set.
static void CheckForNullPointerDereference(Sema &S, Expr *E)
static bool implicitObjectParamIsLifetimeBound(const FunctionDecl *FD)
static bool isExprAnUnaddressableFunction(Sema &S, const Expr *E)
Tries to get a FunctionDecl out of E.
static bool shouldTrackImplicitObjectArg(const CXXMethodDecl *Callee)
static void updateStringLiteralType(Expr *E, QualType Ty)
Update the type of a string literal, including any surrounding parentheses, to match the type of the ...
static void updateGNUCompoundLiteralRValue(Expr *E)
Fix a compound literal initializing an array so it's correctly marked as an rvalue.
static bool initializingConstexprVariable(const InitializedEntity &Entity)
static void visitLifetimeBoundArguments(IndirectLocalPath &Path, Expr *Call, LocalVisitor Visit)
static void warnBracedScalarInit(Sema &S, const InitializedEntity &Entity, SourceRange Braces)
Warn that Entity was of scalar type and was initialized by a single-element braced initializer list.
static bool shouldDestroyEntity(const InitializedEntity &Entity)
Whether the given entity, when initialized with an object created for that initialization,...
static SourceLocation getInitializationLoc(const InitializedEntity &Entity, Expr *Initializer)
Get the location at which initialization diagnostics should appear.
static bool hasAnyDesignatedInits(const InitListExpr *IL)
static bool tryObjCWritebackConversion(Sema &S, InitializationSequence &Sequence, const InitializedEntity &Entity, Expr *Initializer)
static DesignatedInitExpr * CloneDesignatedInitExpr(Sema &SemaRef, DesignatedInitExpr *DIE)
static ExprResult CopyObject(Sema &S, QualType T, const InitializedEntity &Entity, ExprResult CurInit, bool IsExtraneousCopy)
Make a (potentially elidable) temporary copy of the object provided by the given initializer by calli...
static Sema::AssignmentAction getAssignmentAction(const InitializedEntity &Entity, bool Diagnose=false)
static void TryOrBuildParenListInitialization(Sema &S, const InitializedEntity &Entity, const InitializationKind &Kind, ArrayRef< Expr * > Args, InitializationSequence &Sequence, bool VerifyOnly, ExprResult *Result=nullptr)
static void CheckMoveOnConstruction(Sema &S, const Expr *InitExpr, bool IsReturnStmt)
Provide warnings when std::move is used on construction.
static void CheckC23ConstexprInitStringLiteral(const StringLiteral *SE, Sema &SemaRef, QualType &TT)
static void CheckCXX98CompatAccessibleCopy(Sema &S, const InitializedEntity &Entity, Expr *CurInitExpr)
Check whether elidable copy construction for binding a reference to a temporary would have succeeded ...
static bool isOrIsDerivedFromSpecializationOf(CXXRecordDecl *RD, ClassTemplateDecl *CTD)
Determine whether RD is, or is derived from, a specialization of CTD.
static bool TryInitializerListConstruction(Sema &S, InitListExpr *List, QualType DestType, InitializationSequence &Sequence, bool TreatUnavailableAsInvalid)
When initializing from init list via constructor, handle initialization of an object of type std::ini...
static StringInitFailureKind IsStringInit(Expr *Init, const ArrayType *AT, ASTContext &Context)
Check whether the array of type AT can be initialized by the Init expression by means of string initi...
@ SIF_PlainStringIntoUTF8Char
@ SIF_IncompatWideStringIntoWideChar
@ SIF_UTF8StringIntoPlainChar
@ SIF_NarrowStringIntoWideChar
static void handleGslAnnotatedTypes(IndirectLocalPath &Path, Expr *Call, LocalVisitor Visit)
static void TryDefaultInitialization(Sema &S, const InitializedEntity &Entity, const InitializationKind &Kind, InitializationSequence &Sequence)
Attempt default initialization (C++ [dcl.init]p6).
static bool TryOCLSamplerInitialization(Sema &S, InitializationSequence &Sequence, QualType DestType, Expr *Initializer)
static bool pathOnlyInitializesGslPointer(IndirectLocalPath &Path)
static bool isInStlNamespace(const Decl *D)
static bool maybeRecoverWithZeroInitialization(Sema &S, InitializationSequence &Sequence, const InitializedEntity &Entity)
Tries to add a zero initializer. Returns true if that worked.
static ExprResult CheckArrayDesignatorExpr(Sema &S, Expr *Index, llvm::APSInt &Value)
Check that the given Index expression is a valid array designator value.
static bool canPerformArrayCopy(const InitializedEntity &Entity)
Determine whether we can perform an elementwise array copy for this kind of entity.
static bool IsZeroInitializer(Expr *Initializer, Sema &S)
static void TryReferenceInitializationCore(Sema &S, const InitializedEntity &Entity, const InitializationKind &Kind, Expr *Initializer, QualType cv1T1, QualType T1, Qualifiers T1Quals, QualType cv2T2, QualType T2, Qualifiers T2Quals, InitializationSequence &Sequence, bool TopLevelOfInitList)
Reference initialization without resolving overloaded functions.
static PathLifetimeKind shouldLifetimeExtendThroughPath(const IndirectLocalPath &Path)
Determine whether this is an indirect path to a temporary that we are supposed to lifetime-extend alo...
static void CheckC23ConstexprInitConversion(Sema &S, QualType FromType, QualType ToType, Expr *Init)
static void ExpandAnonymousFieldDesignator(Sema &SemaRef, DesignatedInitExpr *DIE, unsigned DesigIdx, IndirectFieldDecl *IndirectField)
Expand a field designator that refers to a member of an anonymous struct or union into a series of fi...
static void TryValueInitialization(Sema &S, const InitializedEntity &Entity, const InitializationKind &Kind, InitializationSequence &Sequence, InitListExpr *InitList=nullptr)
Attempt value initialization (C++ [dcl.init]p7).
static void TryUserDefinedConversion(Sema &S, QualType DestType, const InitializationKind &Kind, Expr *Initializer, InitializationSequence &Sequence, bool TopLevelOfInitList)
Attempt a user-defined conversion between two types (C++ [dcl.init]), which enumerates all conversion...
static OverloadingResult ResolveConstructorOverload(Sema &S, SourceLocation DeclLoc, MultiExprArg Args, OverloadCandidateSet &CandidateSet, QualType DestType, DeclContext::lookup_result Ctors, OverloadCandidateSet::iterator &Best, bool CopyInitializing, bool AllowExplicit, bool OnlyListConstructors, bool IsListInit, bool RequireActualConstructor, bool SecondStepOfCopyInit=false)
static LifetimeResult getEntityLifetime(const InitializedEntity *Entity, const InitializedEntity *InitField=nullptr)
Determine the declaration which an initialized entity ultimately refers to, for the purpose of lifeti...
static bool isVarOnPath(IndirectLocalPath &Path, VarDecl *VD)
static bool shouldTrackFirstArgument(const FunctionDecl *FD)
static void TryListInitialization(Sema &S, const InitializedEntity &Entity, const InitializationKind &Kind, InitListExpr *InitList, InitializationSequence &Sequence, bool TreatUnavailableAsInvalid)
Attempt list initialization (C++0x [dcl.init.list])
static void TryStringLiteralInitialization(Sema &S, const InitializedEntity &Entity, const InitializationKind &Kind, Expr *Initializer, InitializationSequence &Sequence)
Attempt character array initialization from a string literal (C++ [dcl.init.string],...
static bool checkDestructorReference(QualType ElementType, SourceLocation Loc, Sema &SemaRef)
Check if the type of a class element has an accessible destructor, and marks it referenced.
static void TryReferenceInitialization(Sema &S, const InitializedEntity &Entity, const InitializationKind &Kind, Expr *Initializer, InitializationSequence &Sequence, bool TopLevelOfInitList)
Attempt reference initialization (C++0x [dcl.init.ref])
static void DiagnoseNarrowingInInitList(Sema &S, const ImplicitConversionSequence &ICS, QualType PreNarrowingType, QualType EntityType, const Expr *PostInit)
static bool hasCompatibleArrayTypes(ASTContext &Context, const ArrayType *Dest, const ArrayType *Source)
Determine whether we have compatible array types for the purposes of GNU by-copy array initialization...
static bool pathContainsInit(IndirectLocalPath &Path)
static void CheckStringInit(Expr *Str, QualType &DeclT, const ArrayType *AT, Sema &S, bool CheckC23ConstexprInit=false)
static bool isRecordWithAttr(QualType Type)
static bool isExplicitTemporary(const InitializedEntity &Entity, const InitializationKind &Kind, unsigned NumArgs)
Returns true if the parameters describe a constructor initialization of an explicit temporary object,...
static bool isNonReferenceableGLValue(Expr *E)
Determine whether an expression is a non-referenceable glvalue (one to which a reference can never bi...
PathLifetimeKind
Whether a path to an object supports lifetime extension.
@ ShouldExtend
We should lifetime-extend, but we don't because (due to technical limitations) we can't.
@ NoExtend
Do not lifetime extend along this path.
@ Extend
Lifetime-extend along this path.
static bool TryOCLZeroOpaqueTypeInitialization(Sema &S, InitializationSequence &Sequence, QualType DestType, Expr *Initializer)
static bool IsWideCharCompatible(QualType T, ASTContext &Context)
Check whether T is compatible with a wide character type (wchar_t, char16_t or char32_t).
static void diagnoseListInit(Sema &S, const InitializedEntity &Entity, InitListExpr *InitList)
static OverloadingResult TryRefInitWithConversionFunction(Sema &S, const InitializedEntity &Entity, const InitializationKind &Kind, Expr *Initializer, bool AllowRValues, bool IsLValueRef, InitializationSequence &Sequence)
Try a reference initialization that involves calling a conversion function.
static void TryConstructorInitialization(Sema &S, const InitializedEntity &Entity, const InitializationKind &Kind, MultiExprArg Args, QualType DestType, QualType DestArrayType, InitializationSequence &Sequence, bool IsListInit=false, bool IsInitListCopy=false)
Attempt initialization by constructor (C++ [dcl.init]), which enumerates the constructors of the init...
static void emitBadConversionNotes(Sema &S, const InitializedEntity &entity, Expr *op)
Emit notes associated with an initialization that failed due to a "simple" conversion failure.
static bool isIdiomaticBraceElisionEntity(const InitializedEntity &Entity)
Determine whether Entity is an entity for which it is idiomatic to elide the braces in aggregate init...
static void MaybeProduceObjCObject(Sema &S, InitializationSequence &Sequence, const InitializedEntity &Entity)
static SourceRange nextPathEntryRange(const IndirectLocalPath &Path, unsigned I, Expr *E)
Find the range for the first interesting entry in the path at or after I.
static void checkIndirectCopyRestoreSource(Sema &S, Expr *src)
Check whether the given expression is a valid operand for an indirect copy/restore.
static bool shouldBindAsTemporary(const InitializedEntity &Entity)
Whether we should bind a created object as a temporary when initializing the given entity.
static void visitLocalsRetainedByReferenceBinding(IndirectLocalPath &Path, Expr *Init, ReferenceKind RK, LocalVisitor Visit, bool EnableLifetimeWarnings)
Visit the locals that would be reachable through a reference bound to the glvalue expression Init.
static bool ResolveOverloadedFunctionForReferenceBinding(Sema &S, Expr *Initializer, QualType &SourceType, QualType &UnqualifiedSourceType, QualType UnqualifiedTargetType, InitializationSequence &Sequence)
static void visitLocalsRetainedByInitializer(IndirectLocalPath &Path, Expr *Init, LocalVisitor Visit, bool RevisitSubinits, bool EnableLifetimeWarnings)
Visit the locals that would be reachable through an object initialized by the prvalue expression Init...
InvalidICRKind
The non-zero enum values here are indexes into diagnostic alternatives.
static ExprResult PerformConstructorInitialization(Sema &S, const InitializedEntity &Entity, const InitializationKind &Kind, MultiExprArg Args, const InitializationSequence::Step &Step, bool &ConstructorInitRequiresZeroInit, bool IsListInitialization, bool IsStdInitListInitialization, SourceLocation LBraceLoc, SourceLocation RBraceLoc)
static void TryReferenceListInitialization(Sema &S, const InitializedEntity &Entity, const InitializationKind &Kind, InitListExpr *InitList, InitializationSequence &Sequence, bool TreatUnavailableAsInvalid)
Attempt list initialization of a reference.
static bool isLibstdcxxPointerReturnFalseHack(Sema &S, const InitializedEntity &Entity, const Expr *Init)
An egregious hack for compatibility with libstdc++-4.2: in <tr1/hashtable>, a function with a pointer...
static bool hasCopyOrMoveCtorParam(ASTContext &Ctx, const ConstructorInfo &Info)
Determine if the constructor has the signature of a copy or move constructor for the type T of the cl...
static bool DiagnoseUninitializedReference(Sema &S, SourceLocation Loc, QualType T)
Somewhere within T there is an uninitialized reference subobject.
static InvalidICRKind isInvalidICRSource(ASTContext &C, Expr *e, bool isAddressOf, bool &isWeakAccess)
Determines whether this expression is an acceptable ICR source.
Defines the SourceManager interface.
Defines various enumerations that describe declaration and type specifiers.
Defines the clang::TypeLoc interface and its subclasses.
__device__ __2f16 float __ockl_bool s
APValue - This class implements a discriminated union of [uninitialized] [APSInt] [APFloat],...
std::string getAsString(const ASTContext &Ctx, QualType Ty) const
bool isNullPointer() const
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
const ConstantArrayType * getAsConstantArrayType(QualType T) const
QualType getRValueReferenceType(QualType T) const
Return the uniqued reference to the type for an rvalue reference to the specified type.
unsigned getIntWidth(QualType T) const
QualType getTagDeclType(const TagDecl *Decl) const
Return the unique reference to the type for the specified TagDecl (struct/union/class/enum) decl.
DeclarationNameTable DeclarationNames
QualType getRecordType(const RecordDecl *Decl) const
void getObjCEncodingForType(QualType T, std::string &S, const FieldDecl *Field=nullptr, QualType *NotEncodedT=nullptr) const
Emit the Objective-CC type encoding for the given type T into S.
QualType getPackExpansionType(QualType Pattern, std::optional< unsigned > NumExpansions, bool ExpectPackInType=true)
Form a pack expansion type with the given pattern.
CanQualType getCanonicalType(QualType T) const
Return the canonical (structural) type corresponding to the specified potentially non-canonical type ...
bool hasSameType(QualType T1, QualType T2) const
Determine whether the given types T1 and T2 are equivalent.
QualType getVectorType(QualType VectorType, unsigned NumElts, VectorKind VecKind) const
Return the unique reference to a vector type of the specified element type and size.
QualType getPointerType(QualType T) const
Return the uniqued reference to the type for a pointer to the specified type.
const IncompleteArrayType * getAsIncompleteArrayType(QualType T) const
QualType getLValueReferenceType(QualType T, bool SpelledAsLValue=true) const
Return the uniqued reference to the type for an lvalue reference to the specified type.
QualType getTypeDeclType(const TypeDecl *Decl, const TypeDecl *PrevDecl=nullptr) const
Return the unique reference to the type for the specified type declaration.
QualType getConstantArrayType(QualType EltTy, const llvm::APInt &ArySize, const Expr *SizeExpr, ArraySizeModifier ASM, unsigned IndexTypeQuals) const
Return the unique reference to the type for a constant array of the specified element type.
const LangOptions & getLangOpts() const
QualType getBaseElementType(const ArrayType *VAT) const
Return the innermost element type of an array type.
TypeSourceInfo * getTrivialTypeSourceInfo(QualType T, SourceLocation Loc=SourceLocation()) const
Allocate a TypeSourceInfo where all locations have been initialized to a given location,...
CanQualType getSizeType() const
Return the unique type for "size_t" (C99 7.17), defined in <stddef.h>.
QualType getQualifiedType(SplitQualType split) const
Un-split a SplitQualType.
QualType getUnqualifiedArrayType(QualType T, Qualifiers &Quals)
Return this type as a completely-unqualified array type, capturing the qualifiers in Quals.
QualType getDependentSizedArrayType(QualType EltTy, Expr *NumElts, ArraySizeModifier ASM, unsigned IndexTypeQuals, SourceRange Brackets) const
Return a non-unique reference to the type for a dependently-sized array of the specified element type...
bool hasSameUnqualifiedType(QualType T1, QualType T2) const
Determine whether the given types are equivalent after cvr-qualifiers have been removed.
const ArrayType * getAsArrayType(QualType T) const
Type Query functions.
uint64_t getTypeSize(QualType T) const
Return the size of the specified (complete) type T, in bits.
QualType getPromotedIntegerType(QualType PromotableType) const
Return the type that PromotableType will promote to: C99 6.3.1.1p2, assuming that PromotableType is a...
const VariableArrayType * getAsVariableArrayType(QualType T) const
QualType getExtVectorType(QualType VectorType, unsigned NumElts) const
Return the unique reference to an extended vector type of the specified element type and size.
const TargetInfo & getTargetInfo() const
bool typesAreCompatible(QualType T1, QualType T2, bool CompareUnqualified=false)
Compatibility predicates used to check assignment expressions.
QualType getWideCharType() const
Return the type of wide characters.
bool isPromotableIntegerType(QualType T) const
More type predicates useful for type checking/promotion.
uint64_t getCharWidth() const
Return the size of the character type, in bits.
Represents the index of the current element of an array being initialized by an ArrayInitLoopExpr.
Represents a loop initializing the elements of an array.
ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting.
Represents an array type, per C99 6.7.5.2 - Array Declarators.
QualType getElementType() const
Type source information for an attributed type.
TypeLoc getModifiedLoc() const
The modified type, which is generally canonically different from the attribute type.
This class is used for builtin types like 'int'.
Represents a base class of a C++ class.
bool isVirtual() const
Determines whether the base class is a virtual base class (or not).
QualType getType() const
Retrieves the type of the base class.
Represents binding an expression to a temporary.
Represents a call to a C++ constructor.
Expr * getArg(unsigned Arg)
Return the specified argument.
CXXConstructorDecl * getConstructor() const
Get the constructor that this expression will (ultimately) call.
unsigned getNumArgs() const
Return the number of arguments to the constructor call.
Represents a C++ constructor within a class.
CXXConstructorDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
bool isExplicit() const
Return true if the declaration is already resolved to be explicit.
bool isCopyOrMoveConstructor(unsigned &TypeQuals) const
Determine whether this is a copy or move constructor.
Represents a C++ conversion function within a class.
QualType getConversionType() const
Returns the type that this conversion function is converting to.
Represents a C++ deduction guide declaration.
Represents a C++ destructor within a class.
Represents a static or instance method of a struct/union/class.
const CXXRecordDecl * getParent() const
Return the parent of this method declaration, which is the class in which this method is defined.
static CXXParenListInitExpr * Create(ASTContext &C, ArrayRef< Expr * > Args, QualType T, unsigned NumUserSpecifiedExprs, SourceLocation InitLoc, SourceLocation LParenLoc, SourceLocation RParenLoc)
Represents a C++ struct/union/class.
bool hasUninitializedReferenceMember() const
Whether this class or any of its subobjects has any members of reference type which would make value-...
bool allowConstDefaultInit() const
Determine whether declaring a const variable with this type is ok per core issue 253.
llvm::iterator_range< conversion_iterator > getVisibleConversionFunctions() const
Get all conversion functions visible in current class, including conversion function templates.
unsigned getNumBases() const
Retrieves the number of base classes of this class.
llvm::iterator_range< base_class_iterator > base_class_range
llvm::iterator_range< base_class_const_iterator > base_class_const_range
bool forallBases(ForallBasesCallback BaseMatches) const
Determines if the given callback holds for all the direct or indirect base classes of this type.
An expression "T()" which creates a value-initialized rvalue of type T, which is a non-class type.
Implicit construction of a std::initializer_list<T> object from an array temporary within list-initia...
static CXXTemporaryObjectExpr * Create(const ASTContext &Ctx, CXXConstructorDecl *Cons, QualType Ty, TypeSourceInfo *TSI, ArrayRef< Expr * > Args, SourceRange ParenOrBraceRange, bool HadMultipleCandidates, bool ListInitialization, bool StdInitListInitialization, bool ZeroInitialization)
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
Expr * getArg(unsigned Arg)
getArg - Return the specified argument.
SourceLocation getBeginLoc() const LLVM_READONLY
bool isCallToStdMove() const
SourceLocation getRParenLoc() const
CanQual< T > getUnqualifiedType() const
Retrieve the unqualified form of this type.
CastExpr - Base class for type casts, including both implicit casts (ImplicitCastExpr) and explicit c...
SourceLocation getBegin() const
Declaration of a class template.
void setExprNeedsCleanups(bool SideEffects)
Complex values, per C99 6.2.5p11.
QualType getElementType() const
ConditionalOperator - The ?: ternary operator.
Represents the canonical version of C arrays with a specified constant size.
static unsigned getMaxSizeBits(const ASTContext &Context)
Determine the maximum number of active bits that an array's size can require, which limits the maximu...
uint64_t getZExtSize() const
Return the size zero-extended as a uint64_t.
Base class for callback objects used by Sema::CorrectTypo to check the validity of a potential typo c...
virtual bool ValidateCandidate(const TypoCorrection &candidate)
Simple predicate used by the default RankCandidate to determine whether to return an edit distance of...
virtual std::unique_ptr< CorrectionCandidateCallback > clone()=0
Clone this CorrectionCandidateCallback.
A POD class for pairing a NamedDecl* with an access specifier.
static DeclAccessPair make(NamedDecl *D, AccessSpecifier AS)
NamedDecl * getDecl() const
The results of name lookup within a DeclContext.
decl_iterator - Iterates through the declarations stored within this context.
specific_decl_iterator - Iterates over a subrange of declarations stored in a DeclContext,...
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
DeclContext * getParent()
getParent - Returns the containing DeclContext.
bool Equals(const DeclContext *DC) const
Determine whether this declaration context is equivalent to the declaration context DC.
bool InEnclosingNamespaceSetOf(const DeclContext *NS) const
Test if this context is part of the enclosing namespace set of the context NS, as defined in C++0x [n...
lookup_result lookup(DeclarationName Name) const
lookup - Find the declarations (if any) with the given Name in this context.
DeclContext * getRedeclContext()
getRedeclContext - Retrieve the context in which an entity conflicts with other entities of the same ...
bool isStdNamespace() const
decl_range decls() const
decls_begin/decls_end - Iterate over the declarations stored in this context.
A reference to a declared variable, function, enum, etc.
bool refersToEnclosingVariableOrCapture() const
Does this DeclRefExpr refer to an enclosing local or a captured variable?
Decl - This represents one declaration (or definition), e.g.
bool isInStdNamespace() const
SourceLocation getEndLoc() const LLVM_READONLY
ASTContext & getASTContext() const LLVM_READONLY
bool isImplicit() const
isImplicit - Indicates whether the declaration was implicitly generated by the implementation.
bool isInvalidDecl() const
SourceLocation getLocation() const
DeclContext * getDeclContext()
SourceLocation getBeginLoc() const LLVM_READONLY
The name of a declaration.
OverloadedOperatorKind getCXXOverloadedOperator() const
If this name is the name of an overloadable operator in C++ (e.g., operator+), retrieve the kind of o...
SourceLocation getBeginLoc() const LLVM_READONLY
TypeSourceInfo * getTypeSourceInfo() const
Common base class for placeholders for types that get replaced by placeholder type deduction: C++11 a...
Represents a single C99 designator.
bool isFieldDesignator() const
SourceLocation getBeginLoc() const LLVM_READONLY
bool isArrayRangeDesignator() const
void setFieldDecl(FieldDecl *FD)
FieldDecl * getFieldDecl() const
bool isArrayDesignator() const
SourceLocation getFieldLoc() const
const IdentifierInfo * getFieldName() const
SourceLocation getDotLoc() const
SourceLocation getLBracketLoc() const
Represents a C99 designated initializer expression.
bool isDirectInit() const
Whether this designated initializer should result in direct-initialization of the designated subobjec...
Expr * getArrayRangeEnd(const Designator &D) const
Expr * getSubExpr(unsigned Idx) const
llvm::MutableArrayRef< Designator > designators()
bool usesGNUSyntax() const
Determines whether this designated initializer used the deprecated GNU syntax for designated initiali...
Expr * getArrayRangeStart(const Designator &D) const
void ExpandDesignator(const ASTContext &C, unsigned Idx, const Designator *First, const Designator *Last)
Replaces the designator at index Idx with the series of designators in [First, Last).
static DesignatedInitExpr * Create(const ASTContext &C, llvm::ArrayRef< Designator > Designators, ArrayRef< Expr * > IndexExprs, SourceLocation EqualOrColonLoc, bool GNUSyntax, Expr *Init)
Expr * getArrayIndex(const Designator &D) const
Designator * getDesignator(unsigned Idx)
Expr * getInit() const
Retrieve the initializer value.
unsigned size() const
Returns the number of designators in this initializer.
SourceLocation getBeginLoc() const LLVM_READONLY
SourceLocation getEndLoc() const LLVM_READONLY
SourceLocation getEqualOrColonLoc() const
Retrieve the location of the '=' that precedes the initializer value itself, if present.
unsigned getNumSubExprs() const
Retrieve the total number of subexpressions in this designated initializer expression,...
InitListExpr * getUpdater() const
Designation - Represent a full designation, which is a sequence of designators.
const Designator & getDesignator(unsigned Idx) const
unsigned getNumDesignators() const
Designator - A designator in a C99 designated initializer.
SourceLocation getFieldLoc() const
SourceLocation getDotLoc() const
Expr * getArrayRangeStart() const
bool isArrayDesignator() const
SourceLocation getLBracketLoc() const
bool isArrayRangeDesignator() const
bool isFieldDesignator() const
SourceLocation getRBracketLoc() const
SourceLocation getEllipsisLoc() const
Expr * getArrayRangeEnd() const
const IdentifierInfo * getFieldDecl() const
Expr * getArrayIndex() const
static Designator CreateFieldDesignator(const IdentifierInfo *FieldName, SourceLocation DotLoc, SourceLocation FieldLoc)
Creates a field designator.
bool isIgnored(unsigned DiagID, SourceLocation Loc) const
Determine whether the diagnostic is known to be ignored.
RAII object that enters a new expression evaluation context.
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of enums.
The return type of classify().
This represents one expression.
Expr * IgnoreParenCasts() LLVM_READONLY
Skip past any parentheses and casts which might surround this expression until reaching a fixed point...
bool isValueDependent() const
Determines whether the value of this expression depends on.
ExprValueKind getValueKind() const
getValueKind - The value kind that this expression produces.
bool refersToVectorElement() const
Returns whether this expression refers to a vector element.
bool isTypeDependent() const
Determines whether the type of this expression depends on.
llvm::APSInt EvaluateKnownConstInt(const ASTContext &Ctx, SmallVectorImpl< PartialDiagnosticAt > *Diag=nullptr) const
EvaluateKnownConstInt - Call EvaluateAsRValue and return the folded integer.
Expr * IgnoreParenImpCasts() LLVM_READONLY
Skip past any parentheses and implicit casts which might surround this expression until reaching a fi...
Expr * IgnoreImplicit() LLVM_READONLY
Skip past any implicit AST nodes which might surround this expression until reaching a fixed point.
Expr * IgnoreParens() LLVM_READONLY
Skip past any parentheses which might surround this expression until reaching a fixed point.
bool isLValue() const
isLValue - True if this expression is an "l-value" according to the rules of the current language.
static bool hasAnyTypeDependentArguments(ArrayRef< Expr * > Exprs)
hasAnyTypeDependentArguments - Determines if any of the expressions in Exprs is type-dependent.
@ NPC_ValueDependentIsNull
Specifies that a value-dependent expression of integral or dependent type should be considered a null...
@ NPC_ValueDependentIsNotNull
Specifies that a value-dependent expression should be considered to never be a null pointer constant.
ExprObjectKind getObjectKind() const
getObjectKind - The object kind that this expression produces.
bool EvaluateAsRValue(EvalResult &Result, const ASTContext &Ctx, bool InConstantContext=false) const
EvaluateAsRValue - Return true if this is a constant which we can fold to an rvalue using any crazy t...
bool HasSideEffects(const ASTContext &Ctx, bool IncludePossibleEffects=true) const
HasSideEffects - This routine returns true for all those expressions which have any effect other than...
Expr * IgnoreImpCasts() LLVM_READONLY
Skip past any implicit casts which might surround this expression until reaching a fixed point.
bool isTemporaryObject(ASTContext &Ctx, const CXXRecordDecl *TempTy) const
Determine whether the result of this expression is a temporary object of the given class type.
NullPointerConstantKind isNullPointerConstant(ASTContext &Ctx, NullPointerConstantValueDependence NPC) const
isNullPointerConstant - C99 6.3.2.3p3 - Test if this reduces down to a Null pointer constant.
void setValueKind(ExprValueKind Cat)
setValueKind - Set the value kind produced by this expression.
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
bool refersToMatrixElement() const
Returns whether this expression refers to a matrix element.
bool refersToBitField() const
Returns true if this expression is a gl-value that potentially refers to a bit-field.
ExtVectorType - Extended vector type.
Represents difference between two FPOptions values.
Represents a member of a struct/union/class.
bool hasInClassInitializer() const
Determine whether this member has a C++11 default member initializer.
unsigned getFieldIndex() const
Returns the index of this field within its record, as appropriate for passing to ASTRecordLayout::get...
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
bool isUnnamedBitfield() const
Determines whether this is an unnamed bitfield.
static FixItHint CreateRemoval(CharSourceRange RemoveRange)
Create a code modification hint that removes the given source range.
static FixItHint CreateInsertion(SourceLocation InsertionLoc, StringRef Code, bool BeforePreviousInsertions=false)
Create a code modification hint that inserts the given code string at a specific location.
Represents a function declaration or definition.
const ParmVarDecl * getParamDecl(unsigned i) const
unsigned getMinRequiredArguments() const
Returns the minimum number of arguments needed to call this function.
FunctionTemplateDecl * getDescribedFunctionTemplate() const
Retrieves the function template that is described by this function declaration.
QualType getReturnType() const
bool isDeleted() const
Whether this function has been deleted.
bool isDefaulted() const
Whether this function is defaulted.
unsigned getNumParams() const
Return the number of parameters this function must have based on its FunctionType.
Declaration of a template function.
FunctionDecl * getTemplatedDecl() const
Get the underlying function declaration of the template.
One of these records is kept for each identifier that is lexed.
static ImplicitCastExpr * Create(const ASTContext &Context, QualType T, CastKind Kind, Expr *Operand, const CXXCastPath *BasePath, ExprValueKind Cat, FPOptionsOverride FPO)
ImplicitConversionSequence - Represents an implicit conversion sequence, which may be a standard conv...
@ StaticObjectArgumentConversion
StandardConversionSequence Standard
When ConversionKind == StandardConversion, provides the details of the standard conversion sequence.
UserDefinedConversionSequence UserDefined
When ConversionKind == UserDefinedConversion, provides the details of the user-defined conversion seq...
static ImplicitConversionSequence getNullptrToBool(QualType SourceType, QualType DestType, bool NeedLValToRVal)
Form an "implicit" conversion sequence from nullptr_t to bool, for a direct-initialization of a bool ...
Represents an implicitly-generated value initialization of an object of a given type.
Represents a C array with an unspecified size.
Represents a field injected from an anonymous union/struct into the parent scope.
chain_iterator chain_end() const
chain_iterator chain_begin() const
ArrayRef< NamedDecl * >::const_iterator chain_iterator
Describes an C or C++ initializer list.
bool hasArrayFiller() const
Return true if this is an array initializer and its array "filler" has been set.
void setSyntacticForm(InitListExpr *Init)
void markError()
Mark the semantic form of the InitListExpr as error when the semantic analysis fails.
bool hasDesignatedInit() const
Determine whether this initializer list contains a designated initializer.
bool isTransparent() const
Is this a transparent initializer list (that is, an InitListExpr that is purely syntactic,...
void resizeInits(const ASTContext &Context, unsigned NumInits)
Specify the number of initializers.
FieldDecl * getInitializedFieldInUnion()
If this initializes a union, specifies which field in the union to initialize.
unsigned getNumInits() const
SourceLocation getBeginLoc() const LLVM_READONLY
void setInit(unsigned Init, Expr *expr)
SourceLocation getLBraceLoc() const
Expr * updateInit(const ASTContext &C, unsigned Init, Expr *expr)
Updates the initializer at index Init with the new expression expr, and returns the old expression at...
void setArrayFiller(Expr *filler)
InitListExpr * getSyntacticForm() const
Expr * getArrayFiller()
If this initializer list initializes an array with more elements than there are initializers in the l...
SourceLocation getRBraceLoc() const
const Expr * getInit(unsigned Init) const
bool isIdiomaticZeroInitializer(const LangOptions &LangOpts) const
Is this the zero initializer {0} in a language which considers it idiomatic?
SourceLocation getEndLoc() const LLVM_READONLY
void setInitializedFieldInUnion(FieldDecl *FD)
bool isSyntacticForm() const
void setRBraceLoc(SourceLocation Loc)
void sawArrayRangeDesignator(bool ARD=true)
Expr ** getInits()
Retrieve the set of initializers.
Describes the kind of initialization being performed, along with location information for tokens rela...
@ IK_DirectList
Direct list-initialization.
@ IK_Value
Value initialization.
@ IK_Direct
Direct initialization.
@ IK_Copy
Copy initialization.
@ IK_Default
Default initialization.
static InitializationKind CreateDirect(SourceLocation InitLoc, SourceLocation LParenLoc, SourceLocation RParenLoc)
Create a direct initialization.
static InitializationKind CreateForInit(SourceLocation Loc, bool DirectInit, Expr *Init)
Create an initialization from an initializer (which, for direct initialization from a parenthesized l...
static InitializationKind CreateCopy(SourceLocation InitLoc, SourceLocation EqualLoc, bool AllowExplicitConvs=false)
Create a copy initialization.
static InitializationKind CreateDirectList(SourceLocation InitLoc)
static InitializationKind CreateValue(SourceLocation InitLoc, SourceLocation LParenLoc, SourceLocation RParenLoc, bool isImplicit=false)
Create a value initialization.
A single step in the initialization sequence.
StepKind Kind
The kind of conversion or initialization step we are taking.
InitListExpr * WrappingSyntacticList
When Kind = SK_RewrapInitList, the syntactic form of the wrapping list.
ImplicitConversionSequence * ICS
When Kind = SK_ConversionSequence, the implicit conversion sequence.
struct F Function
When Kind == SK_ResolvedOverloadedFunction or Kind == SK_UserConversion, the function that the expres...
Describes the sequence of initializations required to initialize a given object or reference with a s...
step_iterator step_begin() const
void AddListInitializationStep(QualType T)
Add a list-initialization step.
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.
void AddStringInitStep(QualType T)
Add a string init step.
void AddStdInitializerListConstructionStep(QualType T)
Add a step to construct a std::initializer_list object from an initializer list.
void AddConstructorInitializationStep(DeclAccessPair FoundDecl, CXXConstructorDecl *Constructor, QualType T, bool HadMultipleCandidates, bool FromInitList, bool AsInitList)
Add a constructor-initialization step.
@ SK_StdInitializerListConstructorCall
Perform initialization via a constructor taking a single std::initializer_list argument.
@ SK_AtomicConversion
Perform a conversion adding _Atomic to a type.
@ SK_ObjCObjectConversion
An initialization that "converts" an Objective-C object (not a point to an object) to another Objecti...
@ SK_GNUArrayInit
Array initialization (from an array rvalue) as a GNU extension.
@ SK_CastDerivedToBaseLValue
Perform a derived-to-base cast, producing an lvalue.
@ SK_ProduceObjCObject
Produce an Objective-C object pointer.
@ SK_FunctionReferenceConversion
Perform a function reference conversion, see [dcl.init.ref]p4.
@ SK_BindReference
Reference binding to an lvalue.
@ SK_ArrayLoopInit
Array initialization by elementwise copy.
@ SK_ConstructorInitialization
Perform initialization via a constructor.
@ SK_OCLSamplerInit
Initialize an OpenCL sampler from an integer.
@ SK_StringInit
Initialization by string.
@ SK_ZeroInitialization
Zero-initialize the object.
@ SK_CastDerivedToBaseXValue
Perform a derived-to-base cast, producing an xvalue.
@ SK_QualificationConversionXValue
Perform a qualification conversion, producing an xvalue.
@ SK_UserConversion
Perform a user-defined conversion, either via a conversion function or via a constructor.
@ SK_CastDerivedToBasePRValue
Perform a derived-to-base cast, producing an rvalue.
@ SK_BindReferenceToTemporary
Reference binding to a temporary.
@ SK_PassByIndirectRestore
Pass an object by indirect restore.
@ SK_ParenthesizedArrayInit
Array initialization from a parenthesized initializer list.
@ SK_ParenthesizedListInit
Initialize an aggreagate with parenthesized list of values.
@ SK_ArrayInit
Array initialization (from an array rvalue).
@ SK_ExtraneousCopyToTemporary
An optional copy of a temporary object to another temporary object, which is permitted (but not requi...
@ SK_ArrayLoopIndex
Array indexing for initialization by elementwise copy.
@ SK_ConversionSequenceNoNarrowing
Perform an implicit conversion sequence without narrowing.
@ SK_RewrapInitList
Rewrap the single-element initializer list for a reference.
@ SK_CAssignment
C assignment.
@ SK_ConstructorInitializationFromList
Perform initialization via a constructor, taking arguments from a single InitListExpr.
@ SK_PassByIndirectCopyRestore
Pass an object by indirect copy-and-restore.
@ SK_ResolveAddressOfOverloadedFunction
Resolve the address of an overloaded function to a specific function declaration.
@ SK_UnwrapInitList
Unwrap the single-element initializer list for a reference.
@ SK_FinalCopy
Direct-initialization from a reference-related object in the final stage of class copy-initialization...
@ SK_QualificationConversionLValue
Perform a qualification conversion, producing an lvalue.
@ SK_StdInitializerList
Construct a std::initializer_list from an initializer list.
@ SK_QualificationConversionPRValue
Perform a qualification conversion, producing a prvalue.
@ SK_ConversionSequence
Perform an implicit conversion sequence.
@ SK_ListInitialization
Perform list-initialization without a constructor.
@ SK_OCLZeroOpaqueType
Initialize an opaque OpenCL type (event_t, queue_t, etc.) with zero.
void AddUserConversionStep(FunctionDecl *Function, DeclAccessPair FoundDecl, QualType T, bool HadMultipleCandidates)
Add a new step invoking a conversion function, which is either a constructor or a conversion function...
void SetZeroInitializationFixit(const std::string &Fixit, SourceLocation L)
Call for initializations are invalid but that would be valid zero initialzations if Fixit was applied...
InitializationSequence(Sema &S, const InitializedEntity &Entity, const InitializationKind &Kind, MultiExprArg Args, bool TopLevelOfInitList=false, bool TreatUnavailableAsInvalid=true)
Try to perform initialization of the given entity, creating a record of the steps required to perform...
void AddQualificationConversionStep(QualType Ty, ExprValueKind Category)
Add a new step that performs a qualification conversion to the given type.
void AddFunctionReferenceConversionStep(QualType Ty)
Add a new step that performs a function reference conversion to the given type.
~InitializationSequence()
void AddDerivedToBaseCastStep(QualType BaseType, ExprValueKind Category)
Add a new step in the initialization that performs a derived-to- base cast.
FailureKind getFailureKind() const
Determine why initialization failed.
void InitializeFrom(Sema &S, const InitializedEntity &Entity, const InitializationKind &Kind, MultiExprArg Args, bool TopLevelOfInitList, bool TreatUnavailableAsInvalid)
void AddParenthesizedListInitStep(QualType T)
void SetFailed(FailureKind Failure)
Note that this initialization sequence failed.
bool isAmbiguous() const
Determine whether this initialization failed due to an ambiguity.
void AddOCLZeroOpaqueTypeStep(QualType T)
Add a step to initialzie an OpenCL opaque type (event_t, queue_t, etc.) from a zero constant.
void AddFinalCopy(QualType T)
Add a new step that makes a copy of the input to an object of the given type, as the final step in cl...
void setSequenceKind(enum SequenceKind SK)
Set the kind of sequence computed.
void AddObjCObjectConversionStep(QualType T)
Add an Objective-C object conversion step, which is always a no-op.
void SetOverloadFailure(FailureKind Failure, OverloadingResult Result)
Note that this initialization sequence failed due to failed overload resolution.
step_iterator step_end() const
void AddParenthesizedArrayInitStep(QualType T)
Add a parenthesized array initialization step.
void AddExtraneousCopyToTemporary(QualType T)
Add a new step that makes an extraneous copy of the input to a temporary of the same class type.
void setIncompleteTypeFailure(QualType IncompleteType)
Note that this initialization sequence failed due to an incomplete type.
void AddOCLSamplerInitStep(QualType T)
Add a step to initialize an OpenCL sampler from an integer constant.
void AddCAssignmentStep(QualType T)
Add a C assignment step.
void AddPassByIndirectCopyRestoreStep(QualType T, bool shouldCopy)
Add a step to pass an object by indirect copy-restore.
void RewrapReferenceInitList(QualType T, InitListExpr *Syntactic)
Add steps to unwrap a initializer list for a reference around a single element and rewrap it at the e...
bool Diagnose(Sema &S, const InitializedEntity &Entity, const InitializationKind &Kind, ArrayRef< Expr * > Args)
Diagnose an potentially-invalid initialization sequence.
bool Failed() const
Determine whether the initialization sequence is invalid.
void AddAtomicConversionStep(QualType Ty)
Add a new step that performs conversion from non-atomic to atomic type.
void dump() const
Dump a representation of this initialization sequence to standard error, for debugging purposes.
void AddConversionSequenceStep(const ImplicitConversionSequence &ICS, QualType T, bool TopLevelOfInitList=false)
Add a new step that applies an implicit conversion sequence.
void AddZeroInitializationStep(QualType T)
Add a zero-initialization step.
void AddProduceObjCObjectStep(QualType T)
Add a step to "produce" an Objective-C object (by retaining it).
enum SequenceKind getKind() const
Determine the kind of initialization sequence computed.
SequenceKind
Describes the kind of initialization sequence computed.
@ NormalSequence
A normal sequence.
@ FailedSequence
A failed initialization sequence.
@ DependentSequence
A dependent initialization, which could not be type-checked due to the presence of dependent types or...
void AddReferenceBindingStep(QualType T, bool BindingTemporary)
Add a new step binding a reference to an object.
FailureKind
Describes why initialization failed.
@ FK_UserConversionOverloadFailed
Overloading for a user-defined conversion failed.
@ FK_NarrowStringIntoWideCharArray
Initializing a wide char array with narrow string literal.
@ FK_ArrayTypeMismatch
Array type mismatch.
@ FK_ParenthesizedListInitForReference
Reference initialized from a parenthesized initializer list.
@ FK_NonConstLValueReferenceBindingToVectorElement
Non-const lvalue reference binding to a vector element.
@ FK_ReferenceInitDropsQualifiers
Reference binding drops qualifiers.
@ FK_InitListBadDestinationType
Initialization of some unused destination type with an initializer list.
@ FK_ConversionFromPropertyFailed
Implicit conversion failed.
@ FK_NonConstLValueReferenceBindingToUnrelated
Non-const lvalue reference binding to an lvalue of unrelated type.
@ FK_ListConstructorOverloadFailed
Overloading for list-initialization by constructor failed.
@ FK_ReferenceInitFailed
Reference binding failed.
@ FK_DesignatedInitForNonAggregate
@ FK_ArrayNeedsInitList
Array must be initialized with an initializer list.
@ FK_PlainStringIntoUTF8Char
Initializing char8_t array with plain string literal.
@ FK_NonConstantArrayInit
Non-constant array initializer.
@ FK_NonConstLValueReferenceBindingToTemporary
Non-const lvalue reference binding to a temporary.
@ FK_ConversionFailed
Implicit conversion failed.
@ FK_ArrayNeedsInitListOrStringLiteral
Array must be initialized with an initializer list or a string literal.
@ FK_ParenthesizedListInitForScalar
Scalar initialized from a parenthesized initializer list.
@ FK_PlaceholderType
Initializer has a placeholder type which cannot be resolved by initialization.
@ FK_IncompatWideStringIntoWideChar
Initializing wide char array with incompatible wide string literal.
@ FK_NonConstLValueReferenceBindingToMatrixElement
Non-const lvalue reference binding to a matrix element.
@ FK_TooManyInitsForReference
Too many initializers provided for a reference.
@ FK_NonConstLValueReferenceBindingToBitfield
Non-const lvalue reference binding to a bit-field.
@ FK_ReferenceAddrspaceMismatchTemporary
Reference with mismatching address space binding to temporary.
@ FK_ListInitializationFailed
List initialization failed at some point.
@ FK_TooManyInitsForScalar
Too many initializers for scalar.
@ FK_AddressOfOverloadFailed
Cannot resolve the address of an overloaded function.
@ FK_VariableLengthArrayHasInitializer
Variable-length array must not have an initializer.
@ FK_ArrayNeedsInitListOrWideStringLiteral
Array must be initialized with an initializer list or a wide string literal.
@ FK_RValueReferenceBindingToLValue
Rvalue reference binding to an lvalue.
@ FK_Incomplete
Initialization of an incomplete type.
@ FK_WideStringIntoCharArray
Initializing char array with wide string literal.
@ FK_ExplicitConstructor
List-copy-initialization chose an explicit constructor.
@ FK_ReferenceInitOverloadFailed
Overloading due to reference initialization failed.
@ FK_ConstructorOverloadFailed
Overloading for initialization by constructor failed.
@ FK_ReferenceBindingToInitList
Reference initialization from an initializer list.
@ FK_DefaultInitOfConst
Default-initialization of a 'const' object.
@ FK_ParenthesizedListInitFailed
Parenthesized list initialization failed at some point.
@ FK_AddressOfUnaddressableFunction
Trying to take the address of a function that doesn't support having its address taken.
@ FK_UTF8StringIntoPlainChar
Initializing char array with UTF-8 string literal.
bool isDirectReferenceBinding() const
Determine whether this initialization is a direct reference binding (C++ [dcl.init....
void AddArrayInitLoopStep(QualType T, QualType EltTy)
Add an array initialization loop step.
void AddAddressOverloadResolutionStep(FunctionDecl *Function, DeclAccessPair Found, bool HadMultipleCandidates)
Add a new step in the initialization that resolves the address of an overloaded function to a specifi...
void AddArrayInitStep(QualType T, bool IsGNUExtension)
Add an array initialization step.
bool isConstructorInitialization() const
Determine whether this initialization is direct call to a constructor.
SmallVectorImpl< Step >::const_iterator step_iterator
OverloadCandidateSet & getFailedCandidateSet()
Retrieve a reference to the candidate set when overload resolution fails.
Describes an entity that is being initialized.
static InitializedEntity InitializeBase(ASTContext &Context, const CXXBaseSpecifier *Base, bool IsInheritedVirtualBase, const InitializedEntity *Parent=nullptr)
Create the initialization entity for a base class subobject.
static InitializedEntity InitializeMember(FieldDecl *Member, const InitializedEntity *Parent=nullptr, bool Implicit=false)
Create the initialization entity for a member subobject.
VD Variable
When Kind == EK_Variable, EK_Member, EK_Binding, or EK_TemplateParameter, the variable,...
EntityKind getKind() const
Determine the kind of initialization.
DeclarationName getName() const
Retrieve the name of the entity being initialized.
unsigned allocateManglingNumber() const
QualType getType() const
Retrieve type being initialized.
ValueDecl * getDecl() const
Retrieve the variable, parameter, or field being initialized.
bool isImplicitMemberInitializer() const
Is this the implicit initialization of a member of a class from a defaulted constructor?
const InitializedEntity * getParent() const
Retrieve the parent of the entity being initialized, when the initialization itself is occurring with...
static InitializedEntity InitializeTemporary(QualType Type)
Create the initialization entity for a temporary.
bool isParameterConsumed() const
Determine whether this initialization consumes the parameter.
static InitializedEntity InitializeElement(ASTContext &Context, unsigned Index, const InitializedEntity &Parent)
Create the initialization entity for an array element.
unsigned getElementIndex() const
If this is an array, vector, or complex number element, get the element's index.
void setElementIndex(unsigned Index)
If this is already the initializer for an array or vector element, sets the element index.
SourceLocation getCaptureLoc() const
Determine the location of the capture when initializing field from a captured variable in a lambda.
bool isParamOrTemplateParamKind() const
llvm::PointerIntPair< const CXXBaseSpecifier *, 1 > Base
When Kind == EK_Base, the base specifier that provides the base class.
bool allowsNRVO() const
Determine whether this initialization allows the named return value optimization, which also applies ...
bool isParameterKind() const
void dump() const
Dump a representation of the initialized entity to standard error, for debugging purposes.
EntityKind
Specifies the kind of entity being initialized.
@ EK_Variable
The entity being initialized is a variable.
@ EK_Temporary
The entity being initialized is a temporary object.
@ EK_Binding
The entity being initialized is a structured binding of a decomposition declaration.
@ EK_BlockElement
The entity being initialized is a field of block descriptor for the copied-in c++ object.
@ EK_Parameter_CF_Audited
The entity being initialized is a function parameter; function is member of group of audited CF APIs.
@ EK_LambdaToBlockConversionBlockElement
The entity being initialized is a field of block descriptor for the copied-in lambda object that's us...
@ EK_Member
The entity being initialized is a non-static data member subobject.
@ EK_Base
The entity being initialized is a base member subobject.
@ EK_Result
The entity being initialized is the result of a function call.
@ EK_TemplateParameter
The entity being initialized is a non-type template parameter.
@ EK_StmtExprResult
The entity being initialized is the result of a statement expression.
@ EK_ParenAggInitMember
The entity being initialized is a non-static data member subobject of an object initialized via paren...
@ EK_VectorElement
The entity being initialized is an element of a vector.
@ EK_New
The entity being initialized is an object (or array of objects) allocated via new.
@ EK_CompoundLiteralInit
The entity being initialized is the initializer for a compound literal.
@ EK_Parameter
The entity being initialized is a function parameter.
@ EK_Delegating
The initialization is being done by a delegating constructor.
@ EK_ComplexElement
The entity being initialized is the real or imaginary part of a complex number.
@ EK_ArrayElement
The entity being initialized is an element of an array.
@ EK_LambdaCapture
The entity being initialized is the field that captures a variable in a lambda.
@ EK_Exception
The entity being initialized is an exception object that is being thrown.
@ EK_RelatedResult
The entity being implicitly initialized back to the formal result type.
static InitializedEntity InitializeMemberFromParenAggInit(FieldDecl *Member)
Create the initialization entity for a member subobject initialized via parenthesized aggregate init.
SourceLocation getThrowLoc() const
Determine the location of the 'throw' keyword when initializing an exception object.
unsigned Index
When Kind == EK_ArrayElement, EK_VectorElement, or EK_ComplexElement, the index of the array or vecto...
bool isVariableLengthArrayNew() const
Determine whether this is an array new with an unknown bound.
bool isDefaultMemberInitializer() const
Is this the default member initializer of a member (specified inside the class definition)?
llvm::PointerIntPair< ParmVarDecl *, 1 > Parameter
When Kind == EK_Parameter, the ParmVarDecl, with the integer indicating whether the parameter is "con...
const CXXBaseSpecifier * getBaseSpecifier() const
Retrieve the base specifier.
SourceLocation getReturnLoc() const
Determine the location of the 'return' keyword when initializing the result of a function call.
TypeSourceInfo * getTypeSourceInfo() const
Retrieve complete type-source information for the object being constructed, if known.
ObjCMethodDecl * getMethodDecl() const
Retrieve the ObjectiveC method being initialized.
The injected class name of a C++ class template or class template partial specialization.
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'.
An lvalue reference type, per C++11 [dcl.ref].
Describes the capture of a variable or of this, or of a C++1y init-capture.
bool capturesVariable() const
Determine whether this capture handles a variable.
Represents the results of name lookup.
bool empty() const
Return true if no decls were found.
void suppressDiagnostics()
Suppress the diagnostics that would normally fire because of this lookup.
Represents a prvalue temporary that is written into memory so that a reference can bind to it.
StorageDuration getStorageDuration() const
Retrieve the storage duration for the materialized temporary.
This represents a decl that may have a name.
NamedDecl * getUnderlyingDecl()
Looks through UsingDecls and ObjCCompatibleAliasDecls for the underlying named decl.
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
Represent a C++ namespace.
Represents a place-holder for an object not to be initialized by anything.
ObjCEncodeExpr, used for @encode in Objective-C.
QualType getEncodedType() const
ObjCIndirectCopyRestoreExpr - Represents the passing of a function argument by indirect copy-restore ...
OpaqueValueExpr - An expression referring to an opaque object of a fixed type and value class.
bool isAvailableOption(llvm::StringRef Ext, const LangOptions &LO) const
OverloadCandidateSet - A set of overload candidates, used in C++ overload resolution (C++ 13....
void clear(CandidateSetKind CSK)
Clear out all of the candidates.
void setDestAS(LangAS AS)
@ CSK_InitByConstructor
C++ [over.match.ctor], [over.match.list] Initialization of an object of class type by constructor,...
@ CSK_InitByUserDefinedConversion
C++ [over.match.copy]: Copy-initialization of an object of class type by user-defined conversion.
@ CSK_Normal
Normal lookup.
SmallVectorImpl< OverloadCandidate >::iterator iterator
void NoteCandidates(PartialDiagnosticAt PA, Sema &S, OverloadCandidateDisplayKind OCD, ArrayRef< Expr * > Args, StringRef Opc="", SourceLocation Loc=SourceLocation(), llvm::function_ref< bool(OverloadCandidate &)> Filter=[](OverloadCandidate &) { return true;})
When overload resolution fails, prints diagnostic messages containing the candidates in the candidate...
OverloadingResult BestViableFunction(Sema &S, SourceLocation Loc, OverloadCandidateSet::iterator &Best)
Find the best viable function on this overload set, if it exists.
SmallVector< OverloadCandidate *, 32 > CompleteCandidates(Sema &S, OverloadCandidateDisplayKind OCD, ArrayRef< Expr * > Args, SourceLocation OpLoc=SourceLocation(), llvm::function_ref< bool(OverloadCandidate &)> Filter=[](OverloadCandidate &) { return true;})
Represents a parameter to a function.
PointerType - C99 6.7.5.1 - Pointer Declarators.
A (possibly-)qualified type.
bool isVolatileQualified() const
Determine whether this type is volatile-qualified.
bool hasQualifiers() const
Determine whether this type has any qualifiers.
QualType getNonLValueExprType(const ASTContext &Context) const
Determine the type of a (typically non-lvalue) expression with the specified result type.
QualType withConst() const
QualType getLocalUnqualifiedType() const
Return this type with all of the instance-specific qualifiers removed, but without removing any quali...
bool isNull() const
Return true if this QualType doesn't point to a type yet.
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
LangAS getAddressSpace() const
Return the address space of this type.
Qualifiers getQualifiers() const
Retrieve the set of qualifiers applied to this type.
Qualifiers::ObjCLifetime getObjCLifetime() const
Returns lifetime attribute of this type.
QualType getNonReferenceType() const
If Type is a reference type (e.g., const int&), returns the type that the reference refers to ("const...
QualType getCanonicalType() const
QualType getUnqualifiedType() const
Retrieve the unqualified variant of the given type, removing as little sugar as possible.
bool isConstQualified() const
Determine whether this type is const-qualified.
bool hasAddressSpace() const
Check if this type has any address space qualifier.
DestructionKind isDestructedType() const
Returns a nonzero value if objects of this type require non-trivial work to clean up after.
The collection of all-type qualifiers we support.
unsigned getCVRQualifiers() const
void addAddressSpace(LangAS space)
@ OCL_Weak
Reading or writing from this object requires a barrier call.
bool hasQualifiers() const
Return true if the set contains any qualifiers.
bool hasAddressSpace() const
Qualifiers withoutAddressSpace() const
void removeAddressSpace()
static Qualifiers fromCVRMask(unsigned CVR)
static bool isAddressSpaceSupersetOf(LangAS A, LangAS B)
Returns true if address space A is equal to or a superset of B.
bool hasObjCLifetime() const
bool compatiblyIncludes(Qualifiers other) const
Determines if these qualifiers compatibly include another set.
LangAS getAddressSpace() const
An rvalue reference type, per C++11 [dcl.ref].
Represents a struct/union/class.
bool hasFlexibleArrayMember() const
field_iterator field_end() const
field_range fields() const
bool isRandomized() const
RecordDecl * getDefinition() const
Returns the RecordDecl that actually defines this struct/union/class.
specific_decl_iterator< FieldDecl > field_iterator
field_iterator field_begin() const
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
RecordDecl * getDecl() const
Base for LValueReferenceType and RValueReferenceType.
bool isSpelledAsLValue() const
Sema - This implements semantic analysis and AST building for C.
QualType SubstAutoType(QualType TypeWithAuto, QualType Replacement)
Substitute Replacement for auto in TypeWithAuto.
CXXSpecialMember getSpecialMember(const CXXMethodDecl *MD)
@ LookupOrdinaryName
Ordinary name lookup, which finds ordinary names (functions, variables, typedefs, etc....
@ LookupMemberName
Member name lookup, which finds the names of class/struct/union members.
bool DiagRedefinedPlaceholderFieldDecl(SourceLocation Loc, RecordDecl *ClassDecl, const IdentifierInfo *Name)
bool CheckObjCBridgeRelatedConversions(SourceLocation Loc, QualType DestType, QualType SrcType, Expr *&SrcExpr, bool Diagnose=true)
ImplicitConversionSequence TryImplicitConversion(Expr *From, QualType ToType, bool SuppressUserConversions, AllowedExplicit AllowExplicit, bool InOverloadResolution, bool CStyle, bool AllowObjCWritebackConversion)
SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID, bool DeferHint=false)
Emit a diagnostic.
bool IsStringInit(Expr *Init, const ArrayType *AT)
bool isImplicitlyDeleted(FunctionDecl *FD)
Determine whether the given function is an implicitly-deleted special member function.
bool CompleteConstructorCall(CXXConstructorDecl *Constructor, QualType DeclInitType, MultiExprArg ArgsPtr, SourceLocation Loc, SmallVectorImpl< Expr * > &ConvertedArgs, bool AllowExplicit=false, bool IsListInitialization=false)
Given a constructor and the set of arguments provided for the constructor, convert the arguments and ...
void AddConversionCandidate(CXXConversionDecl *Conversion, DeclAccessPair FoundDecl, CXXRecordDecl *ActingContext, Expr *From, QualType ToType, OverloadCandidateSet &CandidateSet, bool AllowObjCConversionOnExplicit, bool AllowExplicit, bool AllowResultConversion=true)
AddConversionCandidate - Add a C++ conversion function as a candidate in the candidate set (C++ [over...
ReferenceCompareResult
ReferenceCompareResult - Expresses the result of comparing two types (cv1 T1 and cv2 T2) to determine...
@ Ref_Incompatible
Ref_Incompatible - The two types are incompatible, so direct reference binding is not possible.
@ Ref_Compatible
Ref_Compatible - The two types are reference-compatible.
@ Ref_Related
Ref_Related - The two types are reference-related, which means that their unqualified forms (T1 and T...
void AddTemplateConversionCandidate(FunctionTemplateDecl *FunctionTemplate, DeclAccessPair FoundDecl, CXXRecordDecl *ActingContext, Expr *From, QualType ToType, OverloadCandidateSet &CandidateSet, bool AllowObjCConversionOnExplicit, bool AllowExplicit, bool AllowResultConversion=true)
Adds a conversion function template specialization candidate to the overload set, using template argu...
ExprResult MaybeBindToTemporary(Expr *E)
MaybeBindToTemporary - If the passed in expression has a record type with a non-trivial destructor,...
ExprResult VerifyIntegerConstantExpression(Expr *E, llvm::APSInt *Result, VerifyICEDiagnoser &Diagnoser, AllowFoldKind CanFold=NoFold)
VerifyIntegerConstantExpression - Verifies that an expression is an ICE, and reports the appropriate ...
ExprResult ActOnDesignatedInitializer(Designation &Desig, SourceLocation EqualOrColonLoc, bool GNUSyntax, ExprResult Init)
FPOptionsOverride CurFPFeatureOverrides()
ExprResult PerformImplicitConversion(Expr *From, QualType ToType, const ImplicitConversionSequence &ICS, AssignmentAction Action, CheckedConversionKind CCK=CCK_ImplicitConversion)
PerformImplicitConversion - Perform an implicit conversion of the expression From to the type ToType ...
DiagnosticsEngine & getDiagnostics() const
bool checkAddressOfFunctionIsAvailable(const FunctionDecl *Function, bool Complain=false, SourceLocation Loc=SourceLocation())
Returns whether the given function's address can be taken or not, optionally emitting a diagnostic if...
AccessResult CheckDestructorAccess(SourceLocation Loc, CXXDestructorDecl *Dtor, const PartialDiagnostic &PDiag, QualType objectType=QualType())
FunctionDecl * ResolveAddressOfOverloadedFunction(Expr *AddressOfExpr, QualType TargetType, bool Complain, DeclAccessPair &Found, bool *pHadMultipleCandidates=nullptr)
ResolveAddressOfOverloadedFunction - Try to resolve the address of an overloaded function (C++ [over....
ExprResult DefaultFunctionArrayLvalueConversion(Expr *E, bool Diagnose=true)
ASTContext & getASTContext() const
CXXDestructorDecl * LookupDestructor(CXXRecordDecl *Class)
Look for the destructor of the given class.
AssignConvertType CheckTransparentUnionArgumentConstraints(QualType ArgType, ExprResult &RHS)
bool isInitListConstructor(const FunctionDecl *Ctor)
Determine whether Ctor is an initializer-list constructor, as defined in [dcl.init....
AccessResult CheckMemberOperatorAccess(SourceLocation Loc, Expr *ObjectExpr, const SourceRange &, DeclAccessPair FoundDecl)
ExprResult ActOnParenListExpr(SourceLocation L, SourceLocation R, MultiExprArg Val)
llvm::SmallVector< QualType, 4 > CurrentParameterCopyTypes
Stack of types that correspond to the parameter entities that are currently being copy-initialized.
std::string getFixItZeroInitializerForType(QualType T, SourceLocation Loc) const
Get a string to suggest for zero-initialization of a type.
FunctionTemplateDecl * DeclareImplicitDeductionGuideFromInitList(TemplateDecl *Template, MutableArrayRef< QualType > ParamTypes, SourceLocation Loc)
void AddTemplateOverloadCandidate(FunctionTemplateDecl *FunctionTemplate, DeclAccessPair FoundDecl, TemplateArgumentListInfo *ExplicitTemplateArgs, ArrayRef< Expr * > Args, OverloadCandidateSet &CandidateSet, bool SuppressUserConversions=false, bool PartialOverloading=false, bool AllowExplicit=true, ADLCallKind IsADLCandidate=ADLCallKind::NotADL, OverloadCandidateParamOrder PO={}, bool AggregateCandidateDeduction=false)
Add a C++ function template specialization as a candidate in the candidate set, using template argume...
SourceLocation getLocForEndOfToken(SourceLocation Loc, unsigned Offset=0)
Calls Lexer::getLocForEndOfToken()
CXXConstructorDecl * LookupDefaultConstructor(CXXRecordDecl *Class)
Look up the default constructor for the given class.
const LangOptions & getLangOpts() const
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...
void NoteTemplateLocation(const NamedDecl &Decl, std::optional< SourceRange > ParamRange={})
bool RequireNonAbstractType(SourceLocation Loc, QualType T, TypeDiagnoser &Diagnoser)
ExprResult ImpCastExprToType(Expr *E, QualType Type, CastKind CK, ExprValueKind VK=VK_PRValue, const CXXCastPath *BasePath=nullptr, CheckedConversionKind CCK=CCK_ImplicitConversion)
ImpCastExprToType - If Expr is not of type 'Type', insert an implicit cast.
void EmitRelatedResultTypeNoteForReturn(QualType destType)
Given that we had incompatible pointer types in a return statement, check whether we're in a method w...
ExprResult BuildCXXMemberCallExpr(Expr *Exp, NamedDecl *FoundDecl, CXXConversionDecl *Method, bool HadMultipleCandidates)
llvm::DenseMap< unsigned, CXXDeductionGuideDecl * > AggregateDeductionCandidates
ExprResult CheckForImmediateInvocation(ExprResult E, FunctionDecl *Decl)
Wrap the expression in a ConstantExpr if it is a potential immediate invocation.
ExprResult TemporaryMaterializationConversion(Expr *E)
If E is a prvalue denoting an unmaterialized temporary, materialize it as an xvalue.
bool CanUseDecl(NamedDecl *D, bool TreatUnavailableAsInvalid)
Determine whether the use of this declaration is valid, without emitting diagnostics.
CleanupInfo Cleanup
Used to control the generation of ExprWithCleanups.
AssignConvertType CheckSingleAssignmentConstraints(QualType LHSType, ExprResult &RHS, bool Diagnose=true, bool DiagnoseCFAudited=false, bool ConvertRHS=true)
Check assignment constraints for an assignment of RHS to LHSType.
ExprResult PerformQualificationConversion(Expr *E, QualType Ty, ExprValueKind VK=VK_PRValue, CheckedConversionKind CCK=CCK_ImplicitConversion)
std::optional< sema::TemplateDeductionInfo * > isSFINAEContext() const
Determines whether we are currently in a context where template argument substitution failures are no...
QualType DeduceTemplateSpecializationFromInitializer(TypeSourceInfo *TInfo, const InitializedEntity &Entity, const InitializationKind &Kind, MultiExprArg Init)
void DefineImplicitDefaultConstructor(SourceLocation CurrentLocation, CXXConstructorDecl *Constructor)
DefineImplicitDefaultConstructor - Checks for feasibility of defining this constructor as the default...
SourceLocation getLocationOfStringLiteralByte(const StringLiteral *SL, unsigned ByteNo) const
bool CheckDerivedToBaseConversion(QualType Derived, QualType Base, SourceLocation Loc, SourceRange Range, CXXCastPath *BasePath=nullptr, bool IgnoreAccess=false)
bool isInLifetimeExtendingContext() const
DeclContext * CurContext
CurContext - This is the current declaration context of parsing.
MaterializeTemporaryExpr * CreateMaterializeTemporaryExpr(QualType T, Expr *Temporary, bool BoundToLvalueReference)
AccessResult CheckConstructorAccess(SourceLocation Loc, CXXConstructorDecl *D, DeclAccessPair FoundDecl, const InitializedEntity &Entity, bool IsCopyBindingRefToTemp=false)
Checks access to a constructor.
AccessResult CheckAddressOfMemberAccess(Expr *OvlExpr, DeclAccessPair FoundDecl)
AssignConvertType
AssignConvertType - All of the 'assignment' semantic checks return this enum to indicate whether the ...
@ Compatible
Compatible - the types are compatible according to the standard.
@ Incompatible
Incompatible - We reject this conversion outright, it is invalid to represent it in the AST.
TemplateNameKindForDiagnostics getTemplateNameKindForDiagnostics(TemplateName Name)
ExprResult CheckPlaceholderExpr(Expr *E)
Check for operands with placeholder types and complain if found.
ExprResult BuildCXXConstructExpr(SourceLocation ConstructLoc, QualType DeclInitType, NamedDecl *FoundDecl, CXXConstructorDecl *Constructor, MultiExprArg Exprs, bool HadMultipleCandidates, bool IsListInitialization, bool IsStdInitListInitialization, bool RequiresZeroInit, CXXConstructionKind ConstructKind, SourceRange ParenRange)
BuildCXXConstructExpr - Creates a complete call to a constructor, including handling of its default a...
CheckedConversionKind
The kind of conversion being performed.
@ CCK_OtherCast
A cast other than a C-style cast.
@ CCK_CStyleCast
A C-style cast.
@ CCK_ImplicitConversion
An implicit conversion.
@ CCK_FunctionalCast
A functional-style cast.
bool inTemplateInstantiation() const
Determine whether we are currently performing template instantiation.
SourceManager & getSourceManager() const
ExprResult FixOverloadedFunctionReference(Expr *E, DeclAccessPair FoundDecl, FunctionDecl *Fn)
FixOverloadedFunctionReference - E is an expression that refers to a C++ overloaded function (possibl...
void DiscardMisalignedMemberAddress(const Type *T, Expr *E)
This function checks if the expression is in the sef of potentially misaligned members and it is conv...
bool DiagRuntimeBehavior(SourceLocation Loc, const Stmt *Statement, const PartialDiagnostic &PD)
Conditionally issue a diagnostic based on the current evaluation context.
ExprResult BuildCXXDefaultArgExpr(SourceLocation CallLoc, FunctionDecl *FD, ParmVarDecl *Param, Expr *Init=nullptr)
BuildCXXDefaultArgExpr - Creates a CXXDefaultArgExpr, instantiating the default expr if needed.
void AddOverloadCandidate(FunctionDecl *Function, DeclAccessPair FoundDecl, ArrayRef< Expr * > Args, OverloadCandidateSet &CandidateSet, bool SuppressUserConversions=false, bool PartialOverloading=false, bool AllowExplicit=true, bool AllowExplicitConversion=false, ADLCallKind IsADLCandidate=ADLCallKind::NotADL, ConversionSequenceList EarlyConversions=std::nullopt, OverloadCandidateParamOrder PO={}, bool AggregateCandidateDeduction=false)
AddOverloadCandidate - Adds the given function to the set of candidate functions, using the given fun...
bool DiagnoseUseOfDecl(NamedDecl *D, ArrayRef< SourceLocation > Locs, const ObjCInterfaceDecl *UnknownObjCClass=nullptr, bool ObjCPropertyAccess=false, bool AvoidPartialAvailabilityChecks=false, ObjCInterfaceDecl *ClassReciever=nullptr, bool SkipTrailingRequiresClause=false)
Determine whether the use of this declaration is valid, and emit any corresponding diagnostics.
bool isCompleteType(SourceLocation Loc, QualType T, CompleteTypeKind Kind=CompleteTypeKind::Default)
bool CanPerformAggregateInitializationForOverloadResolution(const InitializedEntity &Entity, InitListExpr *From)
Determine whether we can perform aggregate initialization for the purposes of overload resolution.
bool isStdInitializerList(QualType Ty, QualType *Element)
Tests whether Ty is an instance of std::initializer_list and, if it is and Element is not NULL,...
void NoteDeletedFunction(FunctionDecl *FD)
Emit a note explaining that this function is deleted.
ExprResult CreateBuiltinArraySubscriptExpr(Expr *Base, SourceLocation LLoc, Expr *Idx, SourceLocation RLoc)
void diagnoseTypo(const TypoCorrection &Correction, const PartialDiagnostic &TypoDiag, bool ErrorRecovery=true)
bool RequireCompleteType(SourceLocation Loc, QualType T, CompleteTypeKind Kind, TypeDiagnoser &Diagnoser)
Ensure that the type T is a complete type.
ReferenceCompareResult CompareReferenceRelationship(SourceLocation Loc, QualType T1, QualType T2, ReferenceConversions *Conv=nullptr)
CompareReferenceRelationship - Compare the two types T1 and T2 to determine whether they are referenc...
PartialDiagnostic PDiag(unsigned DiagID=0)
Build a partial diagnostic.
bool LookupQualifiedName(LookupResult &R, DeclContext *LookupCtx, bool InUnqualifiedLookup=false)
Perform qualified name lookup into a given context.
void checkInitializerLifetime(const InitializedEntity &Entity, Expr *Init)
Check that the lifetime of the initializer (and its subobjects) is sufficient for initializing the en...
SmallVector< ExpressionEvaluationContextRecord, 8 > ExprEvalContexts
A stack of expression evaluation contexts.
QualType getCompletedType(Expr *E)
Get the type of expression E, triggering instantiation to complete the type if necessary – that is,...
SourceManager & SourceMgr
DiagnosticsEngine & Diags
OpenCLOptions & getOpenCLOptions()
static bool CanBeGetReturnObject(const FunctionDecl *FD)
NamespaceDecl * getStdNamespace() const
ExprResult PerformCopyInitialization(const InitializedEntity &Entity, SourceLocation EqualLoc, ExprResult Init, bool TopLevelOfInitList=false, bool AllowExplicit=false)
ExprResult BuildCXXDefaultInitExpr(SourceLocation Loc, FieldDecl *Field)
void EmitRelatedResultTypeNote(const Expr *E)
If the given expression involves a message send to a method with a related result type,...
bool isObjCWritebackConversion(QualType FromType, QualType ToType, QualType &ConvertedType)
Determine whether this is an Objective-C writeback conversion, used for parameter passing when perfor...
QualType SubstAutoTypeDependent(QualType TypeWithAuto)
void runWithSufficientStackSpace(SourceLocation Loc, llvm::function_ref< void()> Fn)
Run some code with "sufficient" stack space.
bool DiagnoseAssignmentResult(AssignConvertType ConvTy, SourceLocation Loc, QualType DstType, QualType SrcType, Expr *SrcExpr, AssignmentAction Action, bool *Complained=nullptr)
DiagnoseAssignmentResult - Emit a diagnostic, if required, for the assignment conversion type specifi...
void MarkFunctionReferenced(SourceLocation Loc, FunctionDecl *Func, bool MightBeOdrUse=true)
Mark a function referenced, and check whether it is odr-used (C++ [basic.def.odr]p2,...
bool CheckConversionToObjCLiteral(QualType DstType, Expr *&SrcExpr, bool Diagnose=true)
bool IsDerivedFrom(SourceLocation Loc, QualType Derived, QualType Base)
Determine whether the type Derived is a C++ class that is derived from the type Base.
bool CanPerformCopyInitialization(const InitializedEntity &Entity, ExprResult Init)
bool CheckExceptionSpecCompatibility(Expr *From, QualType ToType)
void HandleFunctionTypeMismatch(PartialDiagnostic &PDiag, QualType FromType, QualType ToType)
HandleFunctionTypeMismatch - Gives diagnostic information for differeing function types.
DeclContextLookupResult LookupConstructors(CXXRecordDecl *Class)
Look up the constructors for the given class.
CXXConstructorDecl * findInheritingConstructor(SourceLocation Loc, CXXConstructorDecl *BaseCtor, ConstructorUsingShadowDecl *DerivedShadow)
Given a derived-class using shadow declaration for a constructor and the correspnding base class cons...
ValueDecl * tryLookupUnambiguousFieldDecl(RecordDecl *ClassDecl, const IdentifierInfo *MemberOrBase)
Encodes a location in the source.
bool isValid() const
Return true if this is a valid SourceLocation object.
SourceLocation getLocWithOffset(IntTy Offset) const
Return a source location with the specified offset from this SourceLocation.
CharSourceRange getImmediateExpansionRange(SourceLocation Loc) const
Return the start/end of the expansion information for an expansion location.
bool isInSystemHeader(SourceLocation Loc) const
Returns if a SourceLocation is in a system header.
bool isAtStartOfImmediateMacroExpansion(SourceLocation Loc, SourceLocation *MacroBegin=nullptr) const
Returns true if the given MacroID location points at the beginning of the immediate macro expansion.
A trivial tuple used to represent a source range.
void setBegin(SourceLocation b)
SourceLocation getEnd() const
SourceLocation getBegin() const
StandardConversionSequence - represents a standard conversion sequence (C++ 13.3.3....
void setFromType(QualType T)
ImplicitConversionKind Second
Second - The second conversion can be an integral promotion, floating point promotion,...
ImplicitConversionKind First
First – The first conversion can be an lvalue-to-rvalue conversion, array-to-pointer conversion,...
void setAsIdentityConversion()
StandardConversionSequence - Set the standard conversion sequence to the identity conversion.
void setToType(unsigned Idx, QualType T)
NarrowingKind getNarrowingKind(ASTContext &Context, const Expr *Converted, APValue &ConstantValue, QualType &ConstantType, bool IgnoreFloatToIntegralConversion=false) const
Check if this standard conversion sequence represents a narrowing conversion, according to C++11 [dcl...
void setAllToTypes(QualType T)
QualType getToType(unsigned Idx) const
Stmt - This represents one statement.
SourceLocation getEndLoc() const LLVM_READONLY
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
SourceLocation getBeginLoc() const LLVM_READONLY
StringLiteral - This represents a string literal expression, e.g.
unsigned getLength() const
StringLiteralKind getKind() const
int64_t getCodeUnitS(size_t I, uint64_t BitWidth) const
The base class of all kinds of template declarations (e.g., class, function, etc.).
Represents a C++ template name within the type system.
TemplateDecl * getAsTemplateDecl() const
Retrieve the underlying template declaration that this template name refers to, if known.
bool isDependent() const
Determines whether this is a dependent template name.
Represents a type template specialization; the template must be a class template, a type alias templa...
const Type * getTypeForDecl() const
Base wrapper for a particular "section" of type source info.
T getAs() const
Convert to the specified TypeLoc type, returning a null TypeLoc if this TypeLoc is not of the desired...
SourceRange getSourceRange() const LLVM_READONLY
Get the full source range.
SourceLocation getEndLoc() const
Get the end source location.
T getAsAdjusted() const
Convert to the specified TypeLoc type, returning a null TypeLoc if this TypeLoc is not of the desired...
SourceLocation getBeginLoc() const
Get the begin source location.
A container of type source information.
TypeLoc getTypeLoc() const
Return the TypeLoc wrapper for the type source info.
QualType getType() const
Return the type wrapped by this type source info.
The base class of the type hierarchy.
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
bool isBooleanType() const
const Type * getPointeeOrArrayElementType() const
If this is a pointer type, return the pointee type.
bool isIncompleteArrayType() const
bool isSignedIntegerType() const
Return true if this is an integer type that is signed, according to C99 6.2.5p4 [char,...
bool isIntegralOrUnscopedEnumerationType() const
Determine whether this type is an integral or unscoped enumeration type.
bool isRValueReferenceType() const
bool isConstantArrayType() const
bool isPointerType() const
bool isIntegerType() const
isIntegerType() does not include complex integers (a GCC extension).
const T * castAs() const
Member-template castAs<specific type>.
bool isReferenceType() const
bool isScalarType() const
const CXXRecordDecl * getPointeeCXXRecordDecl() const
If this is a pointer or reference to a RecordType, return the CXXRecordDecl that the type refers to.
bool isSizelessBuiltinType() const
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
bool isExtVectorType() const
bool isOCLIntelSubgroupAVCType() const
bool isLValueReferenceType() const
bool isOpenCLSpecificType() const
bool isDependentType() const
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
bool isAggregateType() const
Determines whether the type is a C++ aggregate type or C aggregate or union type.
bool isAnyComplexType() const
DeducedType * getContainedDeducedType() const
Get the DeducedType whose type will be deduced for a variable with an initializer of this type.
const Type * getBaseElementTypeUnsafe() const
Get the base element type of this type, potentially discarding type qualifiers.
bool isAtomicType() const
bool isFunctionProtoType() const
bool isObjCObjectType() const
const ArrayType * getAsArrayTypeUnsafe() const
A variant of getAs<> for array types which silently discards qualifiers from the outermost type.
bool isIncompleteType(NamedDecl **Def=nullptr) const
Types are partitioned into 3 broad categories (C99 6.2.5p1): object types, function types,...
bool isFunctionType() const
bool isObjCObjectPointerType() const
bool isVectorType() const
bool isFloatingType() const
bool isUnsignedIntegerType() const
Return true if this is an integer type that is unsigned, according to C99 6.2.5p6 [which returns true...
const T * getAs() const
Member-template getAs<specific type>'.
const Type * getUnqualifiedDesugaredType() const
Return the specified type with any "sugar" removed from the type, removing any typedefs,...
bool isNullPtrType() const
bool isRecordType() const
bool isObjCRetainableType() const
Simple class containing the result of Sema::CorrectTypo.
DeclClass * getCorrectionDeclAs() const
UnaryOperator - This represents the unary-expression's (except sizeof and alignof),...
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
bool isInitCapture() const
Whether this variable is the implicit variable for a lambda init-capture.
Represents a variable declaration or definition.
const Expr * getInit() const
bool hasLocalStorage() const
Returns true if a variable with function scope is a non-static local variable.
Represents a C array with a specified size that is not an integer-constant-expression.
Represents a GCC generic vector type.
unsigned getNumElements() const
void Profile(llvm::FoldingSetNodeID &ID)
VectorKind getVectorKind() const
QualType getElementType() const
Defines the clang::TargetInfo interface.
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
const AstTypeMatcher< ArrayType > arrayType
Matches all kinds of arrays.
const internal::VariadicDynCastAllOfMatcher< Stmt, Expr > expr
Matches expressions.
bool Zero(InterpState &S, CodePtr OpPC)
The JSON file list parser is used to communicate input to InstallAPI.
@ Seq
'seq' clause, allowed on 'loop' and 'routine' directives.
OverloadedOperatorKind
Enumeration specifying the different kinds of C++ overloaded operators.
OverloadingResult
OverloadingResult - Capture the result of performing overload resolution.
@ OR_Deleted
Succeeded, but refers to a deleted function.
@ OR_Success
Overload resolution succeeded.
@ OR_Ambiguous
Ambiguous candidates found.
@ OR_No_Viable_Function
No viable function found.
bool isCompoundAssignmentOperator(OverloadedOperatorKind Kind)
Determine if this is a compound assignment operator.
@ ovl_fail_bad_conversion
@ OCD_AmbiguousCandidates
Requests that only tied-for-best candidates be shown.
@ OCD_AllCandidates
Requests that all candidates be shown.
LLVM_READONLY bool isUppercase(unsigned char c)
Return true if this character is an uppercase ASCII letter: [A-Z].
@ LCK_ByRef
Capturing by reference.
@ SD_Automatic
Automatic storage duration (most local variables).
@ Result
The result type of a method or function.
@ ICK_Integral_Conversion
Integral conversions (C++ [conv.integral])
@ ICK_Floating_Integral
Floating-integral conversions (C++ [conv.fpint])
@ ICK_Array_To_Pointer
Array-to-pointer conversion (C++ [conv.array])
@ ICK_Lvalue_To_Rvalue
Lvalue-to-rvalue conversion (C++ [conv.lval])
@ ICK_Writeback_Conversion
Objective-C ARC writeback conversion.
ActionResult< Expr * > ExprResult
CastKind
CastKind - The kind of operation required for a conversion.
ExprValueKind
The categorization of expression values, currently following the C++11 scheme.
@ VK_PRValue
A pr-value expression (in the C++11 taxonomy) produces a temporary value.
@ VK_XValue
An x-value expression is a reference to an object with independent storage but which can be "moved",...
@ VK_LValue
An l-value expression is a reference to an object with independent storage.
Expr * IgnoreParensSingleStep(Expr *E)
@ NK_Not_Narrowing
Not a narrowing conversion.
@ NK_Constant_Narrowing
A narrowing conversion, because a constant expression got narrowed.
@ NK_Dependent_Narrowing
Cannot tell whether this is a narrowing conversion because the expression is value-dependent.
@ NK_Type_Narrowing
A narrowing conversion by virtue of the source and destination types.
@ NK_Variable_Narrowing
A narrowing conversion, because a non-constant-expression variable might have got narrowed.
bool declaresSameEntity(const Decl *D1, const Decl *D2)
Determine whether two declarations declare the same entity.
std::pair< SourceLocation, PartialDiagnostic > PartialDiagnosticAt
A partial diagnostic along with the source location where this diagnostic occurs.
ConstructorInfo getConstructorInfo(NamedDecl *ND)
@ Class
The "class" keyword introduces the elaborated-type-specifier.
@ Braces
New-expression has a C++11 list-initializer.
MutableArrayRef< Expr * > MultiExprArg
CXXConstructorDecl * Constructor
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspon...
EvalResult is a struct with detailed info about an evaluated expression.
APValue Val
Val - This is the value the expression can be folded to.
bool HadMultipleCandidates
OverloadCandidate - A single candidate in an overload set (C++ 13.3).
bool Viable
Viable - True to indicate that this overload candidate is viable.
unsigned char FailureKind
FailureKind - The reason why this candidate is not viable.
ConversionSequenceList Conversions
The conversion sequences used to convert the function arguments to the function parameters.
ReferenceConversions
The conversions that would be performed on an lvalue of type T2 when binding a reference of type T1 t...
StandardConversionSequence After
After - Represents the standard conversion that occurs after the actual user-defined conversion.