33#include "llvm/ADT/APInt.h"
34#include "llvm/ADT/FoldingSet.h"
35#include "llvm/ADT/PointerIntPair.h"
36#include "llvm/ADT/STLForwardCompat.h"
37#include "llvm/ADT/SmallString.h"
38#include "llvm/ADT/SmallVector.h"
39#include "llvm/ADT/StringExtras.h"
40#include "llvm/Support/ErrorHandling.h"
41#include "llvm/Support/raw_ostream.h"
77 if (!isa<ConstantArrayType>(AT) && !isa<IncompleteArrayType>(AT))
95 auto IsCharOrUnsignedChar = [](
const QualType &
T) {
96 const BuiltinType *BT = dyn_cast<BuiltinType>(
T.getTypePtr());
101 case StringLiteralKind::UTF8:
111 case StringLiteralKind::Ordinary:
115 return (SL->
getKind() == StringLiteralKind::UTF8 &&
129 case StringLiteralKind::UTF16:
137 case StringLiteralKind::UTF32:
145 case StringLiteralKind::Wide:
153 case StringLiteralKind::Unevaluated:
154 assert(
false &&
"Unevaluated string literal in initialization");
158 llvm_unreachable(
"missed a StringLiteral kind?");
179 if (isa<StringLiteral>(
E) || isa<ObjCEncodeExpr>(
E))
190 if (isa<CompoundLiteralExpr>(
E))
205 if (
const auto *VD = dyn_cast_if_present<VarDecl>(
D); VD && VD->isConstexpr())
215 Sema &S,
bool CheckC23ConstexprInit =
false) {
217 auto *ConstantArrayTy =
219 uint64_t StrLength = ConstantArrayTy->getZExtSize();
221 if (CheckC23ConstexprInit)
228 llvm::APInt ConstVal(32, StrLength);
254 diag::err_initializer_string_for_char_array_too_long)
260 diag::ext_initializer_string_for_char_array_too_long)
308class InitListChecker {
310 bool hadError =
false;
312 bool TreatUnavailableAsInvalid;
313 bool InOverloadResolution;
318 unsigned CurEmbedIndex = 0;
329 unsigned &StructuredIndex);
333 bool TopLevelObject =
false);
336 bool SubobjectIsDesignatorContext,
339 unsigned &StructuredIndex,
340 bool TopLevelObject =
false);
345 unsigned &StructuredIndex,
346 bool DirectlyDesignated =
false);
351 unsigned &StructuredIndex);
356 unsigned &StructuredIndex);
361 unsigned &StructuredIndex);
365 unsigned &StructuredIndex);
370 bool SubobjectIsDesignatorContext,
unsigned &Index,
372 unsigned &StructuredIndex,
373 bool TopLevelObject =
false);
376 llvm::APSInt elementIndex,
377 bool SubobjectIsDesignatorContext,
unsigned &Index,
379 unsigned &StructuredIndex);
385 llvm::APSInt *NextElementIndex,
388 unsigned &StructuredIndex,
389 bool FinishSubobjectInit,
390 bool TopLevelObject);
394 unsigned StructuredIndex,
396 bool IsFullyOverwritten =
false);
397 void UpdateStructuredListElement(
InitListExpr *StructuredList,
398 unsigned &StructuredIndex,
402 unsigned ExpectedNumInits);
403 int numArrayElements(
QualType DeclType);
404 int numStructUnionElements(
QualType DeclType);
412 bool UnionOverride =
false,
413 bool FullyOverwritten =
true) {
418 ? (UnionOverride ? diag::ext_initializer_union_overrides
419 : diag::ext_initializer_overrides)
420 : diag::warn_initializer_overrides;
422 if (InOverloadResolution && SemaRef.
getLangOpts().CPlusPlus) {
443 DiagID = diag::err_initializer_overrides_destructed;
463 << NewInitRange << FullyOverwritten << OldInit->
getType();
492 bool FillWithNoInit);
493 void FillInEmptyInitForField(
unsigned Init,
FieldDecl *Field,
496 bool FillWithNoInit =
false);
500 bool FillWithNoInit =
false);
503 bool TopLevelObject);
508 Expr *Result =
nullptr;
520 assert(AType &&
"expected array type when initializing array");
522 if (
const auto *CAType = dyn_cast<ConstantArrayType>(AType))
523 ElsCount = std::min(CAType->getSize().getZExtValue(),
524 ElsCount - CurEmbedIndex);
534 CurEmbedIndex, ElsCount);
535 CurEmbedIndex += ElsCount;
546 bool VerifyOnly,
bool TreatUnavailableAsInvalid,
547 bool InOverloadResolution =
false,
552 : InitListChecker(S, Entity, IL,
T,
true,
555 &AggrDeductionCandidateParamTypes) {}
557 bool HadError() {
return hadError; }
561 InitListExpr *getFullyStructuredList()
const {
return FullyStructuredList; }
578 bool EmptyInitList = SemaRef.
getLangOpts().CPlusPlus11 &&
591 InitExpr = VerifyOnly
609 if (!InitSeq && EmptyInitList && InitSeq.getFailureKind() ==
613 InitSeq.getFailedCandidateSet()
614 .BestViableFunction(SemaRef,
Kind.getLocation(), Best);
616 assert(O ==
OR_Success &&
"Inconsistent overload resolution");
623 bool IsInStd =
false;
625 ND && !IsInStd; ND = dyn_cast<NamespaceDecl>(ND->getParent())) {
630 if (IsInStd && llvm::StringSwitch<bool>(R->
getName())
631 .Cases(
"basic_string",
"deque",
"forward_list",
true)
632 .Cases(
"list",
"map",
"multimap",
"multiset",
true)
633 .Cases(
"priority_queue",
"queue",
"set",
"stack",
true)
634 .Cases(
"unordered_map",
"unordered_set",
"vector",
true)
636 InitSeq.InitializeFrom(
640 TreatUnavailableAsInvalid);
645 diag::warn_invalid_initializer_from_system_header);
648 diag::note_used_in_initialization_here);
650 SemaRef.
Diag(
Loc, diag::note_used_in_initialization_here);
657 InitSeq.Diagnose(SemaRef, Entity, Kind, SubInit);
660 diag::note_in_omitted_aggregate_initializer)
663 bool IsTrailingArrayNewMember =
666 SemaRef.
Diag(
Loc, diag::note_in_omitted_aggregate_initializer)
667 << (IsTrailingArrayNewMember ? 2 : 0)
676 : InitSeq.Perform(SemaRef, Entity,
Kind, SubInit);
684 if (FullyStructuredList)
686 PerformEmptyInit(
Loc, Entity);
689void InitListChecker::FillInEmptyInitForBase(
692 bool &RequiresSecondPass,
bool FillWithNoInit) {
699 : PerformEmptyInit(ILE->
getEndLoc(), BaseEntity);
706 assert(Init < ILE->getNumInits() &&
"should have been expanded");
711 FillInEmptyInitializations(BaseEntity, InnerILE, RequiresSecondPass,
712 ILE,
Init, FillWithNoInit);
714 dyn_cast<DesignatedInitUpdateExpr>(ILE->
getInit(
Init))) {
715 FillInEmptyInitializations(BaseEntity, InnerDIUE->getUpdater(),
716 RequiresSecondPass, ILE,
Init,
721void InitListChecker::FillInEmptyInitForField(
unsigned Init,
FieldDecl *Field,
724 bool &RequiresSecondPass,
725 bool FillWithNoInit) {
733 if (!RType->getDecl()->isUnion())
734 assert((
Init < NumInits || VerifyOnly) &&
735 "This ILE should have been expanded");
737 if (FillWithNoInit) {
738 assert(!VerifyOnly &&
"should not fill with no-init in verify-only mode");
750 if (
Field->hasInClassInitializer()) {
764 RequiresSecondPass =
true;
769 if (
Field->getType()->isReferenceType()) {
775 SemaRef.
Diag(
Loc, diag::err_init_reference_member_uninitialized)
779 SemaRef.
Diag(
Field->getLocation(), diag::note_uninit_reference_member);
791 if (hadError || VerifyOnly) {
793 }
else if (
Init < NumInits) {
795 }
else if (!isa<ImplicitValueInitExpr>(MemberInit.
get())) {
801 RequiresSecondPass =
true;
805 FillInEmptyInitializations(MemberEntity, InnerILE,
806 RequiresSecondPass, ILE,
Init, FillWithNoInit);
808 dyn_cast<DesignatedInitUpdateExpr>(ILE->
getInit(
Init))) {
809 FillInEmptyInitializations(MemberEntity, InnerDIUE->getUpdater(),
810 RequiresSecondPass, ILE,
Init,
821 bool &RequiresSecondPass,
824 bool FillWithNoInit) {
826 "Should not have void type");
830 if (FillWithNoInit && VerifyOnly)
840 struct UpdateOuterILEWithUpdatedInit {
843 ~UpdateOuterILEWithUpdatedInit() {
847 } UpdateOuterRAII = {OuterILE, OuterIndex};
858 RequiresSecondPass, FillWithNoInit);
860 assert((!RDecl->
isUnion() || !isa<CXXRecordDecl>(RDecl) ||
861 !cast<CXXRecordDecl>(RDecl)->hasInClassInitializer()) &&
862 "We should have computed initialized fields already");
866 unsigned NumElems = numStructUnionElements(ILE->
getType());
874 if (
auto *CXXRD = dyn_cast<CXXRecordDecl>(RDecl)) {
875 for (
auto &
Base : CXXRD->bases()) {
879 FillInEmptyInitForBase(
Init,
Base, Entity, ILE, RequiresSecondPass,
885 for (
auto *Field : RDecl->
fields()) {
886 if (
Field->isUnnamedBitField())
892 FillInEmptyInitForField(
Init, Field, Entity, ILE, RequiresSecondPass,
914 ElementType = AType->getElementType();
915 if (
const auto *CAType = dyn_cast<ConstantArrayType>(AType))
916 NumElements = CAType->getZExtSize();
924 ElementType = VType->getElementType();
925 NumElements = VType->getNumElements();
931 bool SkipEmptyInitChecks =
false;
944 if (!InitExpr && Init < NumInits && ILE->hasArrayFiller())
949 if (SkipEmptyInitChecks)
952 Expr *Filler =
nullptr;
958 PerformEmptyInit(ILE->
getEndLoc(), ElementEntity);
969 }
else if (VerifyOnly) {
970 SkipEmptyInitChecks =
true;
971 }
else if (
Init < NumInits) {
986 if (!isa<ImplicitValueInitExpr>(Filler) && !isa<NoInitExpr>(Filler)) {
992 RequiresSecondPass =
true;
996 = dyn_cast_or_null<InitListExpr>(InitExpr)) {
997 FillInEmptyInitializations(ElementEntity, InnerILE, RequiresSecondPass,
998 ILE,
Init, FillWithNoInit);
1000 dyn_cast_or_null<DesignatedInitUpdateExpr>(InitExpr)) {
1001 FillInEmptyInitializations(ElementEntity, InnerDIUE->getUpdater(),
1002 RequiresSecondPass, ILE,
Init,
1010 if (isa_and_nonnull<DesignatedInitExpr>(
Init))
1015InitListChecker::InitListChecker(
1017 bool VerifyOnly,
bool TreatUnavailableAsInvalid,
bool InOverloadResolution,
1019 : SemaRef(S), VerifyOnly(VerifyOnly),
1020 TreatUnavailableAsInvalid(TreatUnavailableAsInvalid),
1021 InOverloadResolution(InOverloadResolution),
1022 AggrDeductionCandidateParamTypes(AggrDeductionCandidateParamTypes) {
1024 FullyStructuredList =
1033 CheckExplicitInitList(Entity, IL,
T, FullyStructuredList,
1036 if (!hadError && !AggrDeductionCandidateParamTypes && FullyStructuredList) {
1037 bool RequiresSecondPass =
false;
1038 FillInEmptyInitializations(Entity, FullyStructuredList, RequiresSecondPass,
1040 if (RequiresSecondPass && !hadError)
1041 FillInEmptyInitializations(Entity, FullyStructuredList,
1042 RequiresSecondPass,
nullptr, 0);
1044 if (hadError && FullyStructuredList)
1048int InitListChecker::numArrayElements(
QualType DeclType) {
1050 int maxElements = 0x7FFFFFFF;
1053 maxElements =
static_cast<int>(CAT->getZExtSize());
1058int InitListChecker::numStructUnionElements(
QualType DeclType) {
1060 int InitializableMembers = 0;
1061 if (
auto *CXXRD = dyn_cast<CXXRecordDecl>(structDecl))
1062 InitializableMembers += CXXRD->getNumBases();
1063 for (
const auto *Field : structDecl->
fields())
1064 if (!
Field->isUnnamedBitField())
1065 ++InitializableMembers;
1068 return std::min(InitializableMembers, 1);
1074 return RT->getDecl();
1076 return Inject->getDecl();
1106 if (
CXXRecordDecl *CXXRD = dyn_cast<CXXRecordDecl>(ParentRD)) {
1107 if (CXXRD->getNumBases()) {
1111 auto FieldIt = ParentRD->field_begin();
1112 assert(FieldIt != ParentRD->field_end() &&
1113 "no fields but have initializer for member?");
1114 return ++FieldIt == ParentRD->field_end();
1130 unsigned &StructuredIndex) {
1131 int maxElements = 0;
1134 maxElements = numArrayElements(
T);
1136 maxElements = numStructUnionElements(
T);
1140 llvm_unreachable(
"CheckImplicitInitList(): Illegal type");
1142 if (maxElements == 0) {
1145 diag::err_implicit_empty_initializer);
1152 InitListExpr *StructuredSubobjectInitList = getStructuredSubobjectInit(
1153 ParentIList, Index,
T, StructuredList, StructuredIndex,
1156 unsigned StructuredSubobjectInitIndex = 0;
1159 unsigned StartIndex = Index;
1160 CheckListElementTypes(Entity, ParentIList,
T,
1162 StructuredSubobjectInitList,
1163 StructuredSubobjectInitIndex);
1165 if (StructuredSubobjectInitList) {
1166 StructuredSubobjectInitList->
setType(
T);
1168 unsigned EndIndex = (Index == StartIndex? StartIndex : Index - 1);
1171 if (EndIndex < ParentIList->getNumInits() &&
1172 ParentIList->
getInit(EndIndex)) {
1183 diag::warn_missing_braces)
1189 StructuredSubobjectInitList->
getEndLoc()),
1195 if (!VerifyOnly && CXXRD && CXXRD->hasUserDeclaredConstructor()) {
1197 diag::warn_cxx20_compat_aggregate_init_with_ctors)
1213 unsigned DiagID = 0;
1225 DiagID = diag::warn_braces_around_init;
1232 DiagID = diag::warn_braces_around_init;
1258 llvm_unreachable(
"unexpected braced scalar init");
1277 bool TopLevelObject) {
1278 unsigned Index = 0, StructuredIndex = 0;
1279 CheckListElementTypes(Entity, IList,
T,
true,
1280 Index, StructuredList, StructuredIndex, TopLevelObject);
1281 if (StructuredList) {
1287 StructuredList->
setType(ExprTy);
1295 bool ExtraInitsIsError = SemaRef.
getLangOpts().CPlusPlus ||
1297 hadError = ExtraInitsIsError;
1300 }
else if (StructuredIndex == 1 &&
1305 ? diag::err_excess_initializers_in_char_array_initializer
1306 : diag::ext_excess_initializers_in_char_array_initializer;
1310 unsigned DK = ExtraInitsIsError
1311 ? diag::err_excess_initializers_for_sizeless_type
1312 : diag::ext_excess_initializers_for_sizeless_type;
1322 unsigned DK = ExtraInitsIsError ? diag::err_excess_initializers
1323 : diag::ext_excess_initializers;
1331 !isa<InitListExpr>(IList->
getInit(0)))
1337 if (CXXRD && CXXRD->hasUserDeclaredConstructor()) {
1340 bool HasEquivCtor =
false;
1346 if (!HasEquivCtor) {
1348 diag::warn_cxx20_compat_aggregate_init_with_ctors)
1358 bool SubobjectIsDesignatorContext,
1361 unsigned &StructuredIndex,
1362 bool TopLevelObject) {
1366 CheckComplexType(Entity, IList, DeclType, Index,
1367 StructuredList, StructuredIndex);
1369 CheckScalarType(Entity, IList, DeclType, Index,
1370 StructuredList, StructuredIndex);
1372 CheckVectorType(Entity, IList, DeclType, Index,
1373 StructuredList, StructuredIndex);
1374 }
else if (
const RecordDecl *RD = getRecordDecl(DeclType)) {
1380 "non-aggregate records should be handed in CheckSubElementType");
1381 if (
auto *CXXRD = dyn_cast<CXXRecordDecl>(RD))
1382 Bases = CXXRD->bases();
1384 Bases = cast<CXXRecordDecl>(RD)->bases();
1386 CheckStructUnionTypes(Entity, IList, DeclType, Bases, RD->field_begin(),
1387 SubobjectIsDesignatorContext, Index, StructuredList,
1388 StructuredIndex, TopLevelObject);
1393 CheckArrayType(Entity, IList, DeclType, Zero,
1394 SubobjectIsDesignatorContext, Index,
1395 StructuredList, StructuredIndex);
1400 SemaRef.
Diag(IList->
getBeginLoc(), diag::err_illegal_initializer_type)
1404 CheckReferenceType(Entity, IList, DeclType, Index,
1405 StructuredList, StructuredIndex);
1408 SemaRef.
Diag(IList->
getBeginLoc(), diag::err_init_objc_class) << DeclType;
1413 CheckScalarType(Entity, IList, DeclType, Index, StructuredList,
1420 assert(AggrDeductionCandidateParamTypes);
1421 AggrDeductionCandidateParamTypes->push_back(DeclType);
1424 SemaRef.
Diag(IList->
getBeginLoc(), diag::err_illegal_initializer_type)
1435 unsigned &StructuredIndex,
1436 bool DirectlyDesignated) {
1440 return CheckReferenceType(Entity, IList, ElemType, Index,
1441 StructuredList, StructuredIndex);
1444 if (SubInitList->getNumInits() == 1 &&
1449 expr = SubInitList->getInit(0);
1452 }
else if (isa<ImplicitValueInitExpr>(
expr)) {
1456 "found implicit initialization for the wrong type");
1457 UpdateStructuredListElement(StructuredList, StructuredIndex,
expr);
1479 if (TmpEntity.getType()->isDependentType()) {
1484 assert(AggrDeductionCandidateParamTypes);
1498 if (isa<InitListExpr, DesignatedInitExpr>(
expr) ||
1499 !isa_and_present<ConstantArrayType>(
1502 AggrDeductionCandidateParamTypes->push_back(ElemType);
1514 if (
Seq || isa<InitListExpr>(
expr)) {
1515 if (
auto *Embed = dyn_cast<EmbedExpr>(
expr)) {
1516 expr = HandleEmbed(Embed, Entity);
1520 if (Result.isInvalid())
1523 UpdateStructuredListElement(StructuredList, StructuredIndex,
1524 Result.getAs<
Expr>());
1527 }
else if (StructuredList) {
1528 UpdateStructuredListElement(StructuredList, StructuredIndex,
1533 if (AggrDeductionCandidateParamTypes)
1534 AggrDeductionCandidateParamTypes->push_back(ElemType);
1542 return CheckScalarType(Entity, IList, ElemType, Index,
1543 StructuredList, StructuredIndex);
1557 UpdateStructuredListElement(StructuredList, StructuredIndex,
expr);
1586 UpdateStructuredListElement(StructuredList, StructuredIndex,
1604 CheckImplicitInitList(Entity, IList, ElemType, Index, StructuredList,
1609 if (DirectlyDesignated && SemaRef.
getLangOpts().CPlusPlus && !hadError) {
1610 if (InOverloadResolution)
1614 diag::ext_designated_init_brace_elision)
1615 <<
expr->getSourceRange()
1630 assert(
Copy.isInvalid() &&
1631 "expected non-aggregate initialization to fail");
1643 unsigned &StructuredIndex) {
1644 assert(Index == 0 &&
"Index in explicit init list must be zero");
1654 return CheckScalarType(Entity, IList, DeclType, Index, StructuredList,
1659 if (!SemaRef.
getLangOpts().CPlusPlus && !VerifyOnly)
1668 for (
unsigned i = 0; i < 2; ++i) {
1670 CheckSubElementType(ElementEntity, IList, elementType, Index,
1671 StructuredList, StructuredIndex);
1679 unsigned &StructuredIndex) {
1686 ? diag::warn_cxx98_compat_empty_sizeless_initializer
1687 : diag::err_empty_sizeless_initializer)
1692 ? diag::warn_cxx98_compat_empty_scalar_initializer
1693 : diag::err_empty_scalar_initializer)
1709 SemaRef.
Diag(SubIList->getBeginLoc(), diag::ext_many_braces_around_init)
1712 CheckScalarType(Entity, SubIList, DeclType, Index, StructuredList,
1715 }
else if (isa<DesignatedInitExpr>(
expr)) {
1718 diag::err_designator_for_scalar_or_sizeless_init)
1720 <<
expr->getSourceRange();
1725 }
else if (
auto *Embed = dyn_cast<EmbedExpr>(
expr)) {
1726 expr = HandleEmbed(Embed, Entity);
1732 Result = getDummyInit();
1741 Expr *ResultExpr =
nullptr;
1743 if (Result.isInvalid())
1746 ResultExpr = Result.getAs<
Expr>();
1748 if (ResultExpr !=
expr && !VerifyOnly && !CurEmbed) {
1751 IList->
setInit(Index, ResultExpr);
1755 UpdateStructuredListElement(StructuredList, StructuredIndex, ResultExpr);
1758 if (AggrDeductionCandidateParamTypes)
1759 AggrDeductionCandidateParamTypes->push_back(DeclType);
1766 unsigned &StructuredIndex) {
1774 diag::err_init_reference_member_uninitialized)
1796 Result = getDummyInit();
1805 if (Result.isInvalid())
1810 if (!VerifyOnly &&
expr)
1813 UpdateStructuredListElement(StructuredList, StructuredIndex,
expr);
1815 if (AggrDeductionCandidateParamTypes)
1816 AggrDeductionCandidateParamTypes->push_back(DeclType);
1823 unsigned &StructuredIndex) {
1826 unsigned numEltsInit = 0;
1831 CheckEmptyInitializable(
1841 if (!isa<InitListExpr>(
Init) &&
Init->getType()->isVectorType()) {
1845 Result = getDummyInit();
1854 Expr *ResultExpr =
nullptr;
1855 if (Result.isInvalid())
1858 ResultExpr = Result.getAs<
Expr>();
1860 if (ResultExpr !=
Init && !VerifyOnly) {
1863 IList->
setInit(Index, ResultExpr);
1866 UpdateStructuredListElement(StructuredList, StructuredIndex, ResultExpr);
1868 if (AggrDeductionCandidateParamTypes)
1869 AggrDeductionCandidateParamTypes->push_back(elementType);
1876 for (
unsigned i = 0; i < maxElements; ++i, ++numEltsInit) {
1879 CheckEmptyInitializable(ElementEntity, IList->
getEndLoc());
1884 CheckSubElementType(ElementEntity, IList, elementType, Index,
1885 StructuredList, StructuredIndex);
1893 if (isBigEndian && (
T->getVectorKind() == VectorKind::Neon ||
1894 T->getVectorKind() == VectorKind::NeonPoly)) {
1906 diag::warn_neon_vector_initializer_non_portable);
1908 const char *typeCode;
1918 llvm_unreachable(
"Invalid element type!");
1922 ? diag::note_neon_vector_initializer_non_portable_q
1923 : diag::note_neon_vector_initializer_non_portable)
1924 << typeCode << typeSize;
1934 for (
unsigned i = 0; i < maxElements; ++i) {
1943 CheckSubElementType(ElementEntity, IList, elementType, Index,
1944 StructuredList, StructuredIndex);
1956 CheckSubElementType(ElementEntity, IList, VecType, Index,
1957 StructuredList, StructuredIndex);
1958 numEltsInit += numIElts;
1963 if (numEltsInit != maxElements) {
1966 diag::err_vector_incorrect_num_initializers)
1967 << (numEltsInit < maxElements) << maxElements << numEltsInit;
1993 SemaRef.
PDiag(diag::err_access_dtor_temp)
2007 InitType =
Parent->getType();
2013 ExprList.size() == 1
2014 ? dyn_cast_if_present<EmbedExpr>(ExprList[0]->IgnoreParens())
2023 const bool TypesMatch =
2034 llvm::APSInt elementIndex,
2035 bool SubobjectIsDesignatorContext,
2038 unsigned &StructuredIndex) {
2056 if (Index < IList->getNumInits()) {
2069 if (StructuredList) {
2070 UpdateStructuredListElement(StructuredList, StructuredIndex,
2075 if (AggrDeductionCandidateParamTypes)
2076 AggrDeductionCandidateParamTypes->push_back(DeclType);
2097 SemaRef.
Diag(VAT->getSizeExpr()->getBeginLoc(),
2098 diag::err_variable_object_no_init)
2099 << VAT->getSizeExpr()->getSourceRange();
2108 llvm::APSInt maxElements(elementIndex.getBitWidth(),
2109 elementIndex.isUnsigned());
2110 bool maxElementsKnown =
false;
2112 maxElements = CAT->getSize();
2113 elementIndex = elementIndex.extOrTrunc(maxElements.getBitWidth());
2114 elementIndex.setIsUnsigned(maxElements.isUnsigned());
2115 maxElementsKnown =
true;
2119 while (Index < IList->getNumInits()) {
2125 if (!SubobjectIsDesignatorContext)
2130 if (CheckDesignatedInitializer(Entity, IList, DIE, 0,
2131 DeclType,
nullptr, &elementIndex, Index,
2132 StructuredList, StructuredIndex,
true,
2138 if (elementIndex.getBitWidth() > maxElements.getBitWidth())
2139 maxElements = maxElements.extend(elementIndex.getBitWidth());
2140 else if (elementIndex.getBitWidth() < maxElements.getBitWidth())
2141 elementIndex = elementIndex.extend(maxElements.getBitWidth());
2142 elementIndex.setIsUnsigned(maxElements.isUnsigned());
2146 if (!maxElementsKnown && elementIndex > maxElements)
2147 maxElements = elementIndex;
2154 if (maxElementsKnown && elementIndex == maxElements)
2158 SemaRef.
Context, StructuredIndex, Entity);
2160 unsigned EmbedElementIndexBeforeInit = CurEmbedIndex;
2162 CheckSubElementType(ElementEntity, IList, elementType, Index,
2163 StructuredList, StructuredIndex);
2168 elementIndex + CurEmbedIndex - EmbedElementIndexBeforeInit - 1;
2170 auto Embed = cast<EmbedExpr>(
Init);
2172 EmbedElementIndexBeforeInit - 1;
2178 if (!maxElementsKnown && elementIndex > maxElements)
2179 maxElements = elementIndex;
2184 llvm::APSInt
Zero(maxElements.getBitWidth(), maxElements.isUnsigned());
2188 SemaRef.
Diag(IList->
getBeginLoc(), diag::ext_typecheck_zero_array_size);
2192 elementType, maxElements,
nullptr, ArraySizeModifier::Normal, 0);
2199 if ((maxElementsKnown && elementIndex < maxElements) ||
2201 CheckEmptyInitializable(
2210 bool TopLevelObject) {
2212 unsigned FlexArrayDiag;
2213 if (isa<InitListExpr>(InitExpr) &&
2214 cast<InitListExpr>(InitExpr)->getNumInits() == 0) {
2216 FlexArrayDiag = diag::ext_flexible_array_init;
2217 }
else if (!TopLevelObject) {
2219 FlexArrayDiag = diag::err_flexible_array_init;
2222 FlexArrayDiag = diag::err_flexible_array_init;
2223 }
else if (cast<VarDecl>(Entity.
getDecl())->hasLocalStorage()) {
2225 FlexArrayDiag = diag::err_flexible_array_init;
2228 FlexArrayDiag = diag::ext_flexible_array_init;
2234 SemaRef.
Diag(
Field->getLocation(), diag::note_flexible_array_member)
2238 return FlexArrayDiag != diag::ext_flexible_array_init;
2241void InitListChecker::CheckStructUnionTypes(
2244 bool SubobjectIsDesignatorContext,
unsigned &Index,
2245 InitListExpr *StructuredList,
unsigned &StructuredIndex,
2246 bool TopLevelObject) {
2247 const RecordDecl *RD = getRecordDecl(DeclType);
2269 if (isa<CXXRecordDecl>(RD) &&
2270 cast<CXXRecordDecl>(RD)->hasInClassInitializer()) {
2271 if (!StructuredList)
2274 Field != FieldEnd; ++Field) {
2275 if (
Field->hasInClassInitializer() ||
2276 (
Field->isAnonymousStructOrUnion() &&
2277 Field->getType()->getAsCXXRecordDecl()->hasInClassInitializer())) {
2283 llvm_unreachable(
"Couldn't find in-class initializer");
2289 Field != FieldEnd; ++Field) {
2290 if (!
Field->isUnnamedBitField()) {
2291 CheckEmptyInitializable(
2302 bool InitializedSomething =
false;
2305 for (
auto I = Bases.begin(),
E = Bases.end(); I !=
E; ++I) {
2311 if (isa_and_nonnull<DesignatedInitExpr>(
Init))
2328 if (AggrDeductionCandidateParamTypes &&
Base.isPackExpansion()) {
2329 AggrDeductionCandidateParamTypes->push_back(
2334 if (Index < IList->getNumInits())
2346 CheckSubElementType(BaseEntity, IList,
Base.getType(), Index,
2347 StructuredList, StructuredIndex);
2348 InitializedSomething =
true;
2350 CheckEmptyInitializable(BaseEntity, InitLoc);
2365 size_t NumRecordDecls = llvm::count_if(RD->
decls(), [&](
const Decl *
D) {
2366 return isa<FieldDecl>(D) || isa<RecordDecl>(D);
2368 bool HasDesignatedInit =
false;
2372 while (Index < IList->getNumInits()) {
2380 if (!SubobjectIsDesignatorContext)
2383 HasDesignatedInit =
true;
2387 bool DesignatedInitFailed = CheckDesignatedInitializer(
2388 Entity, IList, DIE, 0, DeclType, &Field,
nullptr, Index,
2389 StructuredList, StructuredIndex,
true, TopLevelObject);
2390 if (DesignatedInitFailed)
2395 if (!VerifyOnly &&
D->isFieldDesignator()) {
2397 InitializedFields.insert(F);
2398 if (!DesignatedInitFailed) {
2407 InitializedSomething =
true;
2424 if (NumRecordDecls == 1)
2426 if (
const auto *IL = dyn_cast<IntegerLiteral>(I))
2427 return IL->getValue().isZero();
2435 SemaRef.
Diag(InitLoc, diag::err_non_designated_init_used);
2440 if (Field == FieldEnd) {
2446 if (InitializedSomething && RD->
isUnion())
2450 if (
Field->getType()->isIncompleteArrayType())
2453 if (
Field->isUnnamedBitField()) {
2462 InvalidUse = !SemaRef.
CanUseDecl(*Field, TreatUnavailableAsInvalid);
2483 CheckSubElementType(MemberEntity, IList,
Field->getType(), Index,
2484 StructuredList, StructuredIndex);
2485 InitializedSomething =
true;
2486 InitializedFields.insert(*Field);
2488 if (RD->
isUnion() && StructuredList) {
2499 bool IsCDesignatedInitializer =
2500 HasDesignatedInit && !SemaRef.
getLangOpts().CPlusPlus;
2501 if (!VerifyOnly && InitializedSomething && !RD->
isUnion() &&
2503 !IsCDesignatedInitializer) {
2510 if (HasDesignatedInit && InitializedFields.count(*it))
2513 if (!it->isUnnamedBitField() && !it->hasInClassInitializer() &&
2514 !it->getType()->isIncompleteArrayType()) {
2515 auto Diag = HasDesignatedInit
2516 ? diag::warn_missing_designated_field_initializers
2517 : diag::warn_missing_field_initializers;
2526 if (!StructuredList && Field != FieldEnd && !RD->
isUnion() &&
2527 !
Field->getType()->isIncompleteArrayType()) {
2528 for (;
Field != FieldEnd && !hadError; ++
Field) {
2529 if (!
Field->isUnnamedBitField() && !
Field->hasInClassInitializer())
2530 CheckEmptyInitializable(
2551 if (Field == FieldEnd || !
Field->getType()->isIncompleteArrayType() ||
2555 if (CheckFlexibleArrayInit(Entity, IList->
getInit(Index), *Field,
2565 if (isa<InitListExpr>(IList->
getInit(Index)) ||
2566 AggrDeductionCandidateParamTypes)
2567 CheckSubElementType(MemberEntity, IList,
Field->getType(), Index,
2568 StructuredList, StructuredIndex);
2570 CheckImplicitInitList(MemberEntity, IList,
Field->getType(), Index,
2571 StructuredList, StructuredIndex);
2573 if (RD->
isUnion() && StructuredList) {
2592 PE = IndirectField->
chain_end(); PI != PE; ++PI) {
2600 assert(isa<FieldDecl>(*PI));
2601 Replacements.back().setFieldDecl(cast<FieldDecl>(*PI));
2608 &Replacements[0] + Replacements.size());
2615 for (
unsigned I = 0; I < NumIndexExprs; ++I)
2629 explicit FieldInitializerValidatorCCC(
const RecordDecl *RD)
2637 std::unique_ptr<CorrectionCandidateCallback>
clone()
override {
2638 return std::make_unique<FieldInitializerValidatorCCC>(*
this);
2691 llvm::APSInt *NextElementIndex,
2694 unsigned &StructuredIndex,
2695 bool FinishSubobjectInit,
2696 bool TopLevelObject) {
2697 if (DesigIdx == DIE->
size()) {
2704 assert(isa<InitListExpr>(
Init) &&
2705 "designator result in direct non-list initialization?");
2710 if (StructuredList) {
2714 UpdateStructuredListElement(StructuredList, StructuredIndex,
2718 if (AggrDeductionCandidateParamTypes)
2719 AggrDeductionCandidateParamTypes->push_back(CurrentObjectType);
2724 bool prevHadError = hadError;
2729 unsigned OldIndex = Index;
2732 CheckSubElementType(Entity, IList, CurrentObjectType, Index, StructuredList,
2733 StructuredIndex,
true);
2739 IList->
setInit(OldIndex, DIE);
2741 return hadError && !prevHadError;
2745 bool IsFirstDesignator = (DesigIdx == 0);
2746 if (IsFirstDesignator ? FullyStructuredList : StructuredList) {
2749 if (IsFirstDesignator)
2750 StructuredList = FullyStructuredList;
2752 Expr *ExistingInit = StructuredIndex < StructuredList->getNumInits() ?
2753 StructuredList->getInit(StructuredIndex) :
nullptr;
2754 if (!ExistingInit && StructuredList->hasArrayFiller())
2755 ExistingInit = StructuredList->getArrayFiller();
2758 StructuredList = getStructuredSubobjectInit(
2759 IList, Index, CurrentObjectType, StructuredList, StructuredIndex,
2761 else if (
InitListExpr *Result = dyn_cast<InitListExpr>(ExistingInit))
2762 StructuredList = Result;
2775 diagnoseInitOverride(ExistingInit,
2782 dyn_cast<DesignatedInitUpdateExpr>(ExistingInit))
2783 StructuredList =
E->getUpdater();
2788 StructuredList->updateInit(SemaRef.
Context, StructuredIndex, DIUE);
2797 StructuredList =
nullptr;
2803 if (
D->isFieldDesignator()) {
2813 RecordDecl *RD = getRecordDecl(CurrentObjectType);
2817 Loc =
D->getFieldLoc();
2819 SemaRef.
Diag(
Loc, diag::err_field_designator_non_aggr)
2820 << SemaRef.
getLangOpts().CPlusPlus << CurrentObjectType;
2829 if (
auto *FD = dyn_cast_if_present<FieldDecl>(VD)) {
2831 }
else if (
auto *IFD = dyn_cast_if_present<IndirectFieldDecl>(VD)) {
2837 KnownField = cast<FieldDecl>(*IFD->chain_begin());
2854 SemaRef.
Diag(
D->getFieldLoc(), diag::err_field_designator_nonfield)
2856 SemaRef.
Diag(Lookup.front()->getLocation(),
2857 diag::note_field_designator_found);
2864 FieldInitializerValidatorCCC CCC(RD);
2871 SemaRef.
PDiag(diag::err_field_designator_unknown_suggest)
2872 << FieldName << CurrentObjectType);
2873 KnownField = Corrected.getCorrectionDeclAs<
FieldDecl>();
2884 SemaRef.
Diag(
Loc, diag::err_field_designator_unknown)
2892 unsigned NumBases = 0;
2893 if (
auto *CXXRD = dyn_cast<CXXRecordDecl>(RD))
2894 NumBases = CXXRD->getNumBases();
2896 unsigned FieldIndex = NumBases;
2898 for (
auto *FI : RD->
fields()) {
2899 if (FI->isUnnamedBitField())
2915 if (StructuredList) {
2916 FieldDecl *CurrentField = StructuredList->getInitializedFieldInUnion();
2918 assert(StructuredList->getNumInits() == 1
2919 &&
"A union should never have more than one initializer!");
2921 Expr *ExistingInit = StructuredList->getInit(0);
2924 diagnoseInitOverride(
2932 StructuredList->resizeInits(SemaRef.
Context, 0);
2933 StructuredList->setInitializedFieldInUnion(
nullptr);
2936 StructuredList->setInitializedFieldInUnion(*Field);
2943 InvalidUse = !SemaRef.
CanUseDecl(*Field, TreatUnavailableAsInvalid);
2966 if (IsFirstDesignator && !VerifyOnly && SemaRef.
getLangOpts().CPlusPlus &&
2969 (*NextField)->getFieldIndex() >
Field->getFieldIndex() + 1)) {
2973 if (FI->isUnnamedBitField())
2984 diag::ext_designated_init_reordered)
2987 unsigned OldIndex = StructuredIndex - 1;
2988 if (StructuredList && OldIndex <= StructuredList->getNumInits()) {
2989 if (
Expr *PrevInit = StructuredList->getInit(OldIndex)) {
2990 SemaRef.
Diag(PrevInit->getBeginLoc(),
2991 diag::note_previous_field_init)
3001 D->setFieldDecl(*Field);
3005 if (StructuredList && FieldIndex >= StructuredList->getNumInits())
3006 StructuredList->resizeInits(SemaRef.
Context, FieldIndex + 1);
3009 if (
Field->getType()->isIncompleteArrayType()) {
3011 if ((DesigIdx + 1) != DIE->
size()) {
3018 diag::err_designator_into_flexible_array_member)
3020 SemaRef.
Diag(
Field->getLocation(), diag::note_flexible_array_member)
3026 if (!hadError && !isa<InitListExpr>(DIE->
getInit()) &&
3027 !isa<StringLiteral>(DIE->
getInit())) {
3031 diag::err_flexible_array_init_needs_braces)
3033 SemaRef.
Diag(
Field->getLocation(), diag::note_flexible_array_member)
3040 if (!
Invalid && CheckFlexibleArrayInit(Entity, DIE->
getInit(), *Field,
3050 bool prevHadError = hadError;
3051 unsigned newStructuredIndex = FieldIndex;
3052 unsigned OldIndex = Index;
3057 CheckSubElementType(MemberEntity, IList,
Field->getType(), Index,
3058 StructuredList, newStructuredIndex);
3060 IList->
setInit(OldIndex, DIE);
3061 if (hadError && !prevHadError) {
3066 StructuredIndex = FieldIndex;
3072 unsigned newStructuredIndex = FieldIndex;
3076 if (CheckDesignatedInitializer(MemberEntity, IList, DIE, DesigIdx + 1,
3077 FieldType,
nullptr,
nullptr, Index,
3078 StructuredList, newStructuredIndex,
3079 FinishSubobjectInit,
false))
3090 if (IsFirstDesignator) {
3097 StructuredIndex = FieldIndex;
3101 if (!FinishSubobjectInit)
3109 bool prevHadError = hadError;
3114 CheckStructUnionTypes(Entity, IList, CurrentObjectType, NoBases, Field,
3115 false, Index, StructuredList, FieldIndex);
3116 return hadError && !prevHadError;
3137 SemaRef.
Diag(
D->getLBracketLoc(), diag::err_array_designator_non_array)
3138 << CurrentObjectType;
3143 Expr *IndexExpr =
nullptr;
3144 llvm::APSInt DesignatedStartIndex, DesignatedEndIndex;
3145 if (
D->isArrayDesignator()) {
3148 DesignatedEndIndex = DesignatedStartIndex;
3150 assert(
D->isArrayRangeDesignator() &&
"Need array-range designator");
3152 DesignatedStartIndex =
3154 DesignatedEndIndex =
3163 if (DesignatedStartIndex.getZExtValue()!=DesignatedEndIndex.getZExtValue()&&
3168 if (isa<ConstantArrayType>(AT)) {
3169 llvm::APSInt MaxElements(cast<ConstantArrayType>(AT)->getSize(),
false);
3170 DesignatedStartIndex
3171 = DesignatedStartIndex.extOrTrunc(MaxElements.getBitWidth());
3172 DesignatedStartIndex.setIsUnsigned(MaxElements.isUnsigned());
3174 = DesignatedEndIndex.extOrTrunc(MaxElements.getBitWidth());
3175 DesignatedEndIndex.setIsUnsigned(MaxElements.isUnsigned());
3176 if (DesignatedEndIndex >= MaxElements) {
3179 diag::err_array_designator_too_large)
3186 unsigned DesignatedIndexBitWidth =
3188 DesignatedStartIndex =
3189 DesignatedStartIndex.extOrTrunc(DesignatedIndexBitWidth);
3190 DesignatedEndIndex =
3191 DesignatedEndIndex.extOrTrunc(DesignatedIndexBitWidth);
3192 DesignatedStartIndex.setIsUnsigned(
true);
3193 DesignatedEndIndex.setIsUnsigned(
true);
3196 bool IsStringLiteralInitUpdate =
3197 StructuredList && StructuredList->isStringLiteralInit();
3198 if (IsStringLiteralInitUpdate && VerifyOnly) {
3201 StructuredList =
nullptr;
3202 }
else if (IsStringLiteralInitUpdate) {
3215 unsigned PromotedCharTyWidth = Context.
getTypeSize(PromotedCharTy);
3220 if (cast<ConstantArrayType>(AT)->getSize().ult(StrLen))
3221 StrLen = cast<ConstantArrayType>(AT)->getZExtSize();
3222 StructuredList->resizeInits(Context, StrLen);
3226 for (
unsigned i = 0, e = StrLen; i != e; ++i) {
3227 llvm::APInt CodeUnit(PromotedCharTyWidth, SL->getCodeUnit(i));
3229 Context, CodeUnit, PromotedCharTy, SubExpr->
getExprLoc());
3230 if (CharTy != PromotedCharTy)
3234 StructuredList->updateInit(Context, i,
Init);
3243 if (cast<ConstantArrayType>(AT)->getSize().ult(StrLen))
3244 StrLen = cast<ConstantArrayType>(AT)->getZExtSize();
3245 StructuredList->resizeInits(Context, StrLen);
3249 for (
unsigned i = 0, e = StrLen; i != e; ++i) {
3250 llvm::APInt CodeUnit(PromotedCharTyWidth, Str[i]);
3252 Context, CodeUnit, PromotedCharTy, SubExpr->
getExprLoc());
3253 if (CharTy != PromotedCharTy)
3257 StructuredList->updateInit(Context, i,
Init);
3264 if (StructuredList &&
3265 DesignatedEndIndex.getZExtValue() >= StructuredList->getNumInits())
3266 StructuredList->resizeInits(SemaRef.
Context,
3267 DesignatedEndIndex.getZExtValue() + 1);
3273 unsigned ElementIndex = DesignatedStartIndex.getZExtValue();
3274 unsigned OldIndex = Index;
3279 while (DesignatedStartIndex <= DesignatedEndIndex) {
3285 if (CheckDesignatedInitializer(
3286 ElementEntity, IList, DIE, DesigIdx + 1, ElementType,
nullptr,
3287 nullptr, Index, StructuredList, ElementIndex,
3288 FinishSubobjectInit && (DesignatedStartIndex == DesignatedEndIndex),
3293 ++DesignatedStartIndex;
3294 ElementIndex = DesignatedStartIndex.getZExtValue();
3299 if (IsFirstDesignator) {
3300 if (NextElementIndex)
3301 *NextElementIndex = DesignatedStartIndex;
3302 StructuredIndex = ElementIndex;
3306 if (!FinishSubobjectInit)
3310 bool prevHadError = hadError;
3311 CheckArrayType(Entity, IList, CurrentObjectType, DesignatedStartIndex,
3313 StructuredList, ElementIndex);
3314 return hadError && !prevHadError;
3320InitListChecker::getStructuredSubobjectInit(
InitListExpr *IList,
unsigned Index,
3323 unsigned StructuredIndex,
3325 bool IsFullyOverwritten) {
3326 if (!StructuredList)
3329 Expr *ExistingInit =
nullptr;
3330 if (StructuredIndex < StructuredList->getNumInits())
3331 ExistingInit = StructuredList->
getInit(StructuredIndex);
3333 if (
InitListExpr *Result = dyn_cast_or_null<InitListExpr>(ExistingInit))
3342 if (!IsFullyOverwritten)
3365 diagnoseInitOverride(ExistingInit, InitRange);
3368 unsigned ExpectedNumInits = 0;
3369 if (Index < IList->getNumInits()) {
3370 if (
auto *
Init = dyn_cast_or_null<InitListExpr>(IList->
getInit(Index)))
3371 ExpectedNumInits =
Init->getNumInits();
3377 createInitListExpr(CurrentObjectType, InitRange, ExpectedNumInits);
3386InitListChecker::createInitListExpr(
QualType CurrentObjectType,
3388 unsigned ExpectedNumInits) {
3392 QualType ResultType = CurrentObjectType;
3395 Result->setType(ResultType);
3398 unsigned NumElements = 0;
3403 NumElements = CAType->getZExtSize();
3406 if (NumElements > ExpectedNumInits)
3410 NumElements = VType->getNumElements();
3412 NumElements = numStructUnionElements(CurrentObjectType);
3417 Result->reserveInits(SemaRef.
Context, NumElements);
3424void InitListChecker::UpdateStructuredListElement(
InitListExpr *StructuredList,
3425 unsigned &StructuredIndex,
3428 if (!StructuredList)
3432 StructuredIndex,
expr)) {
3438 diagnoseInitOverride(PrevInit,
expr->getSourceRange());
3447 InitListChecker Check(*
this, Entity, From,
Type,
true,
3450 return !Check.HadError();
3471 return S.
Diag(
Loc, diag::err_array_designator_negative)
3474 Value.setIsUnsigned(
true);
3492 if (
D.isFieldDesignator()) {
3493 Designators.push_back(ASTDesignator::CreateFieldDesignator(
3494 D.getFieldDecl(),
D.getDotLoc(),
D.getFieldLoc()));
3495 }
else if (
D.isArrayDesignator()) {
3496 Expr *Index =
static_cast<Expr *
>(
D.getArrayIndex());
3497 llvm::APSInt IndexValue;
3498 if (!Index->isTypeDependent() && !Index->isValueDependent())
3503 Designators.push_back(ASTDesignator::CreateArrayDesignator(
3504 InitExpressions.size(),
D.getLBracketLoc(),
D.getRBracketLoc()));
3505 InitExpressions.push_back(Index);
3507 }
else if (
D.isArrayRangeDesignator()) {
3508 Expr *StartIndex =
static_cast<Expr *
>(
D.getArrayRangeStart());
3509 Expr *EndIndex =
static_cast<Expr *
>(
D.getArrayRangeEnd());
3510 llvm::APSInt StartValue;
3511 llvm::APSInt EndValue;
3516 if (!StartDependent)
3522 if (!StartIndex || !EndIndex)
3526 if (StartDependent || EndDependent) {
3528 }
else if (StartValue.getBitWidth() > EndValue.getBitWidth())
3529 EndValue = EndValue.extend(StartValue.getBitWidth());
3530 else if (StartValue.getBitWidth() < EndValue.getBitWidth())
3531 StartValue = StartValue.extend(EndValue.getBitWidth());
3533 if (!StartDependent && !EndDependent && EndValue < StartValue) {
3534 Diag(
D.getEllipsisLoc(), diag::err_array_designator_empty_range)
3539 Designators.push_back(ASTDesignator::CreateArrayRangeDesignator(
3540 InitExpressions.size(),
D.getLBracketLoc(),
D.getEllipsisLoc(),
3541 D.getRBracketLoc()));
3542 InitExpressions.push_back(StartIndex);
3543 InitExpressions.push_back(EndIndex);
3553 EqualOrColonLoc, GNUSyntax,
3561InitializedEntity::InitializedEntity(
ASTContext &Context,
unsigned Index,
3566 Kind = EK_ArrayElement;
3569 Kind = EK_VectorElement;
3573 assert(CT &&
"Unexpected type");
3574 Kind = EK_ComplexElement;
3582 bool IsInheritedVirtualBase,
3587 Result.Base = {
Base, IsInheritedVirtualBase};
3605 return Variable.VariableOrMember->getDeclName();
3627 llvm_unreachable(
"Invalid EntityKind!");
3661 llvm_unreachable(
"Invalid EntityKind!");
3696unsigned InitializedEntity::dumpImpl(raw_ostream &OS)
const {
3699 for (
unsigned I = 0; I != Depth; ++I)
3716 case EK_New: OS <<
"New";
break;
3720 case EK_Base: OS <<
"Base";
break;
3727 OS <<
"Block (lambda)";
3730 OS <<
"LambdaCapture ";
3737 D->printQualifiedName(OS);
3740 OS <<
" '" <<
getType() <<
"'\n";
3746 dumpImpl(llvm::errs());
3801 for (
const Step &S : llvm::reverse(Steps)) {
3861 llvm_unreachable(
"Invalid EntityKind!");
3869InitializationSequence
3872 bool HadMultipleCandidates) {
3876 S.Function.HadMultipleCandidates = HadMultipleCandidates;
3878 S.Function.FoundDecl =
Found;
3897 bool BindingTemporary) {
3922 bool HadMultipleCandidates) {
3926 S.Function.HadMultipleCandidates = HadMultipleCandidates;
3928 S.Function.FoundDecl = FoundDecl;
3967 bool TopLevelOfInitList) {
3985 bool HadMultipleCandidates,
bool FromInitList,
bool AsInitList) {
3991 S.Function.HadMultipleCandidates = HadMultipleCandidates;
3992 S.Function.Function = Constructor;
3993 S.Function.FoundDecl = FoundDecl;
4036 Steps.insert(Steps.begin(), S);
4097 "Can only rewrap trivial init lists.");
4101 Steps.insert(Steps.begin(), S);
4105 S.WrappingSyntacticList = Syntactic;
4112 this->Failure = Failure;
4113 this->FailedOverloadResult =
Result;
4134 if (!
Init.empty()) {
4154 "consuming an object of unretainable type?");
4175 bool TreatUnavailableAsInvalid);
4186 bool TreatUnavailableAsInvalid) {
4200 List->getNumInits()),
4205 List->getExprLoc(), List->getBeginLoc(), List->getEndLoc());
4207 TreatUnavailableAsInvalid);
4234 bool CopyInitializing,
bool AllowExplicit,
bool OnlyListConstructors,
4235 bool IsListInit,
bool RequireActualConstructor,
4236 bool SecondStepOfCopyInit =
false) {
4242 if (!Info.Constructor || Info.Constructor->isInvalidDecl())
4259 bool SuppressUserConversions =
4260 SecondStepOfCopyInit ||
4261 (IsListInit && Args.size() == 1 && isa<InitListExpr>(Args[0]) &&
4264 if (Info.ConstructorTmpl)
4266 Info.ConstructorTmpl, Info.FoundDecl,
4267 nullptr, Args, CandidateSet, SuppressUserConversions,
4268 false, AllowExplicit);
4277 bool AllowExplicitConv = AllowExplicit && !CopyInitializing &&
4281 CandidateSet, SuppressUserConversions,
4282 false, AllowExplicit,
4298 if (S.
getLangOpts().CPlusPlus17 && Args.size() == 1 &&
4299 !RequireActualConstructor && !SecondStepOfCopyInit) {
4301 auto *SourceRD =
Initializer->getType()->getAsCXXRecordDecl();
4303 const auto &Conversions = SourceRD->getVisibleConversionFunctions();
4304 for (
auto I = Conversions.begin(),
E = Conversions.end(); I !=
E; ++I) {
4307 D =
D->getUnderlyingDecl();
4314 Conv = cast<CXXConversionDecl>(
D);
4318 ConvTemplate, I.getPair(), ActingDC,
Initializer, DestType,
4319 CandidateSet, AllowExplicit, AllowExplicit,
4323 DestType, CandidateSet, AllowExplicit,
4350 bool IsListInit =
false,
4351 bool IsInitListCopy =
false) {
4352 assert(((!IsListInit && !IsInitListCopy) ||
4353 (Args.size() == 1 && isa<InitListExpr>(Args[0]))) &&
4354 "IsListInit/IsInitListCopy must come with a single initializer list "
4357 (IsListInit || IsInitListCopy) ? cast<InitListExpr>(Args[0]) :
nullptr;
4367 bool RequireActualConstructor =
4373 bool CopyElisionPossible =
false;
4374 auto ElideConstructor = [&] {
4390 if (S.
getLangOpts().CPlusPlus17 && !RequireActualConstructor &&
4391 UnwrappedArgs.size() == 1 && UnwrappedArgs[0]->isPRValue() &&
4413 assert(!IsInitListCopy &&
4414 "IsInitListCopy only possible with aggregate types");
4415 CopyElisionPossible =
true;
4423 assert(DestRecordType &&
"Constructor initialization requires record type");
4425 = cast<CXXRecordDecl>(DestRecordType->
getDecl());
4433 bool AllowExplicit = Kind.AllowExplicit() || IsListInit;
4443 bool AsInitializerList =
false;
4455 AsInitializerList =
true;
4461 S, Kind.getLocation(), Args, CandidateSet, DestType, Ctors, Best,
4462 CopyInitialization, AllowExplicit,
4463 true, IsListInit, RequireActualConstructor);
4478 AsInitializerList =
false;
4480 S, Kind.getLocation(), UnwrappedArgs, CandidateSet, DestType, Ctors,
4481 Best, CopyInitialization, AllowExplicit,
4482 false, IsListInit, RequireActualConstructor);
4494 bool HadMultipleCandidates = (CandidateSet.
size() > 1);
4498 if (
auto *CD = dyn_cast<CXXConversionDecl>(Best->Function)) {
4500 QualType ConvType = CD->getConversionType();
4502 "should not have selected this conversion function");
4504 HadMultipleCandidates);
4535 if (IsListInit && !Kind.AllowExplicit() && CtorDecl->
isExplicit()) {
4555 Best->FoundDecl, CtorDecl, DestArrayType, HadMultipleCandidates,
4556 IsListInit | IsInitListCopy, AsInitializerList);
4569 bool HadMultipleCandidates =
false;
4572 UnqualifiedTargetType,
4574 &HadMultipleCandidates)) {
4576 HadMultipleCandidates);
4577 SourceType = Fn->getType();
4596 bool TopLevelOfInitList);
4610 bool TreatUnavailableAsInvalid) {
4650 T1Quals, cv2T2, T2, T2Quals, Sequence,
4681 TreatUnavailableAsInvalid);
4713 bool TreatUnavailableAsInvalid) {
4725 TreatUnavailableAsInvalid);
4763 !IsDesignatedInit) {
4768 Expr *InitListAsExpr = InitList;
4778 if (!isa<VariableArrayType>(DestAT) &&
4788 TreatUnavailableAsInvalid);
4821 TreatUnavailableAsInvalid))
4825 Expr *InitListAsExpr = InitList;
4827 DestType, Sequence,
true);
4845 ET && ET->getDecl()->isFixed() &&
4894 if (
Init->getType()->isRecordType() ||
4905 TreatUnavailableAsInvalid);
4912 InitListChecker CheckInitList(S, Entity, InitList,
4913 DestType,
true, TreatUnavailableAsInvalid);
4914 if (CheckInitList.HadError()) {
4936 "Must have incompatible references when binding via conversion");
4947 bool AllowExplicitCtors =
false;
4948 bool AllowExplicitConvs = Kind.allowExplicitConversionFunctionsInRefBinding();
4959 if (!Info.Constructor)
4962 if (!Info.Constructor->isInvalidDecl() &&
4963 Info.Constructor->isConvertingConstructor(
true)) {
4964 if (Info.ConstructorTmpl)
4966 Info.ConstructorTmpl, Info.FoundDecl,