25 #include "llvm/ADT/APInt.h" 26 #include "llvm/ADT/SmallString.h" 27 #include "llvm/Support/ErrorHandling.h" 28 #include "llvm/Support/raw_ostream.h" 30 using namespace clang;
64 if (!isa<ConstantArrayType>(AT) && !isa<IncompleteArrayType>(AT))
132 llvm_unreachable(
"missed a StringLiteral kind?");
148 if (isa<StringLiteral>(E) || isa<ObjCEncodeExpr>(E))
150 else if (
ParenExpr *PE = dyn_cast<ParenExpr>(E))
151 E = PE->getSubExpr();
153 E = UO->getSubExpr();
155 E = GSE->getResultExpr();
157 llvm_unreachable(
"unexpected expr in string literal init");
164 auto *ConstantArrayTy =
166 uint64_t StrLength = ConstantArrayTy->getSize().getZExtValue();
171 llvm::APInt ConstVal(32, StrLength);
196 if (StrLength > CAT->
getSize().getZExtValue())
198 diag::err_initializer_string_for_char_array_too_long)
202 if (StrLength-1 > CAT->
getSize().getZExtValue())
204 diag::ext_initializer_string_for_char_array_too_long)
248 class InitListChecker {
252 bool TreatUnavailableAsInvalid;
253 llvm::DenseMap<InitListExpr *, InitListExpr *> SyntacticToSemantic;
259 unsigned &StructuredIndex);
263 bool TopLevelObject =
false);
266 bool SubobjectIsDesignatorContext,
269 unsigned &StructuredIndex,
270 bool TopLevelObject =
false);
275 unsigned &StructuredIndex);
280 unsigned &StructuredIndex);
285 unsigned &StructuredIndex);
290 unsigned &StructuredIndex);
294 unsigned &StructuredIndex);
299 bool SubobjectIsDesignatorContext,
unsigned &Index,
301 unsigned &StructuredIndex,
302 bool TopLevelObject =
false);
305 llvm::APSInt elementIndex,
306 bool SubobjectIsDesignatorContext,
unsigned &Index,
308 unsigned &StructuredIndex);
314 llvm::APSInt *NextElementIndex,
317 unsigned &StructuredIndex,
318 bool FinishSubobjectInit,
319 bool TopLevelObject);
323 unsigned StructuredIndex,
325 bool IsFullyOverwritten =
false);
326 void UpdateStructuredListElement(
InitListExpr *StructuredList,
327 unsigned &StructuredIndex,
329 int numArrayElements(
QualType DeclType);
330 int numStructUnionElements(
QualType DeclType);
336 bool TreatUnavailableAsInvalid);
360 bool FillWithNoInit);
361 void FillInEmptyInitForField(
unsigned Init,
FieldDecl *Field,
364 bool FillWithNoInit =
false);
368 bool FillWithNoInit =
false);
371 bool TopLevelObject);
378 bool TreatUnavailableAsInvalid);
379 bool HadError() {
return hadError; }
383 InitListExpr *getFullyStructuredList()
const {
return FullyStructuredList; }
392 bool TreatUnavailableAsInvalid) {
403 bool EmptyInitList = SemaRef.
getLangOpts().CPlusPlus11 &&
416 InitExpr = VerifyOnly ? &DummyInitList :
new (SemaRef.
Context)
439 assert(O ==
OR_Success &&
"Inconsistent overload resolution");
446 bool IsInStd =
false;
447 for (
NamespaceDecl *ND = dyn_cast<NamespaceDecl>(R->getDeclContext());
448 ND && !IsInStd; ND = dyn_cast<
NamespaceDecl>(ND->getParent())) {
453 if (IsInStd && llvm::StringSwitch<bool>(R->getName())
454 .Cases(
"basic_string",
"deque",
"forward_list",
true)
455 .Cases(
"list",
"map",
"multimap",
"multiset",
true)
456 .Cases(
"priority_queue",
"queue",
"set",
"stack",
true)
457 .Cases(
"unordered_map",
"unordered_set",
"vector",
true)
463 TreatUnavailableAsInvalid);
468 diag::warn_invalid_initializer_from_system_header);
471 diag::note_used_in_initialization_here);
473 SemaRef.
Diag(Loc, diag::note_used_in_initialization_here);
480 InitSeq.
Diagnose(SemaRef, Entity, Kind, SubInit);
483 diag::note_in_omitted_aggregate_initializer)
486 bool IsTrailingArrayNewMember =
489 SemaRef.
Diag(Loc, diag::note_in_omitted_aggregate_initializer)
490 << (IsTrailingArrayNewMember ? 2 : 0)
497 return VerifyOnly ?
ExprResult(static_cast<Expr *>(
nullptr))
498 : InitSeq.
Perform(SemaRef, Entity, Kind, SubInit);
504 "CheckEmptyInitializable is only inteded for verification mode.");
505 if (PerformEmptyInit(SemaRef, Loc, Entity,
true,
510 void InitListChecker::FillInEmptyInitForBase(
513 bool &RequiresSecondPass,
bool FillWithNoInit) {
514 assert(Init < ILE->getNumInits() &&
"should have been expanded");
517 SemaRef.
Context, &Base,
false, &ParentEntity);
522 : PerformEmptyInit(SemaRef, ILE->
getLocEnd(), BaseEntity,
524 TreatUnavailableAsInvalid);
532 dyn_cast<InitListExpr>(ILE->
getInit(Init))) {
533 FillInEmptyInitializations(BaseEntity, InnerILE, RequiresSecondPass,
534 ILE, Init, FillWithNoInit);
536 dyn_cast<DesignatedInitUpdateExpr>(ILE->
getInit(Init))) {
537 FillInEmptyInitializations(BaseEntity, InnerDIUE->getUpdater(),
538 RequiresSecondPass, ILE, Init,
543 void InitListChecker::FillInEmptyInitForField(
unsigned Init,
FieldDecl *Field,
546 bool &RequiresSecondPass,
547 bool FillWithNoInit) {
554 if (!RType->getDecl()->isUnion())
555 assert(Init < NumInits &&
"This ILE should have been expanded");
557 if (Init >= NumInits || !ILE->
getInit(Init)) {
558 if (FillWithNoInit) {
581 RequiresSecondPass =
true;
591 SemaRef.
Diag(Loc, diag::err_init_reference_member_uninitialized)
595 diag::note_uninit_reference_member);
600 ExprResult MemberInit = PerformEmptyInit(SemaRef, Loc, MemberEntity,
602 TreatUnavailableAsInvalid);
610 }
else if (Init < NumInits) {
612 }
else if (!isa<ImplicitValueInitExpr>(MemberInit.
get())) {
618 RequiresSecondPass =
true;
621 = dyn_cast<InitListExpr>(ILE->
getInit(Init)))
622 FillInEmptyInitializations(MemberEntity, InnerILE,
623 RequiresSecondPass, ILE, Init, FillWithNoInit);
625 = dyn_cast<DesignatedInitUpdateExpr>(ILE->
getInit(Init)))
626 FillInEmptyInitializations(MemberEntity, InnerDIUE->getUpdater(),
627 RequiresSecondPass, ILE, Init,
637 bool &RequiresSecondPass,
640 bool FillWithNoInit) {
642 "Should not have void type");
651 struct UpdateOuterILEWithUpdatedInit {
654 ~UpdateOuterILEWithUpdatedInit() {
658 } UpdateOuterRAII = {OuterILE, OuterIndex};
669 Entity, ILE, RequiresSecondPass, FillWithNoInit);
670 else if (RDecl->
isUnion() && isa<CXXRecordDecl>(RDecl) &&
671 cast<CXXRecordDecl>(RDecl)->hasInClassInitializer()) {
672 for (
auto *Field : RDecl->
fields()) {
674 FillInEmptyInitForField(0, Field, Entity, ILE, RequiresSecondPass,
683 unsigned NumElems = numStructUnionElements(ILE->getType());
686 if (ILE->getNumInits() < NumElems)
687 ILE->resizeInits(SemaRef.
Context, NumElems);
691 if (
auto *CXXRD = dyn_cast<CXXRecordDecl>(RDecl)) {
692 for (
auto &Base : CXXRD->bases()) {
696 FillInEmptyInitForBase(Init, Base, Entity, ILE, RequiresSecondPass,
702 for (
auto *Field : RDecl->
fields()) {
709 FillInEmptyInitForField(Init, Field, Entity, ILE, RequiresSecondPass,
729 unsigned NumElements = NumInits;
731 ElementType = AType->getElementType();
732 if (
const auto *CAType = dyn_cast<ConstantArrayType>(AType))
733 NumElements = CAType->getSize().getZExtValue();
741 ElementType = VType->getElementType();
742 NumElements = VType->getNumElements();
748 for (
unsigned Init = 0; Init != NumElements; ++Init) {
759 Expr *InitExpr = (Init < NumInits ? ILE->
getInit(Init) :
nullptr);
760 if (!InitExpr && Init < NumInits && ILE->hasArrayFiller())
763 Expr *Filler =
nullptr;
771 TreatUnavailableAsInvalid);
782 }
else if (Init < NumInits) {
797 if (!isa<ImplicitValueInitExpr>(Filler) && !isa<NoInitExpr>(Filler)) {
803 RequiresSecondPass =
true;
807 = dyn_cast_or_null<InitListExpr>(InitExpr))
808 FillInEmptyInitializations(ElementEntity, InnerILE, RequiresSecondPass,
809 ILE, Init, FillWithNoInit);
811 = dyn_cast_or_null<DesignatedInitUpdateExpr>(InitExpr))
812 FillInEmptyInitializations(ElementEntity, InnerDIUE->getUpdater(),
813 RequiresSecondPass, ILE, Init,
821 bool TreatUnavailableAsInvalid)
822 : SemaRef(S), VerifyOnly(VerifyOnly),
823 TreatUnavailableAsInvalid(TreatUnavailableAsInvalid) {
829 FullyStructuredList =
830 getStructuredSubobjectInit(IL, 0, T,
nullptr, 0, IL->
getSourceRange());
831 CheckExplicitInitList(Entity, IL, T, FullyStructuredList,
834 if (!hadError && !VerifyOnly) {
835 bool RequiresSecondPass =
false;
836 FillInEmptyInitializations(Entity, FullyStructuredList, RequiresSecondPass,
838 if (RequiresSecondPass && !hadError)
839 FillInEmptyInitializations(Entity, FullyStructuredList,
840 RequiresSecondPass,
nullptr, 0);
844 int InitListChecker::numArrayElements(
QualType DeclType) {
846 int maxElements = 0x7FFFFFFF;
849 maxElements =
static_cast<int>(CAT->getSize().getZExtValue());
854 int InitListChecker::numStructUnionElements(
QualType DeclType) {
856 int InitializableMembers = 0;
857 if (
auto *CXXRD = dyn_cast<CXXRecordDecl>(structDecl))
858 InitializableMembers += CXXRD->getNumBases();
859 for (
const auto *Field : structDecl->
fields())
861 ++InitializableMembers;
864 return std::min(InitializableMembers, 1);
886 if (
CXXRecordDecl *CXXRD = dyn_cast<CXXRecordDecl>(ParentRD))
887 if (CXXRD->getNumBases())
890 auto FieldIt = ParentRD->field_begin();
891 assert(FieldIt != ParentRD->field_end() &&
892 "no fields but have initializer for member?");
893 return ++FieldIt == ParentRD->field_end();
906 unsigned &StructuredIndex) {
910 maxElements = numArrayElements(T);
912 maxElements = numStructUnionElements(T);
916 llvm_unreachable(
"CheckImplicitInitList(): Illegal type");
918 if (maxElements == 0) {
921 diag::err_implicit_empty_initializer);
929 = getStructuredSubobjectInit(ParentIList, Index, T, StructuredList,
933 unsigned StructuredSubobjectInitIndex = 0;
936 unsigned StartIndex = Index;
937 CheckListElementTypes(Entity, ParentIList, T,
939 StructuredSubobjectInitList,
940 StructuredSubobjectInitIndex);
943 StructuredSubobjectInitList->
setType(T);
945 unsigned EndIndex = (Index == StartIndex? StartIndex : Index - 1);
948 if (EndIndex < ParentIList->getNumInits() &&
949 ParentIList->
getInit(EndIndex)) {
960 diag::warn_missing_braces)
966 StructuredSubobjectInitList->
getLocEnd()),
992 DiagID = diag::warn_braces_around_scalar_init;
999 DiagID = diag::warn_braces_around_scalar_init;
1025 llvm_unreachable(
"unexpected braced scalar init");
1044 bool TopLevelObject) {
1046 SyntacticToSemantic[IList] = StructuredList;
1050 unsigned Index = 0, StructuredIndex = 0;
1051 CheckListElementTypes(Entity, IList, T,
true,
1052 Index, StructuredList, StructuredIndex, TopLevelObject);
1058 StructuredList->
setType(ExprTy);
1063 if (Index < IList->getNumInits()) {
1074 if (StructuredIndex == 1 &&
1077 unsigned DK = diag::ext_excess_initializers_in_char_array_initializer;
1079 DK = diag::err_excess_initializers_in_char_array_initializer;
1096 unsigned DK = diag::ext_excess_initializers;
1098 DK = diag::err_excess_initializers;
1101 if (SemaRef.
getLangOpts().OpenCL && initKind == 1) {
1102 DK = diag::err_excess_initializers;
1119 bool SubobjectIsDesignatorContext,
1122 unsigned &StructuredIndex,
1123 bool TopLevelObject) {
1127 CheckComplexType(Entity, IList, DeclType, Index,
1128 StructuredList, StructuredIndex);
1130 CheckScalarType(Entity, IList, DeclType, Index,
1131 StructuredList, StructuredIndex);
1133 CheckVectorType(Entity, IList, DeclType, Index,
1134 StructuredList, StructuredIndex);
1137 "non-aggregate records should be handed in CheckSubElementType");
1142 if (
auto *CXXRD = dyn_cast<CXXRecordDecl>(RD))
1143 Bases = CXXRD->bases();
1144 CheckStructUnionTypes(Entity, IList, DeclType, Bases, RD->field_begin(),
1145 SubobjectIsDesignatorContext, Index, StructuredList,
1146 StructuredIndex, TopLevelObject);
1151 CheckArrayType(Entity, IList, DeclType, Zero,
1152 SubobjectIsDesignatorContext, Index,
1153 StructuredList, StructuredIndex);
1158 SemaRef.
Diag(IList->
getLocStart(), diag::err_illegal_initializer_type)
1162 CheckReferenceType(Entity, IList, DeclType, Index,
1163 StructuredList, StructuredIndex);
1171 SemaRef.
Diag(IList->
getLocStart(), diag::err_illegal_initializer_type)
1182 unsigned &StructuredIndex) {
1186 return CheckReferenceType(Entity, IList, ElemType, Index,
1187 StructuredList, StructuredIndex);
1189 if (
InitListExpr *SubInitList = dyn_cast<InitListExpr>(expr)) {
1190 if (SubInitList->getNumInits() == 1 &&
1193 expr = SubInitList->getInit(0);
1196 = getStructuredSubobjectInit(IList, Index, ElemType,
1197 StructuredList, StructuredIndex,
1199 CheckExplicitInitList(Entity, SubInitList, ElemType,
1200 InnerStructuredList);
1202 if (!hadError && !VerifyOnly) {
1203 bool RequiresSecondPass =
false;
1204 FillInEmptyInitializations(Entity, InnerStructuredList,
1205 RequiresSecondPass, StructuredList,
1207 if (RequiresSecondPass && !hadError)
1208 FillInEmptyInitializations(Entity, InnerStructuredList,
1209 RequiresSecondPass, StructuredList,
1217 }
else if (isa<ImplicitValueInitExpr>(expr)) {
1221 "found implicit initialization for the wrong type");
1223 UpdateStructuredListElement(StructuredList, StructuredIndex, expr);
1245 if (Seq || isa<InitListExpr>(expr)) {
1248 Seq.Perform(SemaRef, Entity, Kind, expr);
1252 UpdateStructuredListElement(StructuredList, StructuredIndex,
1263 return CheckScalarType(Entity, IList, ElemType, Index,
1264 StructuredList, StructuredIndex);
1274 UpdateStructuredListElement(StructuredList, StructuredIndex, expr);
1304 UpdateStructuredListElement(StructuredList, StructuredIndex,
1322 CheckImplicitInitList(Entity, IList, ElemType, Index, StructuredList,
1342 unsigned &StructuredIndex) {
1343 assert(Index == 0 &&
"Index in explicit init list must be zero");
1353 return CheckScalarType(Entity, IList, DeclType, Index, StructuredList,
1358 if (!SemaRef.
getLangOpts().CPlusPlus && !VerifyOnly)
1367 for (
unsigned i = 0; i < 2; ++i) {
1369 CheckSubElementType(ElementEntity, IList, elementType, Index,
1370 StructuredList, StructuredIndex);
1378 unsigned &StructuredIndex) {
1383 diag::warn_cxx98_compat_empty_scalar_initializer :
1384 diag::err_empty_scalar_initializer)
1393 if (
InitListExpr *SubIList = dyn_cast<InitListExpr>(expr)) {
1397 SemaRef.
Diag(SubIList->getLocStart(),
1398 diag::ext_many_braces_around_scalar_init)
1399 << SubIList->getSourceRange();
1401 CheckScalarType(Entity, SubIList, DeclType, Index, StructuredList,
1404 }
else if (isa<DesignatedInitExpr>(expr)) {
1407 diag::err_designator_for_scalar_init)
1426 Expr *ResultExpr =
nullptr;
1433 if (ResultExpr != expr) {
1435 IList->
setInit(Index, ResultExpr);
1441 UpdateStructuredListElement(StructuredList, StructuredIndex, ResultExpr);
1449 unsigned &StructuredIndex) {
1457 diag::err_init_reference_member_uninitialized)
1467 if (isa<InitListExpr>(expr) && !SemaRef.
getLangOpts().CPlusPlus11) {
1497 UpdateStructuredListElement(StructuredList, StructuredIndex, expr);
1505 unsigned &StructuredIndex) {
1508 unsigned numEltsInit = 0;
1514 CheckEmptyInitializable(
1536 Expr *ResultExpr =
nullptr;
1542 if (ResultExpr != Init) {
1544 IList->
setInit(Index, ResultExpr);
1550 UpdateStructuredListElement(StructuredList, StructuredIndex,
1559 for (
unsigned i = 0; i < maxElements; ++i, ++numEltsInit) {
1563 CheckEmptyInitializable(ElementEntity, IList->
getLocEnd());
1568 CheckSubElementType(ElementEntity, IList, elementType, Index,
1569 StructuredList, StructuredIndex);
1590 diag::warn_neon_vector_initializer_non_portable);
1592 const char *typeCode;
1602 llvm_unreachable(
"Invalid element type!");
1606 diag::note_neon_vector_initializer_non_portable_q :
1607 diag::note_neon_vector_initializer_non_portable)
1608 << typeCode << typeSize;
1618 for (
unsigned i = 0; i < maxElements; ++i) {
1627 CheckSubElementType(ElementEntity, IList, elementType, Index,
1628 StructuredList, StructuredIndex);
1640 CheckSubElementType(ElementEntity, IList, VecType, Index,
1641 StructuredList, StructuredIndex);
1642 numEltsInit += numIElts;
1647 if (numEltsInit != maxElements) {
1650 diag::err_vector_incorrect_num_initializers)
1651 << (numEltsInit < maxElements) << maxElements << numEltsInit;
1658 llvm::APSInt elementIndex,
1659 bool SubobjectIsDesignatorContext,
1662 unsigned &StructuredIndex) {
1666 if (Index < IList->getNumInits()) {
1676 UpdateStructuredListElement(StructuredList, StructuredIndex,
1689 SemaRef.
Diag(VAT->getSizeExpr()->getLocStart(),
1690 diag::err_variable_object_no_init)
1691 << VAT->getSizeExpr()->getSourceRange();
1699 llvm::APSInt maxElements(elementIndex.getBitWidth(),
1700 elementIndex.isUnsigned());
1701 bool maxElementsKnown =
false;
1703 maxElements = CAT->getSize();
1704 elementIndex = elementIndex.extOrTrunc(maxElements.getBitWidth());
1705 elementIndex.setIsUnsigned(maxElements.isUnsigned());
1706 maxElementsKnown =
true;
1710 while (Index < IList->getNumInits()) {
1716 if (!SubobjectIsDesignatorContext)
1721 if (CheckDesignatedInitializer(Entity, IList, DIE, 0,
1722 DeclType,
nullptr, &elementIndex, Index,
1723 StructuredList, StructuredIndex,
true,
1729 if (elementIndex.getBitWidth() > maxElements.getBitWidth())
1730 maxElements = maxElements.extend(elementIndex.getBitWidth());
1731 else if (elementIndex.getBitWidth() < maxElements.getBitWidth())
1732 elementIndex = elementIndex.extend(maxElements.getBitWidth());
1733 elementIndex.setIsUnsigned(maxElements.isUnsigned());
1737 if (!maxElementsKnown && elementIndex > maxElements)
1738 maxElements = elementIndex;
1745 if (maxElementsKnown && elementIndex == maxElements)
1752 CheckSubElementType(ElementEntity, IList, elementType, Index,
1753 StructuredList, StructuredIndex);
1758 if (!maxElementsKnown && elementIndex > maxElements)
1759 maxElements = elementIndex;
1764 llvm::APSInt Zero(maxElements.getBitWidth(), maxElements.isUnsigned());
1769 diag::ext_typecheck_zero_array_size);
1775 if (!hadError && VerifyOnly) {
1781 if ((maxElementsKnown && elementIndex < maxElements) ||
1792 bool TopLevelObject) {
1794 unsigned FlexArrayDiag;
1795 if (isa<InitListExpr>(InitExpr) &&
1796 cast<InitListExpr>(InitExpr)->getNumInits() == 0) {
1798 FlexArrayDiag = diag::ext_flexible_array_init;
1802 FlexArrayDiag = diag::err_flexible_array_init;
1803 }
else if (!TopLevelObject) {
1805 FlexArrayDiag = diag::err_flexible_array_init;
1808 FlexArrayDiag = diag::err_flexible_array_init;
1809 }
else if (cast<VarDecl>(Entity.
getDecl())->hasLocalStorage()) {
1811 FlexArrayDiag = diag::err_flexible_array_init;
1814 FlexArrayDiag = diag::ext_flexible_array_init;
1825 return FlexArrayDiag != diag::ext_flexible_array_init;
1828 void InitListChecker::CheckStructUnionTypes(
1831 bool SubobjectIsDesignatorContext,
unsigned &Index,
1832 InitListExpr *StructuredList,
unsigned &StructuredIndex,
1833 bool TopLevelObject) {
1849 if (isa<CXXRecordDecl>(RD) && cast<CXXRecordDecl>(RD)->hasInClassInitializer()) {
1853 Field != FieldEnd; ++Field) {
1854 if (Field->hasInClassInitializer()) {
1865 Field != FieldEnd; ++Field) {
1866 if (!Field->isUnnamedBitfield()) {
1868 CheckEmptyInitializable(
1879 bool InitializedSomething =
false;
1882 for (
auto &Base : Bases) {
1888 if (Init && isa<DesignatedInitExpr>(Init))
1892 SemaRef.
Context, &Base,
false, &Entity);
1894 CheckSubElementType(BaseEntity, IList, Base.
getType(), Index,
1895 StructuredList, StructuredIndex);
1896 InitializedSomething =
true;
1897 }
else if (VerifyOnly) {
1898 CheckEmptyInitializable(BaseEntity, InitLoc);
1908 bool CheckForMissingFields =
1911 while (Index < IList->getNumInits()) {
1918 if (!SubobjectIsDesignatorContext)
1923 if (CheckDesignatedInitializer(Entity, IList, DIE, 0,
1924 DeclType, &Field,
nullptr, Index,
1925 StructuredList, StructuredIndex,
1926 true, TopLevelObject))
1929 InitializedSomething =
true;
1933 CheckForMissingFields =
false;
1937 if (Field == FieldEnd) {
1943 if (InitializedSomething && DeclType->
isUnionType())
1947 if (Field->getType()->isIncompleteArrayType())
1950 if (Field->isUnnamedBitfield()) {
1959 InvalidUse = !SemaRef.
CanUseDecl(*Field, TreatUnavailableAsInvalid);
1972 CheckSubElementType(MemberEntity, IList, Field->getType(), Index,
1973 StructuredList, StructuredIndex);
1974 InitializedSomething =
true;
1978 StructuredList->setInitializedFieldInUnion(*Field);
1985 if (!VerifyOnly && InitializedSomething && CheckForMissingFields &&
1986 Field != FieldEnd && !Field->getType()->isIncompleteArrayType() &&
1992 if (!it->isUnnamedBitfield() && !it->hasInClassInitializer()) {
1994 diag::warn_missing_field_initializers) << *it;
2001 if (VerifyOnly && Field != FieldEnd && !DeclType->
isUnionType() &&
2002 !Field->getType()->isIncompleteArrayType()) {
2004 for (; Field != FieldEnd && !hadError; ++Field) {
2005 if (!Field->isUnnamedBitfield() && !Field->hasInClassInitializer())
2006 CheckEmptyInitializable(
2012 if (Field == FieldEnd || !Field->getType()->isIncompleteArrayType() ||
2016 if (CheckFlexibleArrayInit(Entity, IList->
getInit(Index), *Field,
2026 if (isa<InitListExpr>(IList->
getInit(Index)))
2027 CheckSubElementType(MemberEntity, IList, Field->getType(), Index,
2028 StructuredList, StructuredIndex);
2030 CheckImplicitInitList(MemberEntity, IList, Field->getType(), Index,
2031 StructuredList, StructuredIndex);
2047 PE = IndirectField->
chain_end(); PI != PE; ++PI) {
2055 assert(isa<FieldDecl>(*PI));
2056 Replacements.back().setField(cast<FieldDecl>(*PI));
2063 &Replacements[0] + Replacements.size());
2070 for (
unsigned I = 0; I < NumIndexExprs; ++I)
2084 explicit FieldInitializerValidatorCCC(
RecordDecl *RD)
2087 bool ValidateCandidate(
const TypoCorrection &candidate)
override {
2140 llvm::APSInt *NextElementIndex,
2143 unsigned &StructuredIndex,
2144 bool FinishSubobjectInit,
2145 bool TopLevelObject) {
2146 if (DesigIdx == DIE->
size()) {
2148 bool prevHadError = hadError;
2153 unsigned OldIndex = Index;
2156 CheckSubElementType(Entity, IList, CurrentObjectType, Index,
2157 StructuredList, StructuredIndex);
2163 IList->
setInit(OldIndex, DIE);
2165 return hadError && !prevHadError;
2169 bool IsFirstDesignator = (DesigIdx == 0);
2171 assert((IsFirstDesignator || StructuredList) &&
2172 "Need a non-designated initializer list to start from");
2176 if (IsFirstDesignator)
2177 StructuredList = SyntacticToSemantic.lookup(IList);
2179 Expr *ExistingInit = StructuredIndex < StructuredList->
getNumInits() ?
2180 StructuredList->
getInit(StructuredIndex) :
nullptr;
2186 getStructuredSubobjectInit(IList, Index, CurrentObjectType,
2187 StructuredList, StructuredIndex,
2194 dyn_cast<DesignatedInitUpdateExpr>(ExistingInit))
2195 StructuredList = E->getUpdater();
2226 diag::warn_subobject_initializer_overrides)
2230 diag::note_previous_initializer)
2236 assert(StructuredList &&
"Expected a structured initializer list");
2255 SemaRef.
Diag(Loc, diag::err_field_designator_non_aggr)
2256 << SemaRef.
getLangOpts().CPlusPlus << CurrentObjectType;
2266 if (
auto *FD = dyn_cast<FieldDecl>(ND)) {
2270 if (
auto *IFD = dyn_cast<IndirectFieldDecl>(ND)) {
2276 KnownField = cast<FieldDecl>(*IFD->chain_begin());
2287 if (!Lookup.empty()) {
2290 SemaRef.
Diag(Lookup.front()->getLocation(),
2291 diag::note_field_designator_found);
2301 llvm::make_unique<FieldInitializerValidatorCCC>(RT->
getDecl()),
2305 SemaRef.
PDiag(diag::err_field_designator_unknown_suggest)
2306 << FieldName << CurrentObjectType);
2307 KnownField = Corrected.getCorrectionDeclAs<
FieldDecl>();
2312 << FieldName << CurrentObjectType;
2319 unsigned FieldIndex = 0;
2321 if (
auto *CXXRD = dyn_cast<CXXRecordDecl>(RT->
getDecl()))
2322 FieldIndex = CXXRD->getNumBases();
2325 if (FI->isUnnamedBitfield())
2345 &&
"A union should never have more than one initializer!");
2351 diag::warn_initializer_overrides)
2353 SemaRef.
Diag(ExistingInit->getLocStart(),
2354 diag::note_previous_initializer)
2356 << ExistingInit->getSourceRange();
2371 InvalidUse = !SemaRef.
CanUseDecl(*Field, TreatUnavailableAsInvalid);
2390 if (Field->getType()->isIncompleteArrayType()) {
2391 bool Invalid =
false;
2392 if ((DesigIdx + 1) != DIE->
size()) {
2399 diag::err_designator_into_flexible_array_member)
2402 SemaRef.
Diag(Field->getLocation(), diag::note_flexible_array_member)
2408 if (!hadError && !isa<InitListExpr>(DIE->
getInit()) &&
2409 !isa<StringLiteral>(DIE->
getInit())) {
2413 diag::err_flexible_array_init_needs_braces)
2415 SemaRef.
Diag(Field->getLocation(), diag::note_flexible_array_member)
2422 if (!Invalid && CheckFlexibleArrayInit(Entity, DIE->
getInit(), *Field,
2432 bool prevHadError = hadError;
2433 unsigned newStructuredIndex = FieldIndex;
2434 unsigned OldIndex = Index;
2439 CheckSubElementType(MemberEntity, IList, Field->getType(), Index,
2440 StructuredList, newStructuredIndex);
2442 IList->
setInit(OldIndex, DIE);
2443 if (hadError && !prevHadError) {
2448 StructuredIndex = FieldIndex;
2453 QualType FieldType = Field->getType();
2454 unsigned newStructuredIndex = FieldIndex;
2458 if (CheckDesignatedInitializer(MemberEntity, IList, DIE, DesigIdx + 1,
2459 FieldType,
nullptr,
nullptr, Index,
2460 StructuredList, newStructuredIndex,
2461 FinishSubobjectInit,
false))
2472 if (IsFirstDesignator) {
2475 StructuredIndex = FieldIndex;
2479 if (!FinishSubobjectInit)
2487 bool prevHadError = hadError;
2492 CheckStructUnionTypes(Entity, IList, CurrentObjectType, NoBases, Field,
2493 false, Index, StructuredList, FieldIndex);
2494 return hadError && !prevHadError;
2516 << CurrentObjectType;
2521 Expr *IndexExpr =
nullptr;
2522 llvm::APSInt DesignatedStartIndex, DesignatedEndIndex;
2526 DesignatedEndIndex = DesignatedStartIndex;
2530 DesignatedStartIndex =
2532 DesignatedEndIndex =
2541 if (DesignatedStartIndex.getZExtValue()!=DesignatedEndIndex.getZExtValue()&&
2543 FullyStructuredList->sawArrayRangeDesignator();
2546 if (isa<ConstantArrayType>(AT)) {
2547 llvm::APSInt MaxElements(cast<ConstantArrayType>(AT)->getSize(),
false);
2548 DesignatedStartIndex
2549 = DesignatedStartIndex.extOrTrunc(MaxElements.getBitWidth());
2550 DesignatedStartIndex.setIsUnsigned(MaxElements.isUnsigned());
2552 = DesignatedEndIndex.extOrTrunc(MaxElements.getBitWidth());
2553 DesignatedEndIndex.setIsUnsigned(MaxElements.isUnsigned());
2554 if (DesignatedEndIndex >= MaxElements) {
2557 diag::err_array_designator_too_large)
2558 << DesignatedEndIndex.toString(10) << MaxElements.toString(10)
2564 unsigned DesignatedIndexBitWidth =
2566 DesignatedStartIndex =
2567 DesignatedStartIndex.extOrTrunc(DesignatedIndexBitWidth);
2568 DesignatedEndIndex =
2569 DesignatedEndIndex.extOrTrunc(DesignatedIndexBitWidth);
2570 DesignatedStartIndex.setIsUnsigned(
true);
2571 DesignatedEndIndex.setIsUnsigned(
true);
2587 unsigned PromotedCharTyWidth = Context.
getTypeSize(PromotedCharTy);
2591 uint64_t StrLen = SL->getLength();
2592 if (cast<ConstantArrayType>(AT)->getSize().ult(StrLen))
2593 StrLen = cast<ConstantArrayType>(AT)->getSize().getZExtValue();
2598 for (
unsigned i = 0, e = StrLen; i != e; ++i) {
2599 llvm::APInt CodeUnit(PromotedCharTyWidth, SL->getCodeUnit(i));
2601 Context, CodeUnit, PromotedCharTy, SubExpr->
getExprLoc());
2602 if (CharTy != PromotedCharTy)
2605 StructuredList->
updateInit(Context, i, Init);
2613 uint64_t StrLen = Str.size();
2614 if (cast<ConstantArrayType>(AT)->getSize().ult(StrLen))
2615 StrLen = cast<ConstantArrayType>(AT)->getSize().getZExtValue();
2620 for (
unsigned i = 0, e = StrLen; i != e; ++i) {
2621 llvm::APInt CodeUnit(PromotedCharTyWidth, Str[i]);
2623 Context, CodeUnit, PromotedCharTy, SubExpr->
getExprLoc());
2624 if (CharTy != PromotedCharTy)
2627 StructuredList->
updateInit(Context, i, Init);
2635 DesignatedEndIndex.getZExtValue() >= StructuredList->
getNumInits())
2637 DesignatedEndIndex.getZExtValue() + 1);
2643 unsigned ElementIndex = DesignatedStartIndex.getZExtValue();
2644 unsigned OldIndex = Index;
2649 while (DesignatedStartIndex <= DesignatedEndIndex) {
2655 if (CheckDesignatedInitializer(
2656 ElementEntity, IList, DIE, DesigIdx + 1, ElementType,
nullptr,
2657 nullptr, Index, StructuredList, ElementIndex,
2658 FinishSubobjectInit && (DesignatedStartIndex == DesignatedEndIndex),
2663 ++DesignatedStartIndex;
2664 ElementIndex = DesignatedStartIndex.getZExtValue();
2669 if (IsFirstDesignator) {
2670 if (NextElementIndex)
2671 *NextElementIndex = DesignatedStartIndex;
2672 StructuredIndex = ElementIndex;
2676 if (!FinishSubobjectInit)
2680 bool prevHadError = hadError;
2681 CheckArrayType(Entity, IList, CurrentObjectType, DesignatedStartIndex,
2683 StructuredList, ElementIndex);
2684 return hadError && !prevHadError;
2690 InitListChecker::getStructuredSubobjectInit(
InitListExpr *IList,
unsigned Index,
2693 unsigned StructuredIndex,
2695 bool IsFullyOverwritten) {
2698 Expr *ExistingInit =
nullptr;
2699 if (!StructuredList)
2700 ExistingInit = SyntacticToSemantic.lookup(IList);
2701 else if (StructuredIndex < StructuredList->getNumInits())
2702 ExistingInit = StructuredList->
getInit(StructuredIndex);
2713 if (!IsFullyOverwritten)
2729 diag::warn_subobject_initializer_overrides)
2732 diag::note_previous_initializer)
2742 QualType ResultType = CurrentObjectType;
2748 unsigned NumElements = 0;
2749 unsigned NumInits = 0;
2750 bool GotNumInits =
false;
2751 if (!StructuredList) {
2754 }
else if (Index < IList->getNumInits()) {
2756 NumInits = SubList->getNumInits();
2764 NumElements = CAType->getSize().getZExtValue();
2767 if (GotNumInits && NumElements > NumInits)
2771 NumElements = VType->getNumElements();
2788 SyntacticToSemantic[IList] =
Result;
2796 void InitListChecker::UpdateStructuredListElement(
InitListExpr *StructuredList,
2797 unsigned &StructuredIndex,
2800 if (!StructuredList)
2804 StructuredIndex, expr)) {
2812 if (PrevInit->getSourceRange().isValid()) {
2814 diag::warn_initializer_overrides)
2817 SemaRef.
Diag(PrevInit->getLocStart(),
2818 diag::note_previous_initializer)
2820 << PrevInit->getSourceRange();
2843 if (Value.isSigned() && Value.isNegative())
2844 return S.
Diag(Loc, diag::err_array_designator_negative)
2847 Value.setIsUnsigned(
true);
2857 bool Invalid =
false;
2872 llvm::APSInt IndexValue;
2878 Designators.push_back(ASTDesignator(InitExpressions.size(),
2881 InitExpressions.push_back(Index);
2889 llvm::APSInt StartValue;
2890 llvm::APSInt EndValue;
2895 if (!StartDependent)
2901 if (!StartIndex || !EndIndex)
2905 if (StartDependent || EndDependent) {
2907 }
else if (StartValue.getBitWidth() > EndValue.getBitWidth())
2908 EndValue = EndValue.extend(StartValue.getBitWidth());
2909 else if (StartValue.getBitWidth() < EndValue.getBitWidth())
2910 StartValue = StartValue.extend(EndValue.getBitWidth());
2912 if (!StartDependent && !EndDependent && EndValue < StartValue) {
2914 << StartValue.toString(10) << EndValue.toString(10)
2918 Designators.push_back(ASTDesignator(InitExpressions.size(),
2922 InitExpressions.push_back(StartIndex);
2923 InitExpressions.push_back(EndIndex);
2940 InitExpressions, Loc, GNUSyntax,
2943 if (!getLangOpts().
C99)
2954 InitializedEntity::InitializedEntity(
ASTContext &Context,
unsigned Index,
2956 :
Parent(&Parent), Index(Index)
2959 Kind = EK_ArrayElement;
2960 Type = AT->getElementType();
2962 Kind = EK_VectorElement;
2963 Type = VT->getElementType();
2966 assert(CT &&
"Unexpected type");
2967 Kind = EK_ComplexElement;
2975 bool IsInheritedVirtualBase,
2978 Result.Kind = EK_Base;
2981 if (IsInheritedVirtualBase)
2982 Result.
Base |= 0x01;
2984 Result.Type = Base->
getType();
2991 case EK_Parameter_CF_Audited: {
2999 return Variable.VariableOrMember->getDeclName();
3001 case EK_LambdaCapture:
3005 case EK_StmtExprResult:
3011 case EK_ArrayElement:
3012 case EK_VectorElement:
3013 case EK_ComplexElement:
3014 case EK_BlockElement:
3015 case EK_LambdaToBlockConversionBlockElement:
3016 case EK_CompoundLiteralInit:
3017 case EK_RelatedResult:
3021 llvm_unreachable(
"Invalid EntityKind!");
3029 return Variable.VariableOrMember;
3032 case EK_Parameter_CF_Audited:
3036 case EK_StmtExprResult:
3042 case EK_ArrayElement:
3043 case EK_VectorElement:
3044 case EK_ComplexElement:
3045 case EK_BlockElement:
3046 case EK_LambdaToBlockConversionBlockElement:
3047 case EK_LambdaCapture:
3048 case EK_CompoundLiteralInit:
3049 case EK_RelatedResult:
3053 llvm_unreachable(
"Invalid EntityKind!");
3060 return LocAndNRVO.NRVO;
3062 case EK_StmtExprResult:
3065 case EK_Parameter_CF_Audited:
3070 case EK_CompoundLiteralInit:
3073 case EK_ArrayElement:
3074 case EK_VectorElement:
3075 case EK_ComplexElement:
3076 case EK_BlockElement:
3077 case EK_LambdaToBlockConversionBlockElement:
3078 case EK_LambdaCapture:
3079 case EK_RelatedResult:
3086 unsigned InitializedEntity::dumpImpl(raw_ostream &OS)
const {
3087 assert(getParent() !=
this);
3088 unsigned Depth = getParent() ? getParent()->dumpImpl(OS) : 0;
3089 for (
unsigned I = 0; I !=
Depth; ++I)
3093 case EK_Variable: OS <<
"Variable";
break;
3094 case EK_Parameter: OS <<
"Parameter";
break;
3095 case EK_Parameter_CF_Audited: OS <<
"CF audited function Parameter";
3097 case EK_Result: OS <<
"Result";
break;
3098 case EK_StmtExprResult: OS <<
"StmtExprResult";
break;
3099 case EK_Exception: OS <<
"Exception";
break;
3100 case EK_Member: OS <<
"Member";
break;
3101 case EK_Binding: OS <<
"Binding";
break;
3102 case EK_New: OS <<
"New";
break;
3103 case EK_Temporary: OS <<
"Temporary";
break;
3104 case EK_CompoundLiteralInit: OS <<
"CompoundLiteral";
break;
3105 case EK_RelatedResult: OS <<
"RelatedResult";
break;
3106 case EK_Base: OS <<
"Base";
break;
3107 case EK_Delegating: OS <<
"Delegating";
break;
3108 case EK_ArrayElement: OS <<
"ArrayElement " << Index;
break;
3109 case EK_VectorElement: OS <<
"VectorElement " << Index;
break;
3110 case EK_ComplexElement: OS <<
"ComplexElement " << Index;
break;
3111 case EK_BlockElement: OS <<
"Block";
break;
3112 case EK_LambdaToBlockConversionBlockElement:
3113 OS <<
"Block (lambda)";
3115 case EK_LambdaCapture:
3116 OS <<
"LambdaCapture ";
3121 if (
auto *D = getDecl()) {
3123 D->printQualifiedName(OS);
3126 OS <<
" '" << getType().getAsString() <<
"'\n";
3132 dumpImpl(llvm::errs());
3141 case SK_ResolveAddressOfOverloadedFunction:
3142 case SK_CastDerivedToBaseRValue:
3143 case SK_CastDerivedToBaseXValue:
3144 case SK_CastDerivedToBaseLValue:
3145 case SK_BindReference:
3146 case SK_BindReferenceToTemporary:
3148 case SK_ExtraneousCopyToTemporary:
3149 case SK_UserConversion:
3150 case SK_QualificationConversionRValue:
3151 case SK_QualificationConversionXValue:
3152 case SK_QualificationConversionLValue:
3153 case SK_AtomicConversion:
3154 case SK_LValueToRValue:
3155 case SK_ListInitialization:
3156 case SK_UnwrapInitList:
3157 case SK_RewrapInitList:
3158 case SK_ConstructorInitialization:
3159 case SK_ConstructorInitializationFromList:
3160 case SK_ZeroInitialization:
3161 case SK_CAssignment:
3163 case SK_ObjCObjectConversion:
3164 case SK_ArrayLoopIndex:
3165 case SK_ArrayLoopInit:
3167 case SK_GNUArrayInit:
3168 case SK_ParenthesizedArrayInit:
3169 case SK_PassByIndirectCopyRestore:
3170 case SK_PassByIndirectRestore:
3171 case SK_ProduceObjCObject:
3172 case SK_StdInitializerList:
3173 case SK_StdInitializerListConstructorCall:
3174 case SK_OCLSamplerInit:
3175 case SK_OCLZeroEvent:
3176 case SK_OCLZeroQueue:
3179 case SK_ConversionSequence:
3180 case SK_ConversionSequenceNoNarrowing:
3187 for (
auto I = Steps.rbegin(); I != Steps.rend(); ++I) {
3188 if (I->Kind == SK_BindReference)
3190 if (I->Kind == SK_BindReferenceToTemporary)
3200 switch (getFailureKind()) {
3201 case FK_TooManyInitsForReference:
3202 case FK_ParenthesizedListInitForReference:
3203 case FK_ArrayNeedsInitList:
3204 case FK_ArrayNeedsInitListOrStringLiteral:
3205 case FK_ArrayNeedsInitListOrWideStringLiteral:
3206 case FK_NarrowStringIntoWideCharArray:
3207 case FK_WideStringIntoCharArray:
3208 case FK_IncompatWideStringIntoWideChar:
3209 case FK_PlainStringIntoUTF8Char:
3210 case FK_UTF8StringIntoPlainChar:
3211 case FK_AddressOfOverloadFailed:
3212 case FK_NonConstLValueReferenceBindingToTemporary:
3213 case FK_NonConstLValueReferenceBindingToBitfield:
3214 case FK_NonConstLValueReferenceBindingToVectorElement:
3215 case FK_NonConstLValueReferenceBindingToUnrelated:
3216 case FK_RValueReferenceBindingToLValue:
3217 case FK_ReferenceInitDropsQualifiers:
3218 case FK_ReferenceInitFailed:
3219 case FK_ConversionFailed:
3220 case FK_ConversionFromPropertyFailed:
3221 case FK_TooManyInitsForScalar:
3222 case FK_ParenthesizedListInitForScalar:
3223 case FK_ReferenceBindingToInitList:
3224 case FK_InitListBadDestinationType:
3225 case FK_DefaultInitOfConst:
3227 case FK_ArrayTypeMismatch:
3228 case FK_NonConstantArrayInit:
3229 case FK_ListInitializationFailed:
3230 case FK_VariableLengthArrayHasInitializer:
3231 case FK_PlaceholderType:
3232 case FK_ExplicitConstructor:
3233 case FK_AddressOfUnaddressableFunction:
3236 case FK_ReferenceInitOverloadFailed:
3237 case FK_UserConversionOverloadFailed:
3238 case FK_ConstructorOverloadFailed:
3239 case FK_ListConstructorOverloadFailed:
3243 llvm_unreachable(
"Invalid EntityKind!");
3247 return !Steps.empty() && Steps.back().Kind == SK_ConstructorInitialization;
3254 bool HadMultipleCandidates) {
3256 S.
Kind = SK_ResolveAddressOfOverloadedFunction;
3277 bool BindingTemporary) {
3279 S.
Kind = BindingTemporary? SK_BindReferenceToTemporary : SK_BindReference;
3286 S.
Kind = SK_FinalCopy;
3293 S.
Kind = SK_ExtraneousCopyToTemporary;
3302 bool HadMultipleCandidates) {
3304 S.
Kind = SK_UserConversion;
3315 S.
Kind = SK_QualificationConversionRValue;
3318 S.
Kind = SK_QualificationConversionRValue;
3321 S.
Kind = SK_QualificationConversionXValue;
3324 S.
Kind = SK_QualificationConversionLValue;
3333 S.
Kind = SK_AtomicConversion;
3339 assert(!Ty.
hasQualifiers() &&
"rvalues may not have qualifiers");
3342 S.Kind = SK_LValueToRValue;
3349 bool TopLevelOfInitList) {
3351 S.
Kind = TopLevelOfInitList ? SK_ConversionSequenceNoNarrowing
3352 : SK_ConversionSequence;
3360 S.
Kind = SK_ListInitialization;
3367 bool HadMultipleCandidates,
bool FromInitList,
bool AsInitList) {
3369 S.
Kind = FromInitList ? AsInitList ? SK_StdInitializerListConstructorCall
3370 : SK_ConstructorInitializationFromList
3371 : SK_ConstructorInitialization;
3381 S.
Kind = SK_ZeroInitialization;
3388 S.
Kind = SK_CAssignment;
3395 S.
Kind = SK_StringInit;
3402 S.
Kind = SK_ObjCObjectConversion;
3409 S.
Kind = IsGNUExtension ? SK_GNUArrayInit : SK_ArrayInit;
3416 S.
Kind = SK_ArrayLoopIndex;
3418 Steps.insert(Steps.begin(), S);
3420 S.
Kind = SK_ArrayLoopInit;
3427 S.
Kind = SK_ParenthesizedArrayInit;
3435 s.
Kind = (shouldCopy ? SK_PassByIndirectCopyRestore
3436 : SK_PassByIndirectRestore);
3443 S.
Kind = SK_ProduceObjCObject;
3450 S.
Kind = SK_StdInitializerList;
3457 S.
Kind = SK_OCLSamplerInit;
3464 S.
Kind = SK_OCLZeroEvent;
3471 S.
Kind = SK_OCLZeroQueue;
3479 "Can only rewrap trivial init lists.");
3481 S.Kind = SK_UnwrapInitList;
3483 Steps.insert(Steps.begin(), S);
3485 S.Kind = SK_RewrapInitList;
3487 S.WrappingSyntacticList = Syntactic;
3493 setSequenceKind(FailedSequence);
3494 this->Failure = Failure;
3495 this->FailedOverloadResult =
Result;
3516 if (!Init.empty()) {
3536 "consuming an object of unretainable type?");
3557 bool TreatUnavailableAsInvalid);
3568 bool TreatUnavailableAsInvalid) {
3588 TreatUnavailableAsInvalid);
3618 bool CopyInitializing,
bool AllowExplicit,
3619 bool OnlyListConstructors,
bool IsListInit,
3620 bool SecondStepOfCopyInit =
false) {
3625 if (!Info.Constructor || Info.Constructor->isInvalidDecl())
3628 if (!AllowExplicit && Info.Constructor->isExplicit())
3645 bool SuppressUserConversions =
3646 SecondStepOfCopyInit ||
3647 (IsListInit && Args.size() == 1 && isa<InitListExpr>(Args[0]) &&
3650 if (Info.ConstructorTmpl)
3653 CandidateSet, SuppressUserConversions);
3662 bool AllowExplicitConv = AllowExplicit && !CopyInitializing &&
3666 CandidateSet, SuppressUserConversions,
3683 if (S.
getLangOpts().CPlusPlus17 && Args.size() == 1 &&
3684 !SecondStepOfCopyInit) {
3685 Expr *Initializer = Args[0];
3689 for (
auto I = Conversions.begin(), E = Conversions.end(); I != E; ++I) {
3699 Conv = cast<CXXConversionDecl>(D);
3701 if ((AllowExplicit && !CopyInitializing) || !Conv->isExplicit()) {
3704 ActingDC, Initializer, DestType,
3705 CandidateSet, AllowExplicit,
3709 DestType, CandidateSet, AllowExplicit,
3736 bool IsListInit =
false,
3737 bool IsInitListCopy =
false) {
3738 assert(((!IsListInit && !IsInitListCopy) ||
3739 (Args.size() == 1 && isa<InitListExpr>(Args[0]))) &&
3740 "IsListInit/IsInitListCopy must come with a single initializer list " 3743 (IsListInit || IsInitListCopy) ? cast<InitListExpr>(Args[0]) :
nullptr;
3767 UnwrappedArgs.size() == 1 && UnwrappedArgs[0]->isRValue() &&
3777 assert(DestRecordType &&
"Constructor initialization requires record type");
3779 = cast<CXXRecordDecl>(DestRecordType->
getDecl());
3797 bool AsInitializerList =
false;
3809 AsInitializerList =
true;
3815 CandidateSet, DestType, Ctors, Best,
3816 CopyInitialization, AllowExplicit,
3827 AsInitializerList =
false;
3829 CandidateSet, DestType, Ctors, Best,
3830 CopyInitialization, AllowExplicit,
3842 bool HadMultipleCandidates = (CandidateSet.size() > 1);
3846 if (
auto *CD = dyn_cast<CXXConversionDecl>(Best->Function)) {
3848 QualType ConvType = CD->getConversionType();
3850 "should not have selected this conversion function");
3852 HadMultipleCandidates);
3889 Best->FoundDecl, CtorDecl, DestArrayType, HadMultipleCandidates,
3890 IsListInit | IsInitListCopy, AsInitializerList);
3903 bool HadMultipleCandidates =
false;
3906 UnqualifiedTargetType,
3908 &HadMultipleCandidates)) {
3910 HadMultipleCandidates);
3911 SourceType = Fn->getType();
3943 bool TreatUnavailableAsInvalid) {
3978 bool dummy1, dummy2, dummy3;
3985 T1Quals, cv2T2, T2, T2Quals, Sequence);
4000 TreatUnavailableAsInvalid);
4017 bool TreatUnavailableAsInvalid) {
4029 TreatUnavailableAsInvalid);
4055 Expr *InitListAsExpr = InitList;
4065 if (!isa<VariableArrayType>(DestAT) &&
4075 TreatUnavailableAsInvalid);
4108 TreatUnavailableAsInvalid))
4112 Expr *InitListAsExpr = InitList;
4114 DestType, Sequence,
true);
4132 ET && ET->getDecl()->isFixed() &&
4188 TreatUnavailableAsInvalid);
4195 InitListChecker CheckInitList(S, Entity, InitList,
4196 DestType,
true, TreatUnavailableAsInvalid);
4197 if (CheckInitList.HadError()) {
4210 Expr *Initializer,
bool AllowRValues,
bool IsLValueRef,
4219 bool ObjCConversion;
4220 bool ObjCLifetimeConversion;
4222 T1, T2, DerivedToBase,
4224 ObjCLifetimeConversion) &&
4225 "Must have incompatible references when binding via conversion");
4226 (void)DerivedToBase;
4227 (void)ObjCConversion;
4228 (void)ObjCLifetimeConversion;
4239 bool AllowExplicitCtors =
false;
4251 if (!Info.Constructor)
4254 if (!Info.Constructor->isInvalidDecl() &&
4255 Info.Constructor->isConvertingConstructor(AllowExplicitCtors)) {
4256 if (Info.ConstructorTmpl)
4259 Initializer, CandidateSet,
4263 Initializer, CandidateSet,
4279 for (
auto I = Conversions.begin(), E = Conversions.end(); I != E; ++I) {
4282 if (isa<UsingShadowDecl>(D))
4283 D = cast<UsingShadowDecl>(D)->getTargetDecl();
4290 Conv = cast<CXXConversionDecl>(D);
4298 if ((AllowExplicitConvs || !Conv->isExplicit()) &&
4299 (AllowRValues || Conv->getConversionType()->isLValueReferenceType())){
4302 ActingDC, Initializer,
4303 DestType, CandidateSet,
4308 Initializer, DestType, CandidateSet,
4331 if (isa<CXXConversionDecl>(Function))
4344 bool HadMultipleCandidates = (CandidateSet.
size() > 1);
4346 HadMultipleCandidates);
4350 bool NewDerivedToBase =
false;
4351 bool NewObjCConversion =
false;
4352 bool NewObjCLifetimeConversion =
false;
4355 NewDerivedToBase, NewObjCConversion,
4356 NewObjCLifetimeConversion);
4360 assert(!isa<CXXConstructorDecl>(Function) &&
4361 "should not have conversion after constructor");
4365 ICS.
Standard = Best->FinalConversion;
4386 if (NewDerivedToBase)
4388 else if (NewObjCConversion)
4421 T1Quals, cv2T2, T2, T2Quals, Sequence);
4446 bool DerivedToBase =
false;
4447 bool ObjCConversion =
false;
4448 bool ObjCLifetimeConversion =
false;
4452 ObjCConversion, ObjCLifetimeConversion);
4465 if (isLValueRef || T1Function) {
4472 if (T1Quals != T2Quals)
4481 else if (ObjCConversion)
4500 (isLValueRef || InitCategory.
isRValue())) {
4502 S, Entity, Kind, Initializer, isRValueRef,
4503 isLValueRef, Sequence);
4528 switch (RefRelationship) {
4532 FK_NonConstLValueReferenceBindingToBitfield;
4535 FK_NonConstLValueReferenceBindingToVectorElement;
4537 llvm_unreachable(
"unexpected kind of compatible initializer");
4589 if (T1Quals != T2Quals)
4598 else if (ObjCConversion)
4612 S, Entity, Kind, Initializer,
true,
4613 isLValueRef, Sequence);
4623 isRValueRef && InitCategory.
isLValue()) {
4674 (T1CVRQuals | T2CVRQuals) != T1CVRQuals) {
4707 assert((!InitList || InitList->
getNumInits() == 0) &&
4708 "Shouldn't use value-init for non-empty init lists");
4719 if (
CXXRecordDecl *ClassDecl = dyn_cast<CXXRecordDecl>(RT->getDecl())) {
4720 bool NeedZeroInitialization =
true;
4735 NeedZeroInitialization =
false;
4743 if (NeedZeroInitialization)
4757 ClassDecl->hasUninitializedReferenceMember()) {
4765 Expr *InitListAsExpr = InitList;
4767 bool InitListSyntax = InitList;
4772 S, Entity, Kind, Args, T, Entity.
getType(), Sequence, InitListSyntax);
4794 if (DestType->isRecordType() && S.
getLangOpts().CPlusPlus) {
4805 if (DestType.isConstQualified() && S.
getLangOpts().CPlusPlus) {
4812 if (DestType.getQualifiers().hasObjCLifetime()) {
4826 bool TopLevelOfInitList) {
4827 assert(!DestType->
isReferenceType() &&
"References are handled elsewhere");
4829 assert((DestType->
isRecordType() || SourceType->isRecordType()) &&
4830 "Must have a class type to perform a user-defined conversion");
4845 = cast<CXXRecordDecl>(DestRecordType->getDecl());
4851 if (!Info.Constructor)
4854 if (!Info.Constructor->isInvalidDecl() &&
4855 Info.Constructor->isConvertingConstructor(AllowExplicit)) {
4856 if (Info.ConstructorTmpl)
4859 Initializer, CandidateSet,
4863 Initializer, CandidateSet,
4880 = cast<CXXRecordDecl>(SourceRecordType->getDecl());
4882 const auto &Conversions =
4884 for (
auto I = Conversions.begin(), E = Conversions.end(); I != E; ++I) {
4887 if (isa<UsingShadowDecl>(D))
4888 D = cast<UsingShadowDecl>(D)->getTargetDecl();
4895 Conv = cast<CXXConversionDecl>(D);
4897 if (AllowExplicit || !Conv->isExplicit()) {
4900 ActingDC, Initializer, DestType,
4901 CandidateSet, AllowExplicit);
4904 Initializer, DestType, CandidateSet,
4923 bool HadMultipleCandidates = (CandidateSet.
size() > 1);
4925 if (isa<CXXConstructorDecl>(Function)) {
4931 HadMultipleCandidates);
4960 HadMultipleCandidates);
4983 if (Best->FinalConversion.First || Best->FinalConversion.Second ||
4984 Best->FinalConversion.Third) {
4987 ICS.
Standard = Best->FinalConversion;
5005 isa<CXXBoolLiteralExpr>(Init) &&
5006 !cast<CXXBoolLiteralExpr>(Init)->getValue() &&
5015 bool isAddressOf,
bool &isWeakAccess) {
5021 if (op->getOpcode() == UO_AddrOf)
5026 }
else if (
CastExpr *ce = dyn_cast<CastExpr>(e)) {
5027 switch (ce->getCastKind()) {
5030 case CK_LValueBitCast:
5034 case CK_ArrayToPointerDecay:
5037 case CK_NullToPointer:
5045 }
else if (isa<DeclRefExpr>(e)) {
5049 isWeakAccess =
true;
5053 VarDecl *var = dyn_cast<
VarDecl>(cast<DeclRefExpr>(e)->getDecl());
5067 }
else if (isa<ArraySubscriptExpr>(e)) {
5083 bool isWeakAccess =
false;
5087 if (S.
getLangOpts().ObjCAutoRefCount && isWeakAccess)
5093 << ((
unsigned) iik - 1)
5118 Expr *Initializer) {
5119 bool ArrayDecay =
false;
5124 ArgPointee = ArgArrayType->getElementType();
5136 bool ShouldCopy =
true;
5141 if (ArrayDecay || Initializer->
isGLValue()) {
5165 Expr *Initializer) {
5186 Expr *Initializer) {
5199 Expr *Initializer) {
5214 bool TopLevelOfInitList,
5215 bool TreatUnavailableAsInvalid)
5218 TreatUnavailableAsInvalid);
5225 if (!DRE || !isa<FunctionDecl>(DRE->getDecl()))
5229 cast<FunctionDecl>(DRE->getDecl()));
5246 return isa<DecompositionDecl>(Entity.
getDecl());
5272 bool TopLevelOfInitList,
5273 bool TreatUnavailableAsInvalid) {
5280 for (
unsigned I = 0, E = Args.size(); I != E; ++I)
5281 if (Args[I]->getType()->isNonOverloadPlaceholderType()) {
5288 Args[I] = result.
get();
5309 Expr *Initializer =
nullptr;
5310 if (Args.size() == 1) {
5311 Initializer = Args[0];
5314 DestType, Initializer->
getType(),
5317 Args[0] = Initializer;
5319 if (!isa<InitListExpr>(Initializer))
5320 SourceType = Initializer->
getType();
5326 if (
InitListExpr *InitList = dyn_cast_or_null<InitListExpr>(Initializer)) {
5328 TreatUnavailableAsInvalid);
5340 if (Args.size() != 1)
5346 else if (isa<InitListExpr>(Args[0]))
5372 if (Initializer && isa<VariableArrayType>(DestAT)) {
5404 if (Initializer && isa<ConstantArrayType>(DestAT) &&
5422 Expr *OVEAsExpr = &OVE;
5424 TreatUnavailableAsInvalid);
5434 isa<CompoundLiteralExpr>(Initializer->
IgnoreParens()) &&
5450 Initializer && isa<InitListExpr>(Initializer)) {
5452 *
this, TreatUnavailableAsInvalid);
5454 }
else if (DestAT->getElementType()->isCharType())
5466 bool allowObjCWritebackConversion = S.
getLangOpts().ObjCAutoRefCount &&
5473 if (allowObjCWritebackConversion &&
5506 DestType, DestType, *
this);
5515 TopLevelOfInitList);
5519 assert(Args.size() >= 1 &&
"Zero-argument case handled above");
5522 if (Args.size() > 1) {
5525 }
else if (isa<InitListExpr>(Args[0])) {
5535 bool NeedAtomicConversion =
false;
5539 Atomic->getValueType())) {
5540 DestType = Atomic->getValueType();
5541 NeedAtomicConversion =
true;
5546 TopLevelOfInitList);
5548 if (!
Failed() && NeedAtomicConversion)
5565 allowObjCWritebackConversion);
5573 bool ShouldCopy =
true;
5589 }
else if (ICS.
isBad()) {
5610 for (
auto &S : Steps)
5662 llvm_unreachable(
"Invalid EntityKind!");
5694 llvm_unreachable(
"missed an InitializedEntity kind?");
5726 llvm_unreachable(
"missed an InitializedEntity kind?");
5731 Expr *Initializer) {
5763 llvm_unreachable(
"missed an InitializedEntity kind?");
5790 bool IsExtraneousCopy) {
5797 Class = cast<CXXRecordDecl>(Record->getDecl());
5815 S, Loc, CurInitExpr, CandidateSet, T, Ctors, Best,
5824 ? diag::ext_rvalue_to_reference_temp_copy_no_viable
5825 : diag::err_temp_copy_no_viable)
5834 S.
Diag(Loc, diag::err_temp_copy_ambiguous)
5841 S.
Diag(Loc, diag::err_temp_copy_deleted)
5848 bool HadMultipleCandidates = CandidateSet.
size() > 1;
5857 if (IsExtraneousCopy) {
5868 for (
unsigned I = 1, N = Constructor->
getNumParams(); I != N; ++I) {
5871 diag::err_call_incomplete_argument))
5911 Best->Function->getParamDecl(0)->getType().getNonReferenceType(),
5918 HadMultipleCandidates,
5936 Expr *CurInitExpr) {
5955 S, Loc, CurInitExpr, CandidateSet, CurInitExpr->
getType(), Ctors, Best,
5967 Best->FoundDecl, Entity, Diag);
5988 void InitializationSequence::PrintInitLocationNote(
Sema &S,
6003 diag::note_method_return_type_change)
6027 return NumArgs != 1;
6039 bool &ConstructorInitRequiresZeroInit,
6040 bool IsListInitialization,
6041 bool IsStdInitListInitialization,
6044 unsigned NumArgs = Args.size();
6059 assert(Constructor->
getParent() &&
"No parent class for constructor.");
6073 bool AllowExplicitConv =
6081 Loc, ConstructorArgs,
6083 IsListInitialization))
6097 if (
auto *Shadow = dyn_cast<ConstructorUsingShadowDecl>(
6108 ConstructorArgs, ParenOrBraceRange, HadMultipleCandidates,
6109 IsListInitialization, IsStdInitListInitialization,
6110 ConstructorInitRequiresZeroInit);
6126 if (IsListInitialization)
6127 ParenOrBraceRange =
SourceRange(LBraceLoc, RBraceLoc);
6138 HadMultipleCandidates,
6139 IsListInitialization,
6140 IsStdInitListInitialization,
6141 ConstructorInitRequiresZeroInit,
6149 HadMultipleCandidates,
6150 IsListInitialization,
6151 IsStdInitListInitialization,
6152 ConstructorInitRequiresZeroInit,
6196 using LifetimeResult =
6197 llvm::PointerIntPair<const InitializedEntity *, 3, LifetimeKind>;
6210 return {Entity, LK_Extended};
6230 : LK_MemInitializer};
6235 return {Entity, LK_Extended};
6242 return {
nullptr, LK_FullExpression};
6248 return {
nullptr, LK_Return};
6253 return {
nullptr, LK_StmtExprResult};
6259 return {
nullptr, LK_New};
6267 return {
nullptr, LK_FullExpression};
6277 return {InitField, LK_MemInitializer};
6284 return {InitField, LK_MemInitializer};
6291 return {
nullptr, LK_FullExpression};
6295 return {
nullptr, LK_FullExpression};
6297 llvm_unreachable(
"unknown entity kind");
6303 RK_ReferenceBinding,
6306 RK_StdInitializerList,
6314 using Local =
Expr*;
6319 struct IndirectLocalPathEntry {
6328 const Decl *D =
nullptr;
6329 IndirectLocalPathEntry() {}
6332 :
Kind(K), E(E), D(D) {}
6337 struct RevertToOldSizeRAII {
6338 IndirectLocalPath &Path;
6339 unsigned OldSize = Path.size();
6340 RevertToOldSizeRAII(IndirectLocalPath &Path) : Path(Path) {}
6341 ~RevertToOldSizeRAII() { Path.resize(OldSize); }
6344 using LocalVisitor = llvm::function_ref<
bool(IndirectLocalPath &Path, Local L,
6350 if (E.Kind == IndirectLocalPathEntry::VarInit && E.D == VD)
6356 return std::any_of(Path.begin(), Path.end(), [=](IndirectLocalPathEntry E) {
6357 return E.Kind == IndirectLocalPathEntry::DefaultInit ||
6358 E.Kind == IndirectLocalPathEntry::VarInit;
6363 Expr *Init, LocalVisitor Visit,
6364 bool RevisitSubinits);
6368 LocalVisitor Visit);
6388 LocalVisitor Visit) {
6392 if (
auto *CE = dyn_cast<CallExpr>(Call)) {
6393 Callee = CE->getDirectCallee();
6394 Args = llvm::makeArrayRef(CE->getArgs(), CE->getNumArgs());
6396 auto *CCE = cast<CXXConstructExpr>(Call);
6397 Callee = CCE->getConstructor();
6398 Args = llvm::makeArrayRef(CCE->getArgs(), CCE->getNumArgs());
6403 Expr *ObjectArg =
nullptr;
6405 ObjectArg = Args[0];
6406 Args = Args.slice(1);
6407 }
else if (
auto *MCE = dyn_cast<CXXMemberCallExpr>(Call)) {
6408 ObjectArg = MCE->getImplicitObjectArgument();
6411 auto VisitLifetimeBoundArg = [&](
const Decl *D,
Expr *Arg) {
6412 Path.push_back({IndirectLocalPathEntry::LifetimeBoundCall, Arg, D});
6413 if (Arg->isGLValue())
6422 VisitLifetimeBoundArg(Callee, ObjectArg);
6424 for (
unsigned I = 0,
6425 N = std::min<unsigned>(Callee->
getNumParams(), Args.size());
6428 VisitLifetimeBoundArg(Callee->
getParamDecl(I), Args[I]);
6436 LocalVisitor Visit) {
6437 RevertToOldSizeRAII RAII(Path);
6444 if (
auto *EWC = dyn_cast<ExprWithCleanups>(Init))
6445 Init = EWC->getSubExpr();
6447 if (
InitListExpr *ILE = dyn_cast<InitListExpr>(Init)) {
6459 if (
CastExpr *CE = dyn_cast<CastExpr>(Init))
6460 if (CE->getSubExpr()->isGLValue())
6461 Init = CE->getSubExpr();
6465 if (
auto *ASE = dyn_cast<ArraySubscriptExpr>(Init)) {
6466 Init = ASE->getBase();
6468 if (ICE && ICE->getCastKind() == CK_ArrayToPointerDecay)
6469 Init = ICE->getSubExpr();
6478 if (
auto *DIE = dyn_cast<CXXDefaultInitExpr>(Init)) {
6480 {IndirectLocalPathEntry::DefaultInit, DIE, DIE->getField()});
6481 Init = DIE->getExpr();
6483 }
while (Init != Old);
6485 if (
auto *MTE = dyn_cast<MaterializeTemporaryExpr>(Init)) {
6486 if (Visit(Path, Local(MTE), RK))
6491 if (isa<CallExpr>(Init))
6495 case Stmt::DeclRefExprClass: {
6498 auto *DRE = cast<DeclRefExpr>(Init);
6499 auto *VD = dyn_cast<
VarDecl>(DRE->getDecl());
6500 if (VD && VD->hasLocalStorage() &&
6501 !DRE->refersToEnclosingVariableOrCapture()) {
6502 if (!VD->getType()->isReferenceType()) {
6503 Visit(Path, Local(DRE), RK);
6504 }
else if (isa<ParmVarDecl>(DRE->getDecl())) {
6508 }
else if (VD->getInit() && !
isVarOnPath(Path, VD)) {
6509 Path.push_back({IndirectLocalPathEntry::VarInit, DRE, VD});
6511 RK_ReferenceBinding, Visit);
6517 case Stmt::UnaryOperatorClass: {
6527 case Stmt::OMPArraySectionExprClass: {
6529 Path, cast<OMPArraySectionExpr>(Init)->getBase(), Visit,
true);
6533 case Stmt::ConditionalOperatorClass:
6534 case Stmt::BinaryConditionalOperatorClass: {
6535 auto *
C = cast<AbstractConditionalOperator>(Init);
6536 if (!
C->getTrueExpr()->getType()->isVoidType())
6538 if (!
C->getFalseExpr()->getType()->isVoidType())
6553 Expr *Init, LocalVisitor Visit,
6554 bool RevisitSubinits) {
6555 RevertToOldSizeRAII RAII(Path);
6563 if (
auto *DIE = dyn_cast<CXXDefaultInitExpr>(Init)) {
6564 Path.push_back({IndirectLocalPathEntry::DefaultInit, DIE, DIE->getField()});
6565 Init = DIE->getExpr();
6568 if (
auto *EWC = dyn_cast<ExprWithCleanups>(Init))
6569 Init = EWC->getSubExpr();
6575 Init = BTE->getSubExpr();
6580 if (
auto *CE = dyn_cast<CastExpr>(Init)) {
6581 switch (CE->getCastKind()) {
6582 case CK_LValueToRValue:
6585 Path.push_back({IndirectLocalPathEntry::LValToRVal, CE});
6587 Path, Init, RK_ReferenceBinding,
6588 [&](IndirectLocalPath &Path, Local L,
ReferenceKind RK) ->
bool {
6589 if (
auto *DRE = dyn_cast<DeclRefExpr>(L)) {
6590 auto *VD = dyn_cast<
VarDecl>(DRE->getDecl());
6591 if (VD && VD->getType().isConstQualified() && VD->getInit() &&
6593 Path.push_back({IndirectLocalPathEntry::VarInit, DRE, VD});
6596 }
else if (
auto *MTE = dyn_cast<MaterializeTemporaryExpr>(L)) {
6597 if (MTE->getType().isConstQualified())
6610 case CK_BaseToDerived:
6611 case CK_DerivedToBase:
6612 case CK_UncheckedDerivedToBase:
6615 case CK_UserDefinedConversion:
6616 case CK_ConstructorConversion:
6617 case CK_IntegralToPointer:
6618 case CK_PointerToIntegral:
6619 case CK_VectorSplat:
6620 case CK_IntegralCast:
6621 case CK_CPointerToObjCPointerCast:
6622 case CK_BlockPointerToObjCPointerCast:
6623 case CK_AnyPointerToBlockPointerCast:
6624 case CK_AddressSpaceConversion:
6627 case CK_ArrayToPointerDecay:
6630 Path.push_back({IndirectLocalPathEntry::AddressOf, CE});
6632 RK_ReferenceBinding, Visit);
6638 Init = CE->getSubExpr();
6640 }
while (Old != Init);
6645 if (
auto *ILE = dyn_cast<CXXStdInitializerListExpr>(Init))
6647 RK_StdInitializerList, Visit);
6649 if (
InitListExpr *ILE = dyn_cast<InitListExpr>(Init)) {
6653 if (!RevisitSubinits)
6661 for (
unsigned I = 0, N = ILE->
getNumInits(); I != N; ++I)
6668 assert(RD->isAggregate() &&
"aggregate init on non-aggregate");
6676 RK_ReferenceBinding, Visit);
6679 for (
const auto *I : RD->fields()) {
6682 if (I->isUnnamedBitfield())
6685 if (I->getType()->isReferenceType())
6687 RK_ReferenceBinding, Visit);
6701 if (isa<CallExpr>(Init) || isa<CXXConstructExpr>(Init))
6705 case Stmt::UnaryOperatorClass: {
6706 auto *UO = cast<UnaryOperator>(Init);
6709 if (UO->getOpcode() == UO_AddrOf) {
6713 if (isa<MaterializeTemporaryExpr>(UO->getSubExpr()))
6716 Path.push_back({IndirectLocalPathEntry::AddressOf, UO});
6718 RK_ReferenceBinding, Visit);
6723 case Stmt::BinaryOperatorClass: {
6725 auto *BO = cast<BinaryOperator>(Init);
6727 if (!BO->getType()->isPointerType() || (BOK != BO_Add && BOK != BO_Sub))
6730 if (BO->getLHS()->getType()->isPointerType())
6732 else if (BO->getRHS()->getType()->isPointerType())
6737 case Stmt::ConditionalOperatorClass:
6738 case Stmt::BinaryConditionalOperatorClass: {
6739 auto *
C = cast<AbstractConditionalOperator>(Init);
6742 if (!
C->getTrueExpr()->getType()->isVoidType())
6744 if (!
C->getFalseExpr()->getType()->isVoidType())
6749 case Stmt::BlockExprClass:
6750 if (cast<BlockExpr>(Init)->getBlockDecl()->hasCaptures()) {
6752 Visit(Path, Local(cast<BlockExpr>(Init)), RK_ReferenceBinding);
6756 case Stmt::AddrLabelExprClass:
6758 Visit(Path, Local(cast<AddrLabelExpr>(Init)), RK_ReferenceBinding);
6769 for (
auto Elem : Path) {
6770 if (Elem.Kind != IndirectLocalPathEntry::DefaultInit)
6779 for (
unsigned N = Path.size(); I != N; ++I) {
6780 switch (Path[I].Kind) {
6781 case IndirectLocalPathEntry::AddressOf:
6782 case IndirectLocalPathEntry::LValToRVal:
6783 case IndirectLocalPathEntry::LifetimeBoundCall:
6788 case IndirectLocalPathEntry::DefaultInit:
6789 case IndirectLocalPathEntry::VarInit:
6790 return Path[I].E->getSourceRange();
6804 if (LK == LK_FullExpression)
6807 auto TemporaryVisitor = [&](IndirectLocalPath &Path, Local L,
6813 case LK_FullExpression:
6814 llvm_unreachable(
"already handled this");
6844 Diag(DiagLoc, diag::warn_unsupported_lifetime_extension)
6853 Diag(DiagLoc, diag::warn_dangling_variable)
6861 case LK_MemInitializer: {
6862 if (isa<MaterializeTemporaryExpr>(L)) {
6866 if (
auto *ExtendingDecl =
6867 ExtendingEntity ? ExtendingEntity->
getDecl() :
nullptr) {
6868 bool IsSubobjectMember = ExtendingEntity != &Entity;
6870 ? diag::err_dangling_member
6871 : diag::warn_dangling_member)
6872 << ExtendingDecl << IsSubobjectMember << RK << DiagRange;
6877 Path.back().Kind != IndirectLocalPathEntry::DefaultInit) {
6878 Diag(ExtendingDecl->getLocation(),
6879 diag::note_lifetime_extending_member_declared_here)
6880 << RK << IsSubobjectMember;
6899 auto *VD = DRE ? dyn_cast<
VarDecl>(DRE->getDecl()) :
nullptr;
6907 ExtendingEntity ? ExtendingEntity->
getDecl() :
nullptr) {
6909 Diag(DiagLoc, IsPointer ? diag::warn_init_ptr_member_to_parameter_addr
6910 : diag::warn_bind_ref_member_to_parameter)
6911 << Member << VD << isa<ParmVarDecl>(VD) << DiagRange;
6912 Diag(Member->getLocation(),
6913 diag::note_ref_or_ptr_member_declared_here)
6914 << (
unsigned)IsPointer;
6921 if (isa<MaterializeTemporaryExpr>(L)) {
6922 Diag(DiagLoc, RK == RK_ReferenceBinding
6923 ? diag::warn_new_dangling_reference
6924 : diag::warn_new_dangling_initializer_list)
6933 case LK_StmtExprResult:
6934 if (
auto *DRE = dyn_cast<DeclRefExpr>(L)) {
6937 if (LK == LK_StmtExprResult)
6939 Diag(DiagLoc, diag::warn_ret_stack_addr_ref)
6941 << isa<ParmVarDecl>(DRE->getDecl()) << DiagRange;
6942 }
else if (isa<BlockExpr>(L)) {
6943 Diag(DiagLoc, diag::err_ret_local_block) << DiagRange;
6944 }
else if (isa<AddrLabelExpr>(L)) {
6947 if (LK == LK_StmtExprResult)
6949 Diag(DiagLoc, diag::warn_ret_addr_label) << DiagRange;
6951 Diag(DiagLoc, diag::warn_ret_local_temp_addr_ref)
6957 for (
unsigned I = 0; I != Path.size(); ++I) {
6958 auto Elem = Path[I];
6960 switch (Elem.Kind) {
6961 case IndirectLocalPathEntry::AddressOf:
6962 case IndirectLocalPathEntry::LValToRVal:
6967 case IndirectLocalPathEntry::LifetimeBoundCall:
6971 case IndirectLocalPathEntry::DefaultInit: {
6972 auto *FD = cast<FieldDecl>(Elem.D);
6973 Diag(FD->getLocation(), diag::note_init_with_default_member_initalizer)
6978 case IndirectLocalPathEntry::VarInit:
6979 const VarDecl *VD = cast<VarDecl>(Elem.D);
7005 const Expr *PostInit);
7009 bool IsReturnStmt) {
7020 unsigned DiagID = 0;
7050 if (VD->
hasAttr<BlocksAttr>())
7063 if (isa<ParmVarDecl>(VD))
7064 DiagID = diag::warn_redundant_move_on_return;
7066 DiagID = diag::warn_pessimizing_move_on_return;
7068 DiagID = diag::warn_pessimizing_move_on_initialization;
7110 if (UO->getOpcode() == UO_Deref &&
7111 UO->getSubExpr()->IgnoreParenCasts()->
7114 S.
PDiag(diag::warn_binding_null_to_reference)
7115 << UO->getSubExpr()->getSourceRange());
7121 bool BoundToLvalueReference) {
7122 auto MTE =
new (Context)
7131 Cleanup.setExprNeedsCleanups(
false);
7140 if (!E->
isRValue() || !getLangOpts().CPlusPlus11)
7147 if (RequireCompleteType(E->
getExprLoc(), T, diag::err_incomplete_type))
7150 return CreateMaterializeTemporaryExpr(E->
getType(), E,
false);
7163 if (!ZeroInitializationFixit.empty()) {
7164 unsigned DiagID = diag::err_default_init_const;
7166 if (S.
getLangOpts().MSVCCompat && D->hasAttr<SelectAnyAttr>())
7167 DiagID = diag::ext_default_init_const;
7176 ZeroInitializationFixit);
7195 if (isa<InitListExpr>((
Expr *)Args[0])) {
7199 if (
auto *DD = dyn_cast_or_null<DeclaratorDecl>(Entity.
getDecl())) {
7201 TypeLoc TL = TInfo->getTypeLoc();
7204 Brackets = ArrayLoc.getBracketsRange();
7211 ArrayT->getSizeModifier(),
7212 ArrayT->getIndexTypeCVRQualifiers(),
7236 Args.size() == 1 && isa<InitListExpr>(Args[0]) &&
7241 Expr *Init = Args[0];
7242 S.
Diag(Init->
getLocStart(), diag::warn_cxx98_compat_reference_list_init)
7255 S.
Diag(Args[0]->getLocStart(), diag::err_opencl_atomic_init) << 1 <<
7274 switch (Steps.front().Kind) {
7309 assert(Args.size() == 1);
7327 CurInit.
get() && isa<InitListExpr>(CurInit.
get()));
7332 auto checkAbstractType = [&](
QualType T) ->
bool {
7337 diag::err_allocation_of_abstract_type);
7342 bool ConstructorInitRequiresZeroInit =
false;
7373 CurInit.
get()->getLocStart(),
7374 CurInit.
get()->getSourceRange(),
7375 &BasePath, IgnoreBaseAccess))
7386 CurInit.
get(), &BasePath, VK);
7400 if (CurInit.
get()->getType()->isFunctionProtoType()) {
7401 if (
auto *DRE = dyn_cast<DeclRefExpr>(CurInit.
get()->IgnoreParens())) {
7402 if (
auto *FD = dyn_cast<FunctionDecl>(DRE->getDecl())) {
7404 DRE->getLocStart()))
7415 assert(CurInit.
get()->isRValue() &&
"not a temporary");
7461 bool CreatedObject =
false;
7472 Loc, ConstructorArgs))
7477 FoundFn, Constructor,
7479 HadMultipleCandidates,
7493 CastKind = CK_ConstructorConversion;
7494 CreatedObject =
true;
7504 HadMultipleCandidates);
7508 CastKind = CK_UserDefinedConversion;
7509 CreatedObject = Conversion->getReturnType()->isRecordType();
7512 if (CreatedObject && checkAbstractType(CurInit.
get()->getType()))
7517 CurInit.
get()->getValueKind());
7533 S.
PDiag(diag::err_access_dtor_temp) << T);
7557 assert(CurInit.
get()->isRValue() &&
"cannot convert glvalue to atomic");
7564 assert(CurInit.
get()->isGLValue() &&
"cannot load from a prvalue");
7566 CK_LValueToRValue, CurInit.get(),
7586 CurInit = CurInitExprRes;
7607 InitListChecker PerformInitList(S, InitEntity,
7608 InitList, Ty,
false,
7610 if (PerformInitList.HadError())
7618 if ((*ResultType)->isRValueReferenceType())
7620 else if ((*ResultType)->isLValueReferenceType())
7627 PerformInitList.getFullyStructuredList();
7631 : StructuredInitList;
7648 assert(Args.size() == 1 &&
"expected a single argument for list init");
7650 S.
Diag(InitList->getExprLoc(), diag::warn_cxx98_compat_ctor_list_init)
7651 << InitList->getSourceRange();
7652 MultiExprArg Arg(InitList->getInits(), InitList->getNumInits());
7656 ConstructorInitRequiresZeroInit,
7659 InitList->getLBraceLoc(),
7660 InitList->getRBraceLoc());
7665 CurInit = cast<InitListExpr>(CurInit.
get())->getInit(0);
7694 bool IsStdInitListInit =
7701 S, UseTemporary ? TempEntity : Entity, Kind,
7703 ConstructorInitRequiresZeroInit,
7714 if (NextStep != StepEnd &&
7719 ConstructorInitRequiresZeroInit =
true;
7758 CurInit = CurInitExprRes;
7763 InitialCurInit.
get(),
7766 PrintInitLocationNote(S, Entity);
7768 }
else if (Complained)
7769 PrintInitLocationNote(S, Entity);
7782 CK_ObjCObjectLValueCast,
7783 CurInit.
get()->getValueKind());
7795 ArrayLoopCommonExprs.push_back(BaseExpr);
7800 assert(!ArrayLoopCommonExprs.empty() &&
7801 "mismatched SK_ArrayLoopIndex and SK_ArrayLoopInit");
7802 Expr *Common = ArrayLoopCommonExprs.pop_back_val();
7813 << CurInit.
get()->getSourceRange();
7824 IncompleteDest->getElementType(),
7825 ConstantSource->getSize(),
7836 << CurInit.
get()->getSourceRange();
7854 S.
Diag(CurInit.get()->getExprLoc(),
7855 diag::warn_cxx98_compat_initializer_list_init)
7856 << CurInit.get()->getSourceRange();
7860 CurInit.get()->getType(), CurInit.get(),
7890 "Sampler initialization on non-sampler type.");
7891 Expr *Init = CurInit.get();
7892 QualType SourceType = Init->getType();
7899 }
else if (
const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Init)) {
7900 auto Var = cast<VarDecl>(DRE->getDecl());
7903 if (!Var->hasGlobalStorage()) {
7905 CK_LValueToRValue, Init,
7915 if (!Var->getInit() || !isa<ImplicitCastExpr>(Var->getInit()))
7917 Init = cast<ImplicitCastExpr>(
const_cast<Expr*
>(
7918 Var->getInit()))->getSubExpr();
7919 SourceType = Init->getType();
7926 if (!Init->isConstantInitializer(S.
Context,
false))
7937 Init->EvaluateAsInt(Result, S.
Context);
7938 const uint64_t SamplerValue = Result.getLimitedValue();
7945 unsigned AddressingMode = (0x0E & SamplerValue) >> 1;
7946 unsigned FilterMode = (0x30 & SamplerValue) >> 4;
7947 if (FilterMode != 1 && FilterMode != 2)
7949 diag::warn_sampler_initializer_invalid_bits)
7951 if (AddressingMode > 4)
7953 diag::warn_sampler_initializer_invalid_bits)
7954 <<
"Addressing Mode";
7960 CK_IntToOCLSampler);
7965 "Event initialization on non-event type.");
7969 CurInit.get()->getValueKind());
7974 "Event initialization on non queue type.");
7978 CurInit.get()->getValueKind());
7986 if (
auto *Init = CurInit.
get())
7991 cast<FieldDecl>(Entity.
getDecl())->isBitField())
7993 cast<FieldDecl>(Entity.
getDecl()),
7997 if (
const Expr *E = CurInit.
get()) {
8010 S.
Diag(Loc, diag::err_reference_without_init)
8019 for (
const auto *FI : RD->
fields()) {
8020 if (FI->isUnnamedBitfield())
8024 S.
Diag(Loc, diag::note_value_initialization_here) << RD;
8029 for (
const auto &BI : RD->
bases()) {
8031 S.
Diag(Loc, diag::note_value_initialization_here) << RD;
8086 if (
auto *D = Entity.
getDecl())
8087 Loc = D->getLocation();
8088 S.
Diag(Loc, diag::note_in_reference_temporary_list_initializer) << T;
8092 InitListChecker DiagnoseInitList(S, Entity, InitList, DestType,
8095 assert(DiagnoseInitList.HadError() &&
8096 "Inconsistent init list check result.");
8109 if (Args.size() == 1) {
8111 if (List && List->getNumInits() == 1)
8112 OnlyArg = List->getInit(0);
8131 assert(Diagnosed &&
"couldn't find uninitialized reference to diagnose");
8135 <<
SourceRange(Args.front()->getLocStart(), Args.back()->getLocEnd());
8139 << 1 << Entity.
getType() << Args[0]->getSourceRange();
8152 S.
Diag(Kind.
getLocation(), diag::err_array_init_narrow_string_into_wchar);
8155 S.
Diag(Kind.
getLocation(), diag::err_array_init_wide_string_into_char);
8159 diag::err_array_init_incompat_wide_string_into_wchar);
8163 diag::err_array_init_plain_string_into_char8_t);
8164 S.
Diag(Args.front()->getLocStart(),
8165 diag::note_array_init_plain_string_into_char8_t)
8170 diag::err_array_init_utf8_string_into_char);
8176 ? diag::err_array_init_different_type
8177 : diag::err_array_init_non_constant_array))
8180 << Args[0]->getSourceRange();
8198 auto *FD = cast<FunctionDecl>(cast<DeclRefExpr>(OnlyArg)->getDecl());
8206 switch (FailedOverloadResult) {
8210 << OnlyArg->
getType() << DestType
8211 << Args[0]->getSourceRange();
8214 << DestType << OnlyArg->
getType()
8215 << Args[0]->getSourceRange();
8223 diag::err_typecheck_nonviable_condition_incomplete,
8224 OnlyArg->
getType(), Args[0]->getSourceRange()))
8227 << OnlyArg->
getType() << Args[0]->getSourceRange()
8236 << Args[0]->getSourceRange();
8239 = FailedCandidateSet.BestViableFunction(S, Kind.
getLocation(), Best);
8243 llvm_unreachable(
"Inconsistent overload resolution?");
8249 llvm_unreachable(
"Conversion did not fail!");
8254 if (isa<InitListExpr>(Args[0])) {
8256 diag::err_lvalue_reference_bind_to_initlist)
8259 << Args[0]->getSourceRange();
8267 ? diag::err_lvalue_reference_bind_to_temporary
8268 : diag::err_lvalue_reference_bind_to_unrelated)
8272 << Args[0]->getSourceRange();
8277 FieldDecl *BitField = Args[0]->getSourceBitField();
8281 << (BitField !=
nullptr)
8282 << Args[0]->getSourceRange();
8289 S.
Diag(Kind.
getLocation(), diag::err_reference_bind_to_vector_element)
8291 << Args[0]->getSourceRange();
8297 << Args[0]->getSourceRange();
8310 << Args[0]->getSourceRange();
8319 << Args[0]->getSourceRange();
8330 << Args[0]->getSourceRange();
8348 assert(Args.size() > 1 &&
"Expected multiple initializers!");
8349 R =
SourceRange(Args.front()->getLocEnd(), Args.back()->getLocEnd());
8354 S.
Diag(Kind.
getLocation(), diag::err_builtin_func_cast_more_than_one_arg)
8364 << 0 << Entity.
getType() << Args[0]->getSourceRange();
8381 ArgsRange =
SourceRange(Args.front()->getLocStart(),
8382 Args.back()->getLocEnd());
8385 assert(Args.size() == 1 &&
8386 "List construction from other than 1 argument.");
8388 Args =
MultiExprArg(InitList->getInits(), InitList->getNumInits());
8393 switch (FailedOverloadResult) {
8396 << DestType << ArgsRange;
8413 InheritedFrom = Inherited.getShadowDecl()->getNominatedBaseClass();
8416 << (InheritedFrom ? 2 : Constructor->
isImplicit() ? 1 : 0)
8429 << (InheritedFrom ? 2 : Constructor->
isImplicit() ? 1 : 0)
8435 diag::note_member_declared_at);
8439 S.
Diag(Record->getDecl()->getLocation(),
8440 diag::note_previous_decl)
8447 << DestType << ArgsRange;
8454 = FailedCandidateSet.BestViableFunction(S, Kind.
getLocation(), Best);
8457 <<
true << DestType << ArgsRange;
8458 llvm_unreachable(
"Inconsistent overload resolution?");
8468 << DestType << ArgsRange;
8471 <<
true << DestType << ArgsRange;
8478 llvm_unreachable(
"Conversion did not fail!");
8506 diag::err_init_incomplete_type);
8526 = FailedCandidateSet.BestViableFunction(S, Kind.
getLocation(), Best);
8528 assert(Ovl ==
OR_Success &&
"Inconsistent overload resolution");
8531 diag::note_explicit_ctor_deduction_guide_here) <<
false;
8536 PrintInitLocationNote(S, Entity);
8543 OS <<
"Failed sequence: ";
8546 OS <<
"too many initializers for reference";
8550 OS <<
"parenthesized list init for reference";
8554 OS <<
"array requires initializer list";
8558 OS <<
"address of unaddressable function was taken";
8562 OS <<
"array requires initializer list or string literal";
8566 OS <<
"array requires initializer list or wide string literal";
8570 OS <<
"narrow string into wide char array";
8574 OS <<
"wide string into char array";
8578 OS <<
"incompatible wide string into wide char array";
8582 OS <<
"plain string literal into char8_t array";
8586 OS <<
"u8 string literal into char array";
8590 OS <<
"array type mismatch";
8594 OS <<
"non-constant array initializer";
8598 OS <<
"address of overloaded function failed";
8602 OS <<
"overload resolution for reference initialization failed";
8606 OS <<
"non-const lvalue reference bound to temporary";
8610 OS <<
"non-const lvalue reference bound to bit-field";
8614 OS <<
"non-const lvalue reference bound to vector element";
8618 OS <<
"non-const lvalue reference bound to unrelated type";
8622 OS <<
"rvalue reference bound to an lvalue";
8626 OS <<
"reference initialization drops qualifiers";
8630 OS <<
"reference initialization failed";
8634 OS <<
"conversion failed";
8638 OS <<
"conversion from property failed";
8642 OS <<
"too many initializers for scalar";
8646 OS <<
"parenthesized list init for reference";
8650 OS <<
"referencing binding to initializer list";
8654 OS <<
"initializer list for non-aggregate, non-scalar type";
8658 OS <<
"overloading failed for user-defined conversion";
8662 OS <<
"constructor overloading failed";
8666 OS <<
"default initialization of a const variable";
8670 OS <<
"initialization of incomplete type";
8674 OS <<
"list initialization checker failure";
8678 OS <<
"variable length array has an initializer";
8682 OS <<
"initializer expression isn't contextually valid";
8686 OS <<
"list constructor overloading failed";
8690 OS <<
"list copy initialization chose explicit constructor";
8698 OS <<
"Dependent sequence\n";
8702 OS <<
"Normal sequence: ";
8713 OS <<
"resolve address of overloaded function";
8717 OS <<
"derived-to-base (rvalue)";
8721 OS <<
"derived-to-base (xvalue)";
8725 OS <<
"derived-to-base (lvalue)";
8729 OS <<
"bind reference to lvalue";
8733 OS <<
"bind reference to a temporary";
8737 OS <<
"final copy in class direct-initialization";
8741 OS <<
"extraneous C++03 copy to temporary";
8745 OS <<
"user-defined conversion via " << *S->Function.Function;
8749 OS <<
"qualification conversion (rvalue)";
8753 OS <<
"qualification conversion (xvalue)";
8757 OS <<
"qualification conversion (lvalue)";
8761 OS <<
"non-atomic-to-atomic conversion";
8765 OS <<
"load (lvalue to rvalue)";
8769 OS <<
"implicit conversion sequence (";
8775 OS <<
"implicit conversion sequence with narrowing prohibited (";
8781 OS <<
"list aggregate initialization";
8785 OS <<
"unwrap reference initializer list";
8789 OS <<
"rewrap reference initializer list";
8793 OS <<
"constructor initialization";
8797 OS <<
"list initialization via constructor";
8801 OS <<
"zero initialization";
8805 OS <<
"C assignment";
8809 OS <<
"string initialization";
8813 OS <<
"Objective-C object conversion";
8817 OS <<
"indexing for array initialization loop";
8821 OS <<
"array initialization loop";
8825 OS <<
"array initialization";
8829 OS <<
"array initialization (GNU extension)";
8833 OS <<
"parenthesized array initialization";
8837 OS <<
"pass by indirect copy and restore";
8841 OS <<
"pass by indirect restore";
8845 OS <<
"Objective-C object retension";
8849 OS <<
"std::initializer_list from initializer list";
8853 OS <<
"list initialization from std::initializer_list";
8857 OS <<
"OpenCL sampler_t from integer constant";
8861 OS <<
"OpenCL event_t from zero";
8865 OS <<
"OpenCL queue_t from zero";
8869 OS <<
" [" << S->Type.getAsString() <<
']';
8880 return L.CPlusPlus11 &&
8888 const Expr *PostInit) {
8918 ? diag::ext_init_list_type_narrowing
8919 : diag::warn_init_list_type_narrowing)
8929 ? diag::ext_init_list_constant_narrowing
8930 : diag::warn_init_list_constant_narrowing)
8940 ? diag::ext_init_list_variable_narrowing
8941 : diag::warn_init_list_variable_narrowing)
8949 llvm::raw_svector_ostream OS(StaticCast);
8950 OS <<
"static_cast<";
8957 OS << *TT->getDecl();
8966 S.
Diag(PostInit->
getLocStart(), diag::note_init_list_narrowing_silence)
8983 assert(InitE &&
"No initialization expression");
8988 return !Seq.Failed();
8995 bool TopLevelOfInitList,
8996 bool AllowExplicit) {
9001 assert(InitE &&
"No initialization expression?");
9012 const bool ShouldTrackCopy =
9014 if (ShouldTrackCopy) {
9015 if (llvm::find(CurrentParameterCopyTypes, Entity.
getType()) !=
9016 CurrentParameterCopyTypes.end()) {
9017 Seq.SetOverloadFailure(
9023 const auto LastStep = Seq.step_end() - 1;
9024 assert(LastStep->Kind ==
9026 const FunctionDecl *Function = LastStep->Function.Function;
9028 llvm::find_if(Seq.getFailedCandidateSet(),
9030 return Candidate.Viable &&
9031 Candidate.Function == Function &&
9032 Candidate.Conversions.size() > 0;
9034 if (Candidate != Seq.getFailedCandidateSet().end() &&
9036 Candidate->Viable =
false;
9043 CurrentParameterCopyTypes.push_back(Entity.
getType());
9048 if (ShouldTrackCopy)
9049 CurrentParameterCopyTypes.pop_back();
9057 auto NotSpecialization = [&] (
const CXXRecordDecl *Candidate) {
9061 return !(NotSpecialization(RD) && RD->
forallBases(NotSpecialization));
9069 assert(DeducedTST &&
"not a deduced template specialization type");
9077 diag::err_deduced_non_class_template_specialization_type)
9080 Diag(TD->getLocation(), diag::note_template_decl_here);
9103 LookupResult Guides(*
this, NameInfo, LookupOrdinaryName);
9104 LookupQualifiedName(Guides, Template->getDeclContext());
9108 Guides.suppressDiagnostics();
9113 ? dyn_cast<InitListExpr>(Inits[0])
9128 auto tryToResolveOverload =
9131 for (
auto I = Guides.begin(), E = Guides.end(); I != E; ++I) {
9137 auto *GD = dyn_cast_or_null<CXXDeductionGuideDecl>(
9138 TD ? TD->getTemplatedDecl() : dyn_cast<
FunctionDecl>(D));
9149 if (GD->isExplicit())
9155 if (GD->getMinRequiredArguments() > 1 ||
9156 (GD->getNumParams() == 0 && !GD->isVariadic()))
9163 if (OnlyListConstructors && !isInitListConstructor(GD))
9178 bool SuppressUserConversions = Kind.
isCopyInit();
9181 AddTemplateOverloadCandidate(TD, I.getPair(),
nullptr,
9183 SuppressUserConversions);
9185 AddOverloadCandidate(GD, I.getPair(),
Inits, Candidates,
9186 SuppressUserConversions);
9188 return Candidates.BestViableFunction(*
this, Kind.
getLocation(), Best);
9196 bool TryListConstructors =
true;
9202 auto *FD = dyn_cast<
FunctionDecl>(D->getUnderlyingDecl());
9203 if (FD && FD->getMinRequiredArguments() == 0) {
9204 TryListConstructors =
false;
9216 if (!isa<InitListExpr>(E) && RD &&
9219 TryListConstructors =
false;
9222 if (TryListConstructors)
9223 Result = tryToResolveOverload(
true);
9232 Result = tryToResolveOverload(
false);
9236 Diag(Kind.
getLocation(), diag::err_deduced_class_template_ctor_ambiguous)
9246 cast<ClassTemplateDecl>(Template)->getTemplatedDecl();
9250 Complete ? diag::err_deduced_class_template_ctor_no_viable
9251 : diag::err_deduced_class_template_incomplete)
9260 NoteDeletedFunction(Best->Function);
9269 cast<CXXDeductionGuideDecl>(Best->Function)->isExplicit()) {
9270 bool IsDeductionGuide = !Best->Function->isImplicit();
9273 Diag(Best->Function->getLocation(),
9274 diag::note_explicit_ctor_deduction_guide_here)
9275 << IsDeductionGuide;
9281 DiagnoseUseOfDecl(Best->Function, Kind.
getLocation());
9282 MarkFunctionReferenced(Kind.
getLocation(), Best->Function);
9289 return SubstAutoType(TSInfo->
getType(), Best->Function->getReturnType());
ObjCIndirectCopyRestoreExpr - Represents the passing of a function argument by indirect copy-restore ...
bool hasArrayFiller() const
Return true if this is an array initializer and its array "filler" has been set.
Represents a single C99 designator.
const IncompleteArrayType * getAsIncompleteArrayType(QualType T) const
Perform a derived-to-base cast, producing an lvalue.
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
Defines the clang::ASTContext interface.
bool isCallToStdMove() const
void clear(CandidateSetKind CSK)
Clear out all of the candidates.
bool RequireNonAbstractType(SourceLocation Loc, QualType T, TypeDiagnoser &Diagnoser)
Represents a function declaration or definition.
Expr * getArrayIndex(const Designator &D) const
InitListExpr * WrappingSyntacticList
When Kind = SK_RewrapInitList, the syntactic form of the wrapping list.
NamespaceDecl * getStdNamespace() const
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.
step_iterator step_begin() const
SourceLocation getRParenLoc() const
SourceLocation getEllipsisLoc() const
void setArrayFiller(Expr *filler)
SourceLocation getLocWithOffset(int Offset) const
Return a source location with the specified offset from this SourceLocation.
void SetZeroInitializationFixit(const std::string &Fixit, SourceLocation L)
Call for initializations are invalid but that would be valid zero initialzations if Fixit was applied...
A (possibly-)qualified type.
bool hasUninitializedReferenceMember() const
Whether this class or any of its subobjects has any members of reference type which would make value-...
Simple class containing the result of Sema::CorrectTypo.
StringKind getKind() const
bool CheckExceptionSpecCompatibility(Expr *From, QualType ToType)
Expr * getArg(unsigned Arg)
getArg - Return the specified argument.
DeclarationName getName() const
Retrieve the name of the entity being initialized.
void setFromType(QualType T)
Produce an Objective-C object pointer.
bool isCompatibleWithMSVC(MSVCMajorVersion MajorVersion) const
A cast other than a C-style cast.
void AddOCLZeroEventStep(QualType T)
Add a step to initialize an OpenCL event_t from a NULL constant.
const Expr * skipRValueSubobjectAdjustments(SmallVectorImpl< const Expr *> &CommaLHS, SmallVectorImpl< SubobjectAdjustment > &Adjustments) const
Walk outwards from an expression we want to bind a reference to and find the expression whose lifetim...
Initializing char array with wide string literal.
Perform an implicit conversion sequence without narrowing.
An initialization that "converts" an Objective-C object (not a point to an object) to another Objecti...
const Expr * getInit(unsigned Init) const
InvalidICRKind
The non-zero enum values here are indexes into diagnostic alternatives.
ExprResult ActOnParenListExpr(SourceLocation L, SourceLocation R, MultiExprArg Val)
static ExprResult CheckArrayDesignatorExpr(Sema &S, Expr *Index, llvm::APSInt &Value)
Check that the given Index expression is a valid array designator value.
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)
Reference initialization without resolving overloaded functions.
Perform a qualification conversion, producing an rvalue.
Cannot tell whether this is a narrowing conversion because the expression is value-dependent.
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 SecondStepOfCopyInit=false)
ExprResult BuildCXXDefaultArgExpr(SourceLocation CallLoc, FunctionDecl *FD, ParmVarDecl *Param)
BuildCXXDefaultArgExpr - Creates a CXXDefaultArgExpr, instantiating the default expr if needed...
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 DesignatedInitExpr * CloneDesignatedInitExpr(Sema &SemaRef, DesignatedInitExpr *DIE)
bool isRecordType() const
bool allowConstDefaultInit() const
Determine whether declaring a const variable with this type is ok per core issue 253.
static InitializedEntity InitializeMember(FieldDecl *Member, const InitializedEntity *Parent=nullptr, bool Implicit=false)
Create the initialization entity for a member subobject.
UserDefinedConversionSequence UserDefined
When ConversionKind == UserDefinedConversion, provides the details of the user-defined conversion seq...
QualType getQualifiedType(SplitQualType split) const
Un-split a SplitQualType.
QualType getLValueReferenceType(QualType T, bool SpelledAsLValue=true) const
Return the uniqued reference to the type for an lvalue reference to the specified type...
ConstructorInfo getConstructorInfo(NamedDecl *ND)
SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID)
Emit a diagnostic.
Decl - This represents one declaration (or definition), e.g.
uintptr_t Base
When Kind == EK_Base, the base specifier that provides the base class.
Represents the index of the current element of an array being initialized by an ArrayInitLoopExpr.
static bool canPerformArrayCopy(const InitializedEntity &Entity)
Determine whether we can perform an elementwise array copy for this kind of entity.
bool isExtVectorType() const
bool isVirtual() const
Determines whether the base class is a virtual base class (or not).
AssignConvertType
AssignConvertType - All of the 'assignment' semantic checks return this enum to indicate whether the ...
bool isTransparent() const
Is this a transparent initializer list (that is, an InitListExpr that is purely syntactic, and whose semantics are that of the sole contained initializer)?
Classification Classify(ASTContext &Ctx) const
Classify - Classify this expression according to the C++11 expression taxonomy.
unsigned getNumSubExprs() const
Retrieve the total number of subexpressions in this designated initializer expression, including the actual initialized value and any expressions that occur within array and array-range designators.
FailureKind getFailureKind() const
Determine why initialization failed.
Not a narrowing conversion.
llvm::iterator_range< conversion_iterator > getVisibleConversionFunctions()
Get all conversion functions visible in current class, including conversion function templates...
ParenExpr - This represents a parethesized expression, e.g.
NamedDecl * getDecl() const
QualType getNonReferenceType() const
If Type is a reference type (e.g., const int&), returns the type that the reference refers to ("const...
bool CanPerformCopyInitialization(const InitializedEntity &Entity, ExprResult Init)
enum SequenceKind getKind() const
Determine the kind of initialization sequence computed.
ExprResult CreateBuiltinArraySubscriptExpr(Expr *Base, SourceLocation LLoc, Expr *Idx, SourceLocation RLoc)
static InitializationKind CreateDirect(SourceLocation InitLoc, SourceLocation LParenLoc, SourceLocation RParenLoc)
Create a direct initialization.
The base class of the type hierarchy.
static bool tryObjCWritebackConversion(Sema &S, InitializationSequence &Sequence, const InitializedEntity &Entity, Expr *Initializer)
The entity being initialized is a variable.
const IdentifierInfo * getField() const
Represents an array type, per C99 6.7.5.2 - Array Declarators.
Represent a C++ namespace.
SourceLocation getLocForEndOfToken(SourceLocation Loc, unsigned Offset=0)
Calls Lexer::getLocForEndOfToken()
Represents a call to a C++ constructor.
Overloading for a user-defined conversion failed.
TypeSourceInfo * getTypeSourceInfo() const
Retrieve complete type-source information for the object being constructed, if known.
Ambiguous candidates found.
QualType withConst() const
Incompatible - We reject this conversion outright, it is invalid to represent it in the AST...
const TargetInfo & getTargetInfo() const
static void visitLocalsRetainedByReferenceBinding(IndirectLocalPath &Path, Expr *Init, ReferenceKind RK, LocalVisitor Visit)
Visit the locals that would be reachable through a reference bound to the glvalue expression Init...
A container of type source information.
QualType getCallResultType() const
Determine the type of an expression that calls this function.
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...
Perform a derived-to-base cast, producing an xvalue.
SourceLocation getCaptureLoc() const
Determine the location of the capture when initializing field from a captured variable in a lambda...
The entity being initialized is a base member subobject.
List-copy-initialization chose an explicit constructor.
The entity being initialized is the result of a statement expression.
SourceLocation getLocEnd() const LLVM_READONLY
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...
Represents a C++ constructor within a class.
Represents a prvalue temporary that is written into memory so that a reference can bind to it...
float __ovld __cnfn distance(float p0, float p1)
Returns the distance between p0 and p1.
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, C99 6.9p3)
bool hasInClassInitializer() const
Determine whether this member has a C++11 default member initializer.
SourceLocation getEndLoc() const
Get the end source location.
QualType getElementType() const
static InitializedEntity InitializeTemporary(QualType Type)
Create the initialization entity for a temporary.
The entity being initialized is a function parameter; function is member of group of audited CF APIs...
bool isDefaultConstructor() const
Whether this constructor is a default constructor (C++ [class.ctor]p5), which can be used to default-...
Initialize an OpenCL sampler from an integer.
static InitializedEntity InitializeBase(ASTContext &Context, const CXXBaseSpecifier *Base, bool IsInheritedVirtualBase, const InitializedEntity *Parent=nullptr)
Create the initialization entity for a base class subobject.
SourceLocation getLocStart() const LLVM_READONLY
bool isUnsignedIntegerType() const
Return true if this is an integer type that is unsigned, according to C99 6.2.5p6 [which returns true...
RAII object that enters a new expression evaluation context.
Represents a variable declaration or definition.
PartialDiagnostic PDiag(unsigned DiagID=0)
Build a partial diagnostic.
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...
void AddCAssignmentStep(QualType T)
Add a C assignment step.
Initialization by string.
CleanupInfo Cleanup
Used to control the generation of ExprWithCleanups.
QualType getReturnType() const
Array initialization by elementwise copy.
DiagnosticsEngine & Diags
const internal::VariadicDynCastAllOfMatcher< Stmt, Expr > expr
Matches expressions.
const T * getAs() const
Member-template getAs<specific type>'.
bool isDirectReferenceBinding() const
Determine whether this initialization is a direct reference binding (C++ [dcl.init.ref]).
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...
SourceLocation getEqualLoc() const
Retrieve the location of the equal sign for copy initialization (if present).
void AddOverloadCandidate(FunctionDecl *Function, DeclAccessPair FoundDecl, ArrayRef< Expr *> Args, OverloadCandidateSet &CandidateSet, bool SuppressUserConversions=false, bool PartialOverloading=false, bool AllowExplicit=false, ConversionSequenceList EarlyConversions=None)
AddOverloadCandidate - Adds the given function to the set of candidate functions, using the given fun...
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...
AccessResult CheckDestructorAccess(SourceLocation Loc, CXXDestructorDecl *Dtor, const PartialDiagnostic &PDiag, QualType objectType=QualType())
Represents a C++17 deduced template specialization type.
void resizeInits(const ASTContext &Context, unsigned NumInits)
Specify the number of initializers.
void setInit(unsigned Init, Expr *expr)
NamedDecl * getUnderlyingDecl()
Looks through UsingDecls and ObjCCompatibleAliasDecls for the underlying named decl.
Expr * IgnoreImplicit() LLVM_READONLY
IgnoreImplicit - Skip past any implicit AST nodes which might surround this expression.
bool isIdiomaticZeroInitializer(const LangOptions &LangOpts) const
Is this the zero initializer {0} in a language which considers it idiomatic?
DeclClass * getCorrectionDeclAs() const
Non-const lvalue reference binding to an lvalue of unrelated type.
Implicit construction of a std::initializer_list<T> object from an array temporary within list-initia...
SourceLocation getThrowLoc() const
Determine the location of the 'throw' keyword when initializing an exception object.
bool isInvalidDecl() const
void setBegin(SourceLocation b)
Perform a derived-to-base cast, producing an rvalue.
void AddReferenceBindingStep(QualType T, bool BindingTemporary)
Add a new step binding a reference to an object.
static InitializationKind CreateDirectList(SourceLocation InitLoc)
EntityKind getKind() const
Determine the kind of initialization.
Initializing char array with UTF-8 string literal.
void setElementIndex(unsigned Index)
If this is already the initializer for an array or vector element, sets the element index...
Represents a parameter to a function.
The entity being initialized is a temporary object.
Expr * getArrayRangeStart() const
QualType getLocalUnqualifiedType() const
Return this type with all of the instance-specific qualifiers removed, but without removing any quali...
const CXXBaseSpecifier * getBaseSpecifier() const
Retrieve the base specifier.
Defines the clang::Expr interface and subclasses for C++ expressions.
The collection of all-type qualifiers we support.
static void CheckMoveOnConstruction(Sema &S, const Expr *InitExpr, bool IsReturnStmt)
Provide warnings when std::move is used on construction.
Non-const lvalue reference binding to a vector element.
ExprResult PerformImplicitConversion(Expr *From, QualType ToType, AssignmentAction Action, bool AllowExplicit=false)
PerformImplicitConversion - Perform an implicit conversion of the expression From to the type ToType...
bool isImplicitMemberInitializer() const
Is this the implicit initialization of a member of a class from a defaulted constructor?
Base wrapper for a particular "section" of type source info.
Expr * IgnoreImpCasts() LLVM_READONLY
IgnoreImpCasts - Skip past any implicit casts which might surround this expression.
Expr * FixOverloadedFunctionReference(Expr *E, DeclAccessPair FoundDecl, FunctionDecl *Fn)
FixOverloadedFunctionReference - E is an expression that refers to a C++ overloaded function (possibl...
SourceLocation getDotLoc() const
Represents a struct/union/class.
Represents a C99 designated initializer expression.
Construct a std::initializer_list from an initializer list.
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
Trying to take the address of a function that doesn't support having its address taken.
Represents a class template specialization, which refers to a class template with a given set of temp...
One of these records is kept for each identifier that is lexed.
static void CheckForNullPointerDereference(Sema &S, const Expr *E)
SourceLocation getBegin() const
static bool isExprAnUnaddressableFunction(Sema &S, const Expr *E)
Tries to get a FunctionDecl out of E.
bool isArrayRangeDesignator() const
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...
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Expr * getInit() const
Retrieve the initializer value.
bool inTemplateInstantiation() const
Determine whether we are currently performing template instantiation.
The results of name lookup within a DeclContext.
TemplateDecl * getAsTemplateDecl() const
Retrieve the underlying template declaration that this template name refers to, if known...
C++ [over.match.copy]: Copy-initialization of an object of class type by user-defined conversion...
ImplicitConversionSequence * ICS
When Kind = SK_ConversionSequence, the implicit conversion sequence.
Base class for callback objects used by Sema::CorrectTypo to check the validity of a potential typo c...
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...
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 isSpelledAsLValue() const
field_range fields() const
Represents a member of a struct/union/class.
Represents a place-holder for an object not to be initialized by anything.
static DesignatedInitExpr * Create(const ASTContext &C, llvm::ArrayRef< Designator > Designators, ArrayRef< Expr *> IndexExprs, SourceLocation EqualOrColonLoc, bool GNUSyntax, Expr *Init)
bool isArrayDesignator() const
bool CheckObjCBridgeRelatedConversions(SourceLocation Loc, QualType DestType, QualType SrcType, Expr *&SrcExpr, bool Diagnose=true)
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...
SourceLocation getRBraceLoc() const
Rewrap the single-element initializer list for a reference.
bool isReferenceType() const
InheritedConstructor getInheritedConstructor() const
Get the constructor that this inheriting constructor is based on.
void AddOCLSamplerInitStep(QualType T)
Add a step to initialize an OpenCL sampler from an integer constant.
bool Equals(const DeclContext *DC) const
Determine whether this declaration context is equivalent to the declaration context DC...
Ref_Incompatible - The two types are incompatible, so direct reference binding is not possible...
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
void SetOverloadFailure(FailureKind Failure, OverloadingResult Result)
Note that this initialization sequence failed due to failed overload resolution.
bool isIntegralOrEnumerationType() const
Determine whether this type is an integral or enumeration type.
specific_decl_iterator< FieldDecl > field_iterator
~InitializationSequence()
void NoteDeletedFunction(FunctionDecl *FD)
Emit a note explaining that this function is deleted.
An r-value expression (a pr-value in the C++11 taxonomy) produces a temporary value.
static bool implicitObjectParamIsLifetimeBound(const FunctionDecl *FD)
Perform initialization via a constructor taking a single std::initializer_list argument.
Describes an C or C++ initializer list.
bool CanUseDecl(NamedDecl *D, bool TreatUnavailableAsInvalid)
Determine whether the use of this declaration is valid, without emitting diagnostics.
An rvalue reference type, per C++11 [dcl.ref].
bool isCompleteType(SourceLocation Loc, QualType T)
SourceRange getParenOrBraceRange() const
Retrieve the source range containing the locations of the open and closing parentheses or braces for ...
Represents the results of name lookup.
bool refersToBitField() const
Returns true if this expression is a gl-value that potentially refers to a bit-field.
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...
StepKind Kind
The kind of conversion or initialization step we are taking.
bool isImplicitValueInit() const
Determine whether this initialization is an implicit value-initialization, e.g., as occurs during agg...
Succeeded, but refers to a deleted function.
ReferenceCompareResult CompareReferenceRelationship(SourceLocation Loc, QualType T1, QualType T2, bool &DerivedToBase, bool &ObjCConversion, bool &ObjCLifetimeConversion)
CompareReferenceRelationship - Compare the two types T1 and T2 to determine whether they are referenc...
static bool pathContainsInit(IndirectLocalPath &Path)
Ref_Compatible - The two types are reference-compatible.
ExprResult ActOnDesignatedInitializer(Designation &Desig, SourceLocation Loc, bool GNUSyntax, ExprResult Init)
static void visitLocalsRetainedByInitializer(IndirectLocalPath &Path, Expr *Init, LocalVisitor Visit, bool RevisitSubinits)
Visit the locals that would be reachable through an object initialized by the prvalue expression Init...
bool hasAddressSpace() const
const ArrayType * getAsArrayTypeUnsafe() const
A variant of getAs<> for array types which silently discards qualifiers from the outermost type...
OverloadCandidateSet & getFailedCandidateSet()
Retrieve a reference to the candidate set when overload resolution fails.
ExprValueKind getValueKind() const
getValueKind - The value kind that this expression produces.
An x-value expression is a reference to an object with independent storage but which can be "moved"...
QualType getToType(unsigned Idx) const
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...
std::string getAsString(ASTContext &Ctx, QualType Ty) const
unsigned getElementIndex() const
If this is an array, vector, or complex number element, get the element's index.
bool isVolatileQualified() const
Determine whether this type is volatile-qualified.
LangAS getAddressSpace() const
Variable-length array must not have an initializer.
ImplicitConversionKind Second
Second - The second conversion can be an integral promotion, floating point promotion, integral conversion, floating point conversion, floating-integral conversion, pointer conversion, pointer-to-member conversion, or boolean conversion.
static void visitLifetimeBoundArguments(IndirectLocalPath &Path, Expr *Call, LocalVisitor Visit)
Initialization of an incomplete type.
void dump() const
Dump a representation of this initialization sequence to standard error, for debugging purposes...
The entity being initialized is a non-static data member subobject.
static InitializationKind CreateValue(SourceLocation InitLoc, SourceLocation LParenLoc, SourceLocation RParenLoc, bool isImplicit=false)
Create a value initialization.
bool isRValueReferenceType() const
CheckedConversionKind
The kind of conversion being performed.
A narrowing conversion, because a constant expression got narrowed.
Unwrap the single-element initializer list for a reference.
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...
void AddParenthesizedArrayInitStep(QualType T)
Add a parenthesized array initialization step.
Expr * IgnoreParenCasts() LLVM_READONLY
IgnoreParenCasts - Ignore parentheses and casts.
SourceLocation getEqualOrColonLoc() const
Retrieve the location of the '=' that precedes the initializer value itself, if present.
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...
SmallVectorImpl< Step >::const_iterator step_iterator
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
field_iterator field_begin() const
bool declaresSameEntity(const Decl *D1, const Decl *D2)
Determine whether two declarations declare the same entity.
The entity being initialized is an element of a vector.
CastExpr - Base class for type casts, including both implicit casts (ImplicitCastExpr) and explicit c...
Represents binding an expression to a temporary.
AccessResult CheckConstructorAccess(SourceLocation Loc, CXXConstructorDecl *D, DeclAccessPair FoundDecl, const InitializedEntity &Entity, bool IsCopyBindingRefToTemp=false)
Checks access to a constructor.
const LangOptions & getLangOpts() const
bool isTypeDependent() const
isTypeDependent - Determines whether this expression is type-dependent (C++ [temp.dep.expr]), which means that its type could change from one template instantiation to the next.
ExprResult DefaultFunctionArrayLvalueConversion(Expr *E, bool Diagnose=true)
bool isScalarType() const
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.
Perform initialization via a constructor.
Perform a user-defined conversion, either via a conversion function or via a constructor.
Implicit conversion failed.
Member name lookup, which finds the names of class/struct/union members.
is ARM Neon polynomial vector
The entity being initialized is a function parameter.
void checkInitializerLifetime(const InitializedEntity &Entity, Expr *Init)
Check that the lifetime of the initializer (and its subobjects) is sufficient for initializing the en...
static void diagnoseListInit(Sema &S, const InitializedEntity &Entity, InitListExpr *InitList)
bool hasParenOrBraceRange() const
Determine whether this initialization has a source range containing the locations of open and closing...
ValueDecl * getDecl() const
Retrieve the variable, parameter, or field being initialized.
lookup_result lookup(DeclarationName Name) const
lookup - Find the declarations (if any) with the given Name in this context.
bool isAmbiguous() const
Determine whether this initialization failed due to an ambiguity.
ExprResult TemporaryMaterializationConversion(Expr *E)
If E is a prvalue denoting an unmaterialized temporary, materialize it as an xvalue.
CXXConstructorDecl * findInheritingConstructor(SourceLocation Loc, CXXConstructorDecl *BaseCtor, ConstructorUsingShadowDecl *DerivedShadow)
Given a derived-class using shadow declaration for a constructor and the correspnding base class cons...
Perform an implicit conversion sequence.
ConditionalOperator - The ?: ternary operator.
CXXConstructorDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
Sema - This implements semantic analysis and AST building for C.
void setField(FieldDecl *FD)
Overloading for list-initialization by constructor failed.
Perform list-initialization without a constructor.
bool isPromotableIntegerType() const
More type predicates useful for type checking/promotion.
void EmitRelatedResultTypeNoteForReturn(QualType destType)
Given that we had incompatible pointer types in a return statement, check whether we're in a method w...
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
Reference binding drops qualifiers.
unsigned getNumDesignators() const
void AddObjCObjectConversionStep(QualType T)
Add an Objective-C object conversion step, which is always a no-op.
Non-const lvalue reference binding to a bit-field.
CXXConstructorDecl * getConstructor() const
Get the constructor that this expression will (ultimately) call.
Cannot resolve the address of an overloaded function.
bool DiagnoseUseOfDecl(NamedDecl *D, ArrayRef< SourceLocation > Locs, const ObjCInterfaceDecl *UnknownObjCClass=nullptr, bool ObjCPropertyAccess=false, bool AvoidPartialAvailabilityChecks=false)
Determine whether the use of this declaration is valid, and emit any corresponding diagnostics...
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...
CastKind
CastKind - The kind of operation required for a conversion.
The return type of classify().
void AddStdInitializerListConstructionStep(QualType T)
Add a step to construct a std::initializer_list object from an initializer list.
static ImplicitCastExpr * Create(const ASTContext &Context, QualType T, CastKind Kind, Expr *Operand, const CXXCastPath *BasePath, ExprValueKind Cat)
DeclarationNameTable DeclarationNames
bool hasQualifiers() const
Determine whether this type has any qualifiers.
InitListExpr * getUpdater() const
A narrowing conversion by virtue of the source and destination types.
bool isFunctionalCast() const
Determine whether this is a functional-style cast.
TypeSourceInfo * getTrivialTypeSourceInfo(QualType T, SourceLocation Loc=SourceLocation()) const
Allocate a TypeSourceInfo where all locations have been initialized to a given location, which defaults to the empty location.
unsigned allocateManglingNumber() const
The entity being initialized is a field of block descriptor for the copied-in c++ object...
llvm::APSInt EvaluateKnownConstInt(const ASTContext &Ctx, SmallVectorImpl< PartialDiagnosticAt > *Diag=nullptr) const
EvaluateKnownConstInt - Call EvaluateAsRValue and return the folded integer.
ImplicitConversionSequence TryImplicitConversion(Expr *From, QualType ToType, bool SuppressUserConversions, bool AllowExplicit, bool InOverloadResolution, bool CStyle, bool AllowObjCWritebackConversion)
QualType getPromotedIntegerType(QualType PromotableType) const
Return the type that PromotableType will promote to: C99 6.3.1.1p2, assuming that PromotableType is a...
bool isObjCWritebackConversion(QualType FromType, QualType ToType, QualType &ConvertedType)
Determine whether this is an Objective-C writeback conversion, used for parameter passing when perfor...
bool HasSideEffects(const ASTContext &Ctx, bool IncludePossibleEffects=true) const
HasSideEffects - This routine returns true for all those expressions which have any effect other than...
SourceLocation getLocStart() const LLVM_READONLY
void AddTemplateConversionCandidate(FunctionTemplateDecl *FunctionTemplate, DeclAccessPair FoundDecl, CXXRecordDecl *ActingContext, Expr *From, QualType ToType, OverloadCandidateSet &CandidateSet, bool AllowObjCConversionOnExplicit, bool AllowResultConversion=true)
Adds a conversion function template specialization candidate to the overload set, using template argu...
Initializing wide char array with incompatible wide string literal.
The entity being initialized is the real or imaginary part of a complex number.
An expression "T()" which creates a value-initialized rvalue of type T, which is a non-class type...
QualType getElementType() const
SourceLocation getLocStart() const LLVM_READONLY
Type source information for an attributed type.
Implicit conversion failed.
QualType getVectorType(QualType VectorType, unsigned NumElts, VectorType::VectorKind VecKind) const
Return the unique reference to a vector type of the specified element type and size.
llvm::MutableArrayRef< Designator > designators()
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Expr - This represents one expression.
bool isCopyOrMoveConstructor(unsigned &TypeQuals) const
Determine whether this is a copy or move constructor.
void setRBraceLoc(SourceLocation Loc)
ExprValueKind
The categorization of expression values, currently following the C++11 scheme.
bool isDefaulted() const
Whether this function is defaulted per C++0x.
Initializing char8_t array with plain string literal.
bool isInSystemHeader(SourceLocation Loc) const
Returns if a SourceLocation is in a system header.
bool hasLocalStorage() const
Returns true if a variable with function scope is a non-static local variable.
void dump() const
Dump a representation of the initialized entity to standard error, for debugging purposes.
Scalar initialized from a parenthesized initializer list.
StandardConversionSequence After
After - Represents the standard conversion that occurs after the actual user-defined conversion...
static void updateStringLiteralType(Expr *E, QualType Ty)
Update the type of a string literal, including any surrounding parentheses, to match the type of the ...
The entity being initialized is an object (or array of objects) allocated via new.
Perform a qualification conversion, producing an xvalue.
void setSyntacticForm(InitListExpr *Init)
const T * castAs() const
Member-template castAs<specific type>.
Represents a C++ functional cast expression that builds a temporary object.
bool isObjCRetainableType() const
T getAs() const
Convert to the specified TypeLoc type, returning a null TypeLoc if this TypeLoc is not of the desired...
Represents a C++ destructor within a class.
Initializing a wide char array with narrow string literal.
bool isFieldDesignator() const
unsigned getNumInits() const
bool isImplicit() const
isImplicit - Indicates whether the declaration was implicitly generated by the implementation.
void ClearExprs(Sema &Actions)
ClearExprs - Null out any expression references, which prevents them from being 'delete'd later...
QualType getTagDeclType(const TagDecl *Decl) const
Return the unique reference to the type for the specified TagDecl (struct/union/class/enum) decl...
const Expr * getCallee() const
void AddProduceObjCObjectStep(QualType T)
Add a step to "produce" an Objective-C object (by retaining it).
Passing zero to a function where OpenCL event_t is expected.
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...
ExprResult VerifyIntegerConstantExpression(Expr *E, llvm::APSInt *Result, VerifyICEDiagnoser &Diagnoser, bool AllowFold=true)
VerifyIntegerConstantExpression - Verifies that an expression is an ICE, and reports the appropriate ...
field_iterator field_end() const
Resolve the address of an overloaded function to a specific function declaration. ...
DeclContext * getDeclContext()
Overload resolution succeeded.
bool isAnyComplexType() const
The entity being initialized is an exception object that is being thrown.
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...
unsigned size() const
Returns the number of designators in this initializer.
ExprResult CheckPlaceholderExpr(Expr *E)
Check for operands with placeholder types and complain if found.
struct F Function
When Kind == SK_ResolvedOverloadedFunction or Kind == SK_UserConversion, the function that the expres...
bool refersToEnclosingVariableOrCapture() const
Does this DeclRefExpr refer to an enclosing local or a captured variable?
Represents a C++ template name within the type system.
Ref_Related - The two types are reference-related, which means that their unqualified forms (T1 and T...
bool isConstructorInitialization() const
Determine whether this initialization is direct call to a constructor.
ReferenceCompareResult
ReferenceCompareResult - Expresses the result of comparing two types (cv1 T1 and cv2 T2) to determine...
bool RequireCompleteType(SourceLocation Loc, QualType T, TypeDiagnoser &Diagnoser)
Ensure that the type T is a complete type.
Defines the clang::TypeLoc interface and its subclasses.
Floating-integral conversions (C++ [conv.fpint])
const AstTypeMatcher< ArrayType > arrayType
Matches all kinds of arrays.
Specifies that a value-dependent expression of integral or dependent type should be considered a null...
bool isSignedIntegerType() const
Return true if this is an integer type that is signed, according to C99 6.2.5p4 [char, signed char, short, int, long..], or an enum decl which has a signed representation.
bool isTemporaryObject(ASTContext &Ctx, const CXXRecordDecl *TempTy) const
Determine whether the result of this expression is a temporary object of the given class type...
CharSourceRange getImmediateExpansionRange(SourceLocation Loc) const
Return the start/end of the expansion information for an expansion location.
void setValueKind(ExprValueKind Cat)
setValueKind - Set the value kind produced by this expression.
StandardConversionSequence Standard
When ConversionKind == StandardConversion, provides the details of the standard conversion sequence...
QualType getConstantArrayType(QualType EltTy, const llvm::APInt &ArySize, ArrayType::ArraySizeModifier ASM, unsigned IndexTypeQuals) const
Return the unique reference to the type for a constant array of the specified element type...
StorageDuration getStorageDuration() const
Retrieve the storage duration for the materialized temporary.
QualType getEncodedType() const
bool isExplicitCast() const
Determine whether this initialization is an explicit cast.
Expr * getArrayRangeEnd() const
static void TryDefaultInitialization(Sema &S, const InitializedEntity &Entity, const InitializationKind &Kind, InitializationSequence &Sequence)
Attempt default initialization (C++ [dcl.init]p6).
QualType getRecordType(const RecordDecl *Decl) const
Initializer has a placeholder type which cannot be resolved by initialization.
SourceLocation getLBracketLoc() const
SourceLocation getEnd() const
UnaryOperator - This represents the unary-expression's (except sizeof and alignof), the postinc/postdec operators from postfix-expression, and various extensions.
Represents a GCC generic vector type.
static void TryReferenceInitialization(Sema &S, const InitializedEntity &Entity, const InitializationKind &Kind, Expr *Initializer, InitializationSequence &Sequence)
Attempt reference initialization (C++0x [dcl.init.ref])
bool usesGNUSyntax() const
Determines whether this designated initializer used the deprecated GNU syntax for designated initiali...
An lvalue reference type, per C++11 [dcl.ref].
void AddConversionCandidate(CXXConversionDecl *Conversion, DeclAccessPair FoundDecl, CXXRecordDecl *ActingContext, Expr *From, QualType ToType, OverloadCandidateSet &CandidateSet, bool AllowObjCConversionOnExplicit, bool AllowResultConversion=true)
AddConversionCandidate - Add a C++ conversion function as a candidate in the candidate set (C++ [over...
SourceLocation getLocation() const
Retrieve the location at which initialization is occurring.
bool AllowExplicit() const
Retrieve whether this initialization allows the use of explicit constructors.
const Type * getBaseElementTypeUnsafe() const
Get the base element type of this type, potentially discarding type qualifiers.
Represents a C++ conversion function within a class.
void AddStringInitStep(QualType T)
Add a string init step.
QualType getTypeDeclType(const TypeDecl *Decl, const TypeDecl *PrevDecl=nullptr) const
Return the unique reference to the type for the specified type declaration.
SourceLocation getReturnLoc() const
Determine the location of the 'return' keyword when initializing the result of a function call...
The result type of a method or function.
bool isTrivial() const
Whether this function is "trivial" in some specialized C++ senses.
Pass an object by indirect restore.
bool isNull() const
Return true if this QualType doesn't point to a type yet.
Expr * getArrayIndex() const
__UINTPTR_TYPE__ uintptr_t
An unsigned integer type with the property that any valid pointer to void can be converted to this ty...
void DefineImplicitDefaultConstructor(SourceLocation CurrentLocation, CXXConstructorDecl *Constructor)
DefineImplicitDefaultConstructor - Checks for feasibility of defining this constructor as the default...
T getAsAdjusted() const
Convert to the specified TypeLoc type, returning a null TypeLoc if this TypeLoc is not of the desired...
InitKind getKind() const
Determine the initialization kind.
void AddZeroInitializationStep(QualType T)
Add a zero-initialization step.
static void TryReferenceListInitialization(Sema &S, const InitializedEntity &Entity, const InitializationKind &Kind, InitListExpr *InitList, InitializationSequence &Sequence, bool TreatUnavailableAsInvalid)
Attempt list initialization of a reference.
CXXDestructorDecl * LookupDestructor(CXXRecordDecl *Class)
Look for the destructor of the given class.
AttributedType::Kind getAttrKind() const
static InitializationKind CreateCopy(SourceLocation InitLoc, SourceLocation EqualLoc, bool AllowExplicitConvs=false)
Create a copy initialization.
ExprObjectKind getObjectKind() const
getObjectKind - The object kind that this expression produces.
FailureKind
Describes why initialization failed.
A narrowing conversion, because a non-constant-expression variable might have got narrowed...
Too many initializers for scalar.
Lvalue-to-rvalue conversion (C++ [conv.lval])
bool isConstQualified() const
Determine whether this type is const-qualified.
List initialization failed at some point.
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...
RecordDecl * getDecl() const
bool Diagnose(Sema &S, const InitializedEntity &Entity, const InitializationKind &Kind, ArrayRef< Expr *> Args)
Diagnose an potentially-invalid initialization sequence.
bool isAtStartOfImmediateMacroExpansion(SourceLocation Loc, SourceLocation *MacroBegin=nullptr) const
Returns true if the given MacroID location points at the beginning of the immediate macro expansion...
SourceLocation getLocStart() const LLVM_READONLY
QualType getWideCharType() const
Return the type of wide characters.
Initialize queue_t from 0.
Perform a conversion adding _Atomic to a type.
void AddListInitializationStep(QualType T)
Add a list-initialization step.
chain_iterator chain_end() const
ExprResult BuildCXXConstructExpr(SourceLocation ConstructLoc, QualType DeclInitType, NamedDecl *FoundDecl, CXXConstructorDecl *Constructor, MultiExprArg Exprs, bool HadMultipleCandidates, bool IsListInitialization, bool IsStdInitListInitialization, bool RequiresZeroInit, unsigned ConstructKind, SourceRange ParenRange)
BuildCXXConstructExpr - Creates a complete call to a constructor, including handling of its default a...
bool allowExplicitConversionFunctionsInRefBinding() const
Retrieve whether this initialization allows the use of explicit conversion functions when binding a r...
CXXConstructorDecl * Constructor
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).
OpaqueValueExpr - An expression referring to an opaque object of a fixed type and value class...
Perform a qualification conversion, producing an lvalue.
Integral conversions (C++ [conv.integral])
SmallVectorImpl< OverloadCandidate >::iterator iterator
void AddLValueToRValueStep(QualType Ty)
Add a new step that performs a load of the given type.
Reference binding to an lvalue.
ExprResult MaybeBindToTemporary(Expr *E)
MaybeBindToTemporary - If the passed in expression has a record type with a non-trivial destructor...
bool isParameterKind() const
ImplicitConversionSequence - Represents an implicit conversion sequence, which may be a standard conv...
const Designator & getDesignator(unsigned Idx) const
QualType getCanonicalType() const
ArrayRef< NamedDecl * >::const_iterator chain_iterator
ActionResult - This structure is used while parsing/acting on expressions, stmts, etc...
bool allowsNRVO() const
Determine whether this initialization allows the named return value optimization, which also applies ...
OverloadCandidate - A single candidate in an overload set (C++ 13.3).
SequenceKind
Describes the kind of initialization sequence computed.
Array indexing for initialization by elementwise copy.
ASTContext & getASTContext() const
NullPointerConstantKind isNullPointerConstant(ASTContext &Ctx, NullPointerConstantValueDependence NPC) const
isNullPointerConstant - C99 6.3.2.3p3 - Test if this reduces down to a Null pointer constant...
FunctionDecl * getTemplatedDecl() const
Get the underlying function declaration of the template.
Encodes a location in the source.
C++ [over.match.ctor], [over.match.list] Initialization of an object of class type by constructor...
SourceLocation getFieldLoc() const
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of enums...
Reference initialization from an initializer list.
static bool shouldLifetimeExtendThroughPath(const IndirectLocalPath &Path)
Determine whether this is an indirect path to a temporary that we are supposed to lifetime-extend alo...
static bool shouldBindAsTemporary(const InitializedEntity &Entity)
Whether we should bind a created object as a temporary when initializing the given entity...
Expr * getSubExpr() const
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...
bool ConversionToObjCStringLiteralCheck(QualType DstType, Expr *&SrcExpr, bool Diagnose=true)
Expr * getSubExpr(unsigned Idx) const
bool isUnnamedBitfield() const
Determines whether this is an unnamed bitfield.
bool isCStyleOrFunctionalCast() const
Determine whether this initialization is a C-style cast.
MutableArrayRef< Expr * > MultiExprArg
QualType DeduceTemplateSpecializationFromInitializer(TypeSourceInfo *TInfo, const InitializedEntity &Entity, const InitializationKind &Kind, MultiExprArg Init)
SourceLocation getLocStart() const LLVM_READONLY
QualType getElementType() const
void setReferenced(bool R=true)
llvm::iterator_range< base_class_iterator > base_class_range
static bool isVarOnPath(IndirectLocalPath &Path, VarDecl *VD)
OverloadingResult
OverloadingResult - Capture the result of performing overload resolution.
static InitializedEntity InitializeElement(ASTContext &Context, unsigned Index, const InitializedEntity &Parent)
Create the initialization entity for an array element.
static InvalidICRKind isInvalidICRSource(ASTContext &C, Expr *e, bool isAddressOf, bool &isWeakAccess)
Determines whether this expression is an acceptable ICR source.
QualType getBaseElementType(const ArrayType *VAT) const
Return the innermost element type of an array type.
const ConstantArrayType * getAsConstantArrayType(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...
Initialization of some unused destination type with an initializer list.
The entity being initialized is the result of a function call.
void InitializeFrom(Sema &S, const InitializedEntity &Entity, const InitializationKind &Kind, MultiExprArg Args, bool TopLevelOfInitList, bool TreatUnavailableAsInvalid)
Objective-C ARC writeback conversion.
The entity being implicitly initialized back to the formal result type.
const ParmVarDecl * getParamDecl(unsigned i) const
Zero-initialize the object.
The entity being initialized is the initializer for a compound literal.
const ArrayType * getAsArrayType(QualType T) const
Type Query functions.
void AddExtraneousCopyToTemporary(QualType T)
Add a new step that makes an extraneous copy of the input to a temporary of the same class type...
Specifies that a value-dependent expression should be considered to never be a null pointer constant...
OverloadingResult BestViableFunction(Sema &S, SourceLocation Loc, OverloadCandidateSet::iterator &Best)
Find the best viable function on this overload set, if it exists.
SourceLocation getLocEnd() const LLVM_READONLY
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...
SourceLocation getLBracketLoc() const
Describes the kind of initialization being performed, along with location information for tokens rela...
bool isValueDependent() const
isValueDependent - Determines whether this expression is value-dependent (C++ [temp.dep.constexpr]).
bool forallBases(ForallBasesCallback BaseMatches, bool AllowShortCircuit=true) const
Determines if the given callback holds for all the direct or indirect base classes of this type...
AssignConvertType CheckTransparentUnionArgumentConstraints(QualType ArgType, ExprResult &RHS)
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...
The entity being initialized is an element of an array.
bool isObjCObjectPointerType() const
bool isAnyPointerType() const
void setAsIdentityConversion()
StandardConversionSequence - Set the standard conversion sequence to the identity conversion...
Reference initialized from a parenthesized initializer list.
ImplicitCastExpr - Allows us to explicitly represent implicit type conversions, which have no direct ...
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 bool DiagnoseUninitializedReference(Sema &S, SourceLocation Loc, QualType T)
Somewhere within T there is an uninitialized reference subobject.
DestructionKind isDestructedType() const
Returns a nonzero value if objects of this type require non-trivial work to clean up after...
Expr ** getInits()
Retrieve the set of initializers.
bool isLValue() const
isLValue - True if this expression is an "l-value" according to the rules of the current language...
Overloading for initialization by constructor failed.
static bool ResolveOverloadedFunctionForReferenceBinding(Sema &S, Expr *Initializer, QualType &SourceType, QualType &UnqualifiedSourceType, QualType UnqualifiedTargetType, InitializationSequence &Sequence)
bool refersToVectorElement() const
Returns whether this expression refers to a vector element.
Requests that all candidates be shown.
An optional copy of a temporary object to another temporary object, which is permitted (but not requi...
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.
SourceLocation getLocEnd() const LLVM_READONLY
void AddOCLZeroQueueStep(QualType T)
Add a step to initialize an OpenCL queue_t from 0.
unsigned getMinRequiredArguments() const
Returns the minimum number of arguments needed to call this function.
bool isUsed(bool CheckUsedAttr=true) const
Whether any (re-)declaration of the entity was used, meaning that a definition is required...
Expr * getArrayRangeStart(const Designator &D) const
void AddAtomicConversionStep(QualType Ty)
Add a new step that performs conversion from non-atomic to atomic type.
bool HadMultipleCandidates
void AddArrayInitStep(QualType T, bool IsGNUExtension)
Add an array initialization step.
bool isVectorType() const
void AddPassByIndirectCopyRestoreStep(QualType T, bool shouldCopy)
Add a step to pass an object by indirect copy-restore.
OverloadCandidateSet - A set of overload candidates, used in C++ overload resolution (C++ 13...
Expr * getArrayFiller()
If this initializer list initializes an array with more elements than there are initializers in the l...
bool hasFlexibleArrayMember() const
static void CheckStringInit(Expr *Str, QualType &DeclT, const ArrayType *AT, Sema &S)
std::string getFixItZeroInitializerForType(QualType T, SourceLocation Loc) const
Get a string to suggest for zero-initialization of a type.
bool hasSameUnqualifiedType(QualType T1, QualType T2) const
Determine whether the given types are equivalent after cvr-qualifiers have been removed.
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
CXXSpecialMember getSpecialMember(const CXXMethodDecl *MD)
getSpecialMember - get the special member enum for a method.
Pass an object by indirect copy-and-restore.
A POD class for pairing a NamedDecl* with an access specifier.
ExprResult BuildCXXMemberCallExpr(Expr *Exp, NamedDecl *FoundDecl, CXXConversionDecl *Method, bool HadMultipleCandidates)
Represents a C11 generic selection.
Rvalue reference binding to an lvalue.
void SetFailed(FailureKind Failure)
Note that this initialization sequence failed.
decl_iterator - Iterates through the declarations stored within this context.
static unsigned getMaxSizeBits(const ASTContext &Context)
Determine the maximum number of active bits that an array's size can require, which limits the maximu...
void diagnoseTypo(const TypoCorrection &Correction, const PartialDiagnostic &TypoDiag, bool ErrorRecovery=true)
ExprResult PerformCopyInitialization(const InitializedEntity &Entity, SourceLocation EqualLoc, ExprResult Init, bool TopLevelOfInitList=false, bool AllowExplicit=false)
Array must be initialized with an initializer list or a string literal.
DeclContextLookupResult LookupConstructors(CXXRecordDecl *Class)
Look up the constructors for the given class.
static bool isInvalid(LocType Loc, bool *Invalid)
QualType getType() const
Retrieve type being initialized.
Dataflow Directional Tag Classes.
static bool NarrowingErrs(const LangOptions &L)
bool isExplicit() const
Whether this function is explicit.
void setExtendingDecl(const ValueDecl *ExtendedBy, unsigned ManglingNumber)
bool isValid() const
Return true if this is a valid SourceLocation object.
Non-constant array initializer.
DeducedType * getContainedDeducedType() const
Get the DeducedType whose type will be deduced for a variable with an initializer of this type...
void setIncompleteTypeFailure(QualType IncompleteType)
Note that this initialization sequence failed due to an incomplete type.
A single step in the initialization sequence.
Array must be initialized with an initializer list or a wide string literal.
ExprResult ImpCastExprToType(Expr *E, QualType Type, CastKind CK, ExprValueKind VK=VK_RValue, const CXXCastPath *BasePath=nullptr, CheckedConversionKind CCK=CCK_ImplicitConversion)
ImpCastExprToType - If Expr is not of type 'Type', insert an implicit cast.
Too many initializers provided for a reference.
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 isNonReferenceableGLValue(Expr *E)
Determine whether an expression is a non-referenceable glvalue (one to which a reference can never bi...
Perform a load from a glvalue, producing an rvalue.
static void checkIndirectCopyRestoreSource(Sema &S, Expr *src)
Check whether the given expression is a valid operand for an indirect copy/restore.
Represents a field injected from an anonymous union/struct into the parent scope. ...
void HandleFunctionTypeMismatch(PartialDiagnostic &PDiag, QualType FromType, QualType ToType)
HandleFunctionTypeMismatch - Gives diagnostic information for differeing function types...
bool DiagRuntimeBehavior(SourceLocation Loc, const Stmt *Statement, const PartialDiagnostic &PD)
Conditionally issue a diagnostic based on the current evaluation context.
static FixItHint CreateRemoval(CharSourceRange RemoveRange)
Create a code modification hint that removes the given source range.
const Expr * getInit() const
Array-to-pointer conversion (C++ [conv.array])
const InitializedEntity * getParent() const
Retrieve the parent of the entity being initialized, when the initialization itself is occurring with...
SourceLocation getLBraceLoc() const
DeclarationName - The name of a declaration.
StmtClass getStmtClass() const
VectorKind getVectorKind() const
const CXXRecordDecl * getParent() const
Returns the parent of this method declaration, which is the class in which this method is defined...
static bool IsWideCharCompatible(QualType T, ASTContext &Context)
Check whether T is compatible with a wide character type (wchar_t, char16_t or char32_t).
SourceLocation getLocStart() const LLVM_READONLY
Requests that only viable candidates be shown.
Array initialization (from an array rvalue) as a GNU extension.
bool isIntegerConstantExpr(llvm::APSInt &Result, const ASTContext &Ctx, SourceLocation *Loc=nullptr, bool isEvaluated=true) const
isIntegerConstantExpr - Return true if this expression is a valid integer constant expression...
Optional< sema::TemplateDeductionInfo * > isSFINAEContext() const
Determines whether we are currently in a context where template argument substitution failures are no...
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...
bool isAggregateType() const
Determines whether the type is a C++ aggregate type or C aggregate or union type. ...
TypeLoc getModifiedLoc() const
The modified type, which is generally canonically different from the attribute type.
Overloading due to reference initialization failed.
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspnd...
void setInitializedFieldInUnion(FieldDecl *FD)
specific_decl_iterator - Iterates over a subrange of declarations stored in a DeclContext, providing only those that are of type SpecificDecl (or a class derived from it).
static bool isIdiomaticBraceElisionEntity(const InitializedEntity &Entity)
Determine whether Entity is an entity for which it is idiomatic to elide the braces in aggregate init...
Expr * IgnoreParenImpCasts() LLVM_READONLY
IgnoreParenImpCasts - Ignore parentheses and implicit casts.
Expr * getArrayRangeEnd(const Designator &D) const
static bool isRValueRef(QualType ParamType)
bool isStringLiteralInit() const
SourceLocation getFieldLoc() const
unsigned getIntWidth(QualType T) const
QualType getDependentSizedArrayType(QualType EltTy, Expr *NumElts, ArrayType::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 isIncompleteArrayType() const
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
void setAllToTypes(QualType T)
Complex values, per C99 6.2.5p11.
static bool TryOCLZeroEventInitialization(Sema &S, InitializationSequence &Sequence, QualType DestType, Expr *Initializer)
Array must be initialized with an initializer list.
static bool shouldDestroyEntity(const InitializedEntity &Entity)
Whether the given entity, when initialized with an object created for that initialization, requires destruction.
bool isIntegerType() const
isIntegerType() does not include complex integers (a GCC extension).
The entity being initialized is a structured binding of a decomposition declaration.
static void emitBadConversionNotes(Sema &S, const InitializedEntity &entity, Expr *op)
Emit notes associated with an initialization that failed due to a "simple" conversion failure...
chain_iterator chain_begin() const
ObjCEncodeExpr, used for @encode in Objective-C.
bool CheckDerivedToBaseConversion(QualType Derived, QualType Base, SourceLocation Loc, SourceRange Range, CXXCastPath *BasePath=nullptr, bool IgnoreAccess=false)
const llvm::APInt & getSize() const
Reference binding failed.
void AddTemplateOverloadCandidate(FunctionTemplateDecl *FunctionTemplate, DeclAccessPair FoundDecl, TemplateArgumentListInfo *ExplicitTemplateArgs, ArrayRef< Expr *> Args, OverloadCandidateSet &CandidateSet, bool SuppressUserConversions=false, bool PartialOverloading=false)
Add a C++ function template specialization as a candidate in the candidate set, using template argume...
bool isAtomicType() 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.
bool isFunctionType() const
TypeSourceInfo * getTypeSourceInfo() const
FieldDecl * getField() const
MaterializeTemporaryExpr * CreateMaterializeTemporaryExpr(QualType T, Expr *Temporary, bool BoundToLvalueReference)
Expr * getArg(unsigned Arg)
Return the specified argument.
bool isImplicitlyDeleted(FunctionDecl *FD)
Determine whether the given function is an implicitly-deleted special member function.
Base for LValueReferenceType and RValueReferenceType.
DeclContext * getRedeclContext()
getRedeclContext - Retrieve the context in which an entity conflicts with other entities of the same ...
bool hasSameType(QualType T1, QualType T2) const
Determine whether the given types T1 and T2 are equivalent.
void AddArrayInitLoopStep(QualType T, QualType EltTy)
Add an array initialization loop step.
AccessResult CheckMemberOperatorAccess(SourceLocation Loc, Expr *ObjectExpr, Expr *ArgExpr, DeclAccessPair FoundDecl)
Checks access to an overloaded member operator, including conversion operators.
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.
step_iterator step_end() const
void AddDerivedToBaseCastStep(QualType BaseType, ExprValueKind Category)
Add a new step in the initialization that performs a derived-to- base cast.
bool isConstantArrayType() const
QualType getNonLValueExprType(const ASTContext &Context) const
Determine the type of a (typically non-lvalue) expression with the specified result type...
void setExprNeedsCleanups(bool SideEffects)
APValue - This class implements a discriminated union of [uninitialized] [APSInt] [APFloat]...
Represents a base class of a C++ class.
bool isInitListConstructor(const FunctionDecl *Ctor)
Determine whether Ctor is an initializer-list constructor, as defined in [dcl.init.list]p2.
static bool TryOCLSamplerInitialization(Sema &S, InitializationSequence &Sequence, QualType DestType, Expr *Initializer)
uint64_t getTypeSize(QualType T) const
Return the size of the specified (complete) type T, in bits.
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...
static SourceLocation getInitializationLoc(const InitializedEntity &Entity, Expr *Initializer)
Get the location at which initialization diagnostics should appear.
bool isObjCObjectType() const
bool isIncompleteType(NamedDecl **Def=nullptr) const
Types are partitioned into 3 broad categories (C99 6.2.5p1): object types, function types...
bool 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...
CanQualType getCanonicalType(QualType T) const
Return the canonical (structural) type corresponding to the specified potentially non-canonical type ...
bool isLValueReferenceType() const
TypeLoc getTypeLoc() const
Return the TypeLoc wrapper for the type source info.
Reading or writing from this object requires a barrier call.
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...
Direct-initialization from a reference-related object in the final stage of class copy-initialization...
DesignatorKind getKind() const
SourceLocation getLocEnd() const LLVM_READONLY
bool typesAreCompatible(QualType T1, QualType T2, bool CompareUnqualified=false)
Compatibility predicates used to check assignment expressions.
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])
bool Failed() const
Determine whether the initialization sequence is invalid.
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], C99 6.7.8).
Describes the sequence of initializations required to initialize a given object or reference with a s...
ActionResult< Expr * > ExprResult
QualType getUnqualifiedType() const
Retrieve the unqualified variant of the given type, removing as little sugar as possible.
Represents a C++ struct/union/class.
Compatible - the types are compatible according to the standard.
Perform initialization via a constructor, taking arguments from a single InitListExpr.
bool CompleteConstructorCall(CXXConstructorDecl *Constructor, 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 ...
Represents a loop initializing the elements of an array.
SourceRange getRange() const
Retrieve the source range that covers the initialization.
QualType getRValueReferenceType(QualType T) const
Return the uniqued reference to the type for an rvalue reference to the specified type...
bool isParameterConsumed() const
Determine whether this initialization consumes the parameter.
Represents a C array with an unspecified size.
static bool hasAnyTypeDependentArguments(ArrayRef< Expr *> Exprs)
hasAnyTypeDependentArguments - Determines if any of the expressions in Exprs is type-dependent.
Qualifiers getQualifiers() const
Retrieve the set of qualifiers applied to this type.
The entity being initialized is a field of block descriptor for the copied-in lambda object that's us...
The parameter type of a method or function.
The entity being initialized is the field that captures a variable in a lambda.
void setSequenceKind(enum SequenceKind SK)
Set the kind of sequence computed.
DeclContext * CurContext
CurContext - This is the current declaration context of parsing.
static void TryValueInitialization(Sema &S, const InitializedEntity &Entity, const InitializationKind &Kind, InitializationSequence &Sequence, InitListExpr *InitList=nullptr)
Attempt value initialization (C++ [dcl.init]p7).
A dependent initialization, which could not be type-checked due to the presence of dependent types or...
Declaration of a class template.
bool isCStyleCast() const
Determine whether this is a C-style cast.
SourceLocation getRBracketLoc() const
QualType getPointerType(QualType T) const
Return the uniqued reference to the type for a pointer to the specified type.
This class is used for builtin types like 'int'.
SourceManager & getSourceManager() const
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
StringLiteral - This represents a string literal expression, e.g.
Defines the clang::TargetInfo interface.
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
static bool isOrIsDerivedFromSpecializationOf(CXXRecordDecl *RD, ClassTemplateDecl *CTD)
Determine whether RD is, or is derived from, a specialization of CTD.
Designator * getDesignator(unsigned Idx)
unsigned getCVRQualifiers() const
Reference binding to a temporary.
void reserveInits(const ASTContext &C, unsigned NumInits)
Reserve space for some number of initializers.
void EmitRelatedResultTypeNote(const Expr *E)
If the given expression involves a message send to a method with a related result type...
static Decl::Kind getKind(const Decl *D)
void AddConstructorInitializationStep(DeclAccessPair FoundDecl, CXXConstructorDecl *Constructor, QualType T, bool HadMultipleCandidates, bool FromInitList, bool AsInitList)
Add a constructor-initialization step.
unsigned getNumElements() const
Designation - Represent a full designation, which is a sequence of designators.
static Sema::AssignmentAction getAssignmentAction(const InitializedEntity &Entity, bool Diagnose=false)
bool isDependentType() const
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
A reference to a declared variable, function, enum, etc.
bool isIgnored(unsigned DiagID, SourceLocation Loc) const
Determine whether the diagnostic is known to be ignored.
Designator - A designator in a C99 designated initializer.
bool isDeleted() const
Whether this function has been deleted.
CXXConstructorDecl * LookupDefaultConstructor(CXXRecordDecl *Class)
Look up the default constructor for the given class.
bool isPointerType() const
The initialization is being done by a delegating constructor.
ExprResult BuildCXXDefaultInitExpr(SourceLocation Loc, FieldDecl *Field)
void AddQualificationConversionStep(QualType Ty, ExprValueKind Category)
Add a new step that performs a qualification conversion to the given type.
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...
__DEVICE__ int min(int __a, int __b)
SourceManager & SourceMgr
ImplicitConversionKind First
First – The first conversion can be an lvalue-to-rvalue conversion, array-to-pointer conversion...
FieldDecl * getInitializedFieldInUnion()
If this initializes a union, specifies which field in the union to initialize.
No viable function found.
A failed initialization sequence.
Array initialization (from an array rvalue).
AccessResult CheckAddressOfMemberAccess(Expr *OvlExpr, DeclAccessPair FoundDecl)
An l-value expression is a reference to an object with independent storage.
Default-initialization of a 'const' object.
unsigned getNumArgs() const
bool isFloatingType() const
void AddConversionSequenceStep(const ImplicitConversionSequence &ICS, QualType T, bool TopLevelOfInitList=false)
Add a new step that applies an implicit conversion sequence.
A trivial tuple used to represent a source range.
TypoCorrection CorrectTypo(const DeclarationNameInfo &Typo, Sema::LookupNameKind LookupKind, Scope *S, CXXScopeSpec *SS, std::unique_ptr< 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...
This represents a decl that may have a name.
bool isOpenCLSpecificType() const
SourceLocation getDotLoc() const
Represents a C array with a specified size that is not an integer-constant-expression.
Automatic storage duration (most local variables).
static void DiagnoseNarrowingInInitList(Sema &S, const ImplicitConversionSequence &ICS, QualType PreNarrowingType, QualType EntityType, const Expr *PostInit)
Describes an entity that is being initialized.
bool isDefaultMemberInitializer() const
Is this the default member initializer of a member (specified inside the class definition)?
void setToType(unsigned Idx, QualType T)
unsigned getNumParams() const
Return the number of parameters this function must have based on its FunctionType.
ObjCMethodDecl * getMethodDecl() const
Retrieve the ObjectiveC method being initialized.
SourceLocation getBegin() const
const LangOptions & getLangOpts() const
bool hasDefaultConstructor() const
Determine whether this class has any default constructors.
bool isVariableLengthArrayNew() const
Determine whether this is an array new with an unknown bound.
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 ...
Direct list-initialization.
void NoteCandidates(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...
Array initialization from a parenthesized initializer list.
IdentifierInfo * getFieldName() const
Represents the canonical version of C arrays with a specified constant size.
InitListExpr * getSyntacticForm() const
static void MaybeProduceObjCObject(Sema &S, InitializationSequence &Sequence, const InitializedEntity &Entity)
Declaration of a template function.
Represents an implicitly-generated value initialization of an object of a given type.
QualType getUnqualifiedArrayType(QualType T, Qualifiers &Quals)
Return this type as a completely-unqualified array type, capturing the qualifiers in Quals...
SourceLocation getLocation() const
QualType getType() const
Return the type wrapped by this type source info.
static bool TryOCLZeroQueueInitialization(Sema &S, InitializationSequence &Sequence, QualType DestType, Expr *Initializer)
static bool maybeRecoverWithZeroInitialization(Sema &S, InitializationSequence &Sequence, const InitializedEntity &Entity)
Tries to add a zero initializer. Returns true if that worked.
Non-const lvalue reference binding to a temporary.
Expr * IgnoreParens() LLVM_READONLY
IgnoreParens - Ignore parentheses.
bool isCXXInstanceMember() const
Determine whether the given declaration is an instance member of a C++ class.
CanQualType getSizeType() const
Return the unique type for "size_t" (C99 7.17), defined in <stddef.h>.
Qualifiers::ObjCLifetime getObjCLifetime() const
Returns lifetime attribute of this type.
SourceRange getSourceRange() const LLVM_READONLY
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...
StandardConversionSequence - represents a standard conversion sequence (C++ 13.3.3.1.1).
QualType getType() const
Retrieves the type of the base class.