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?");
149 if (isa<StringLiteral>(E) || isa<ObjCEncodeExpr>(E)) {
151 }
else if (
ParenExpr *PE = dyn_cast<ParenExpr>(E)) {
152 E = PE->getSubExpr();
154 assert(UO->getOpcode() == UO_Extension);
155 E = UO->getSubExpr();
157 E = GSE->getResultExpr();
158 }
else if (
ChooseExpr *CE = dyn_cast<ChooseExpr>(E)) {
159 E = CE->getChosenSubExpr();
161 llvm_unreachable(
"unexpected expr in string literal init");
171 if (isa<CompoundLiteralExpr>(E)) {
173 }
else if (
ParenExpr *PE = dyn_cast<ParenExpr>(E)) {
174 E = PE->getSubExpr();
176 assert(UO->getOpcode() == UO_Extension);
177 E = UO->getSubExpr();
179 E = GSE->getResultExpr();
180 }
else if (
ChooseExpr *CE = dyn_cast<ChooseExpr>(E)) {
181 E = CE->getChosenSubExpr();
183 llvm_unreachable(
"unexpected expr in array compound literal init");
191 auto *ConstantArrayTy =
193 uint64_t StrLength = ConstantArrayTy->getSize().getZExtValue();
223 if (StrLength > CAT->
getSize().getZExtValue())
225 diag::err_initializer_string_for_char_array_too_long)
229 if (StrLength-1 > CAT->
getSize().getZExtValue())
231 diag::ext_initializer_string_for_char_array_too_long)
279 class InitListChecker {
281 bool hadError =
false;
283 bool TreatUnavailableAsInvalid;
284 bool InOverloadResolution;
297 unsigned &StructuredIndex);
301 bool TopLevelObject =
false);
304 bool SubobjectIsDesignatorContext,
307 unsigned &StructuredIndex,
308 bool TopLevelObject =
false);
313 unsigned &StructuredIndex);
318 unsigned &StructuredIndex);
323 unsigned &StructuredIndex);
328 unsigned &StructuredIndex);
332 unsigned &StructuredIndex);
337 bool SubobjectIsDesignatorContext,
unsigned &Index,
339 unsigned &StructuredIndex,
340 bool TopLevelObject =
false);
344 bool SubobjectIsDesignatorContext,
unsigned &Index,
346 unsigned &StructuredIndex);
355 unsigned &StructuredIndex,
356 bool FinishSubobjectInit,
357 bool TopLevelObject);
361 unsigned StructuredIndex,
363 bool IsFullyOverwritten =
false);
364 void UpdateStructuredListElement(
InitListExpr *StructuredList,
365 unsigned &StructuredIndex,
369 unsigned ExpectedNumInits);
370 int numArrayElements(
QualType DeclType);
371 int numStructUnionElements(
QualType DeclType);
378 bool FullyOverwritten =
true) {
382 ? diag::ext_initializer_overrides
383 : diag::warn_initializer_overrides;
385 if (InOverloadResolution && SemaRef.
getLangOpts().CPlusPlus) {
406 DiagID = diag::err_initializer_overrides_destructed;
426 << NewInitRange << FullyOverwritten << OldInit->
getType();
455 bool FillWithNoInit);
456 void FillInEmptyInitForField(
unsigned Init,
FieldDecl *Field,
459 bool FillWithNoInit =
false);
463 bool FillWithNoInit =
false);
466 bool TopLevelObject);
472 QualType &T,
bool VerifyOnly,
bool TreatUnavailableAsInvalid,
473 bool InOverloadResolution =
false);
474 bool HadError() {
return hadError; }
478 InitListExpr *getFullyStructuredList()
const {
return FullyStructuredList; }
495 bool EmptyInitList = SemaRef.getLangOpts().CPlusPlus11 &&
508 InitExpr = VerifyOnly ? &DummyInitList :
new (SemaRef.Context)
510 InitExpr->
setType(SemaRef.Context.VoidTy);
531 assert(O ==
OR_Success &&
"Inconsistent overload resolution");
537 SemaRef.SourceMgr.isInSystemHeader(CtorDecl->
getLocation())) {
538 bool IsInStd =
false;
539 for (
NamespaceDecl *ND = dyn_cast<NamespaceDecl>(R->getDeclContext());
540 ND && !IsInStd; ND = dyn_cast<
NamespaceDecl>(ND->getParent())) {
541 if (SemaRef.getStdNamespace()->InEnclosingNamespaceSetOf(ND))
545 if (IsInStd && llvm::StringSwitch<bool>(R->getName())
546 .Cases(
"basic_string",
"deque",
"forward_list",
true)
547 .Cases(
"list",
"map",
"multimap",
"multiset",
true)
548 .Cases(
"priority_queue",
"queue",
"set",
"stack",
true)
549 .Cases(
"unordered_map",
"unordered_set",
"vector",
true)
555 TreatUnavailableAsInvalid);
560 diag::warn_invalid_initializer_from_system_header);
563 diag::note_used_in_initialization_here);
565 SemaRef.Diag(Loc, diag::note_used_in_initialization_here);
572 InitSeq.
Diagnose(SemaRef, Entity, Kind, SubInit);
575 diag::note_in_omitted_aggregate_initializer)
578 bool IsTrailingArrayNewMember =
581 SemaRef.Diag(Loc, diag::note_in_omitted_aggregate_initializer)
582 << (IsTrailingArrayNewMember ? 2 : 0)
591 : InitSeq.
Perform(SemaRef, Entity, Kind, SubInit);
599 if (FullyStructuredList)
601 PerformEmptyInit(Loc, Entity);
604 void InitListChecker::FillInEmptyInitForBase(
607 bool &RequiresSecondPass,
bool FillWithNoInit) {
609 SemaRef.Context, &Base,
false, &ParentEntity);
614 : PerformEmptyInit(ILE->
getEndLoc(), BaseEntity);
621 assert(Init < ILE->getNumInits() &&
"should have been expanded");
625 dyn_cast<InitListExpr>(ILE->
getInit(Init))) {
626 FillInEmptyInitializations(BaseEntity, InnerILE, RequiresSecondPass,
627 ILE, Init, FillWithNoInit);
629 dyn_cast<DesignatedInitUpdateExpr>(ILE->
getInit(Init))) {
630 FillInEmptyInitializations(BaseEntity, InnerDIUE->getUpdater(),
631 RequiresSecondPass, ILE, Init,
636 void InitListChecker::FillInEmptyInitForField(
unsigned Init,
FieldDecl *Field,
639 bool &RequiresSecondPass,
640 bool FillWithNoInit) {
646 if (Init >= NumInits || !ILE->
getInit(Init)) {
648 if (!RType->getDecl()->isUnion())
649 assert((Init < NumInits || VerifyOnly) &&
650 "This ILE should have been expanded");
652 if (FillWithNoInit) {
653 assert(!VerifyOnly &&
"should not fill with no-init in verify-only mode");
658 ILE->
updateInit(SemaRef.Context, Init, Filler);
669 ExprResult DIE = SemaRef.BuildCXXDefaultInitExpr(Loc, Field);
674 SemaRef.checkInitializerLifetime(MemberEntity, DIE.
get());
679 RequiresSecondPass =
true;
690 SemaRef.Diag(Loc, diag::err_init_reference_member_uninitialized)
694 diag::note_uninit_reference_member);
700 ExprResult MemberInit = PerformEmptyInit(Loc, MemberEntity);
706 if (hadError || VerifyOnly) {
708 }
else if (Init < NumInits) {
710 }
else if (!isa<ImplicitValueInitExpr>(MemberInit.
get())) {
716 RequiresSecondPass =
true;
719 = dyn_cast<InitListExpr>(ILE->
getInit(Init))) {
720 FillInEmptyInitializations(MemberEntity, InnerILE,
721 RequiresSecondPass, ILE, Init, FillWithNoInit);
723 dyn_cast<DesignatedInitUpdateExpr>(ILE->
getInit(Init))) {
724 FillInEmptyInitializations(MemberEntity, InnerDIUE->getUpdater(),
725 RequiresSecondPass, ILE, Init,
736 bool &RequiresSecondPass,
739 bool FillWithNoInit) {
740 assert((ILE->
getType() != SemaRef.Context.VoidTy) &&
741 "Should not have void type");
745 if (FillWithNoInit && VerifyOnly)
755 struct UpdateOuterILEWithUpdatedInit {
758 ~UpdateOuterILEWithUpdatedInit() {
762 } UpdateOuterRAII = {OuterILE, OuterIndex};
773 Entity, ILE, RequiresSecondPass, FillWithNoInit);
774 else if (RDecl->
isUnion() && isa<CXXRecordDecl>(RDecl) &&
775 cast<CXXRecordDecl>(RDecl)->hasInClassInitializer()) {
776 for (
auto *Field : RDecl->
fields()) {
778 FillInEmptyInitForField(0, Field, Entity, ILE, RequiresSecondPass,
787 unsigned NumElems = numStructUnionElements(ILE->getType());
790 if (!VerifyOnly && ILE->getNumInits() < NumElems)
791 ILE->resizeInits(SemaRef.Context, NumElems);
795 if (
auto *CXXRD = dyn_cast<CXXRecordDecl>(RDecl)) {
796 for (
auto &Base : CXXRD->bases()) {
800 FillInEmptyInitForBase(Init, Base, Entity, ILE, RequiresSecondPass,
806 for (
auto *Field : RDecl->
fields()) {
813 FillInEmptyInitForField(Init, Field, Entity, ILE, RequiresSecondPass,
833 unsigned NumElements = NumInits;
834 if (
const ArrayType *AType = SemaRef.Context.getAsArrayType(ILE->
getType())) {
835 ElementType = AType->getElementType();
836 if (
const auto *CAType = dyn_cast<ConstantArrayType>(AType))
837 NumElements = CAType->getSize().getZExtValue();
845 ElementType = VType->getElementType();
846 NumElements = VType->getNumElements();
852 bool SkipEmptyInitChecks =
false;
853 for (
unsigned Init = 0; Init != NumElements; ++Init) {
861 if (Init >= NumInits && (ILE->
hasArrayFiller() || SkipEmptyInitChecks))
864 Expr *InitExpr = (Init < NumInits ? ILE->
getInit(Init) :
nullptr);
865 if (!InitExpr && Init < NumInits && ILE->hasArrayFiller())
870 if (SkipEmptyInitChecks)
873 Expr *Filler =
nullptr;
876 Filler =
new (SemaRef.Context)
NoInitExpr(ElementType);
879 PerformEmptyInit(ILE->
getEndLoc(), ElementEntity);
890 }
else if (VerifyOnly) {
891 SkipEmptyInitChecks =
true;
892 }
else if (Init < NumInits) {
907 if (!isa<ImplicitValueInitExpr>(Filler) && !isa<NoInitExpr>(Filler)) {
912 ILE->
updateInit(SemaRef.Context, Init, Filler);
913 RequiresSecondPass =
true;
917 = dyn_cast_or_null<InitListExpr>(InitExpr)) {
918 FillInEmptyInitializations(ElementEntity, InnerILE, RequiresSecondPass,
919 ILE, Init, FillWithNoInit);
921 dyn_cast_or_null<DesignatedInitUpdateExpr>(InitExpr)) {
922 FillInEmptyInitializations(ElementEntity, InnerDIUE->getUpdater(),
923 RequiresSecondPass, ILE, Init,
930 for (
const Stmt *Init : *IL)
931 if (Init && isa<DesignatedInitExpr>(Init))
938 bool TreatUnavailableAsInvalid,
939 bool InOverloadResolution)
940 : SemaRef(S), VerifyOnly(VerifyOnly),
941 TreatUnavailableAsInvalid(TreatUnavailableAsInvalid),
942 InOverloadResolution(InOverloadResolution) {
944 FullyStructuredList =
950 FullyStructuredList->setSyntacticForm(IL);
953 CheckExplicitInitList(Entity, IL, T, FullyStructuredList,
956 if (!hadError && FullyStructuredList) {
957 bool RequiresSecondPass =
false;
958 FillInEmptyInitializations(Entity, FullyStructuredList, RequiresSecondPass,
960 if (RequiresSecondPass && !hadError)
961 FillInEmptyInitializations(Entity, FullyStructuredList,
962 RequiresSecondPass,
nullptr, 0);
966 int InitListChecker::numArrayElements(
QualType DeclType) {
968 int maxElements = 0x7FFFFFFF;
970 SemaRef.Context.getAsConstantArrayType(DeclType)) {
971 maxElements =
static_cast<int>(CAT->getSize().getZExtValue());
976 int InitListChecker::numStructUnionElements(
QualType DeclType) {
978 int InitializableMembers = 0;
979 if (
auto *CXXRD = dyn_cast<CXXRecordDecl>(structDecl))
980 InitializableMembers += CXXRD->getNumBases();
981 for (
const auto *Field : structDecl->
fields())
983 ++InitializableMembers;
986 return std::min(InitializableMembers, 1);
1008 if (
CXXRecordDecl *CXXRD = dyn_cast<CXXRecordDecl>(ParentRD))
1009 if (CXXRD->getNumBases())
1012 auto FieldIt = ParentRD->field_begin();
1013 assert(FieldIt != ParentRD->field_end() &&
1014 "no fields but have initializer for member?");
1015 return ++FieldIt == ParentRD->field_end();
1028 unsigned &StructuredIndex) {
1029 int maxElements = 0;
1032 maxElements = numArrayElements(T);
1034 maxElements = numStructUnionElements(T);
1038 llvm_unreachable(
"CheckImplicitInitList(): Illegal type");
1040 if (maxElements == 0) {
1043 diag::err_implicit_empty_initializer);
1050 InitListExpr *StructuredSubobjectInitList = getStructuredSubobjectInit(
1051 ParentIList, Index, T, StructuredList, StructuredIndex,
1054 unsigned StructuredSubobjectInitIndex = 0;
1057 unsigned StartIndex = Index;
1058 CheckListElementTypes(Entity, ParentIList, T,
1060 StructuredSubobjectInitList,
1061 StructuredSubobjectInitIndex);
1063 if (StructuredSubobjectInitList) {
1064 StructuredSubobjectInitList->
setType(T);
1066 unsigned EndIndex = (Index == StartIndex? StartIndex : Index - 1);
1069 if (EndIndex < ParentIList->getNumInits() &&
1070 ParentIList->
getInit(EndIndex)) {
1080 SemaRef.Diag(StructuredSubobjectInitList->
getBeginLoc(),
1081 diag::warn_missing_braces)
1086 SemaRef.getLocForEndOfToken(
1087 StructuredSubobjectInitList->
getEndLoc()),
1093 if (!VerifyOnly && CXXRD && CXXRD->hasUserDeclaredConstructor()) {
1094 SemaRef.Diag(StructuredSubobjectInitList->
getBeginLoc(),
1095 diag::warn_cxx2a_compat_aggregate_init_with_ctors)
1111 unsigned DiagID = 0;
1121 DiagID = diag::warn_braces_around_scalar_init;
1128 DiagID = diag::warn_braces_around_scalar_init;
1154 llvm_unreachable(
"unexpected braced scalar init");
1173 bool TopLevelObject) {
1174 unsigned Index = 0, StructuredIndex = 0;
1175 CheckListElementTypes(Entity, IList, T,
true,
1176 Index, StructuredList, StructuredIndex, TopLevelObject);
1177 if (StructuredList) {
1183 StructuredList->
setType(ExprTy);
1191 bool ExtraInitsIsError = SemaRef.getLangOpts().CPlusPlus ||
1193 hadError = ExtraInitsIsError;
1196 }
else if (StructuredIndex == 1 &&
1201 ? diag::err_excess_initializers_in_char_array_initializer
1202 : diag::ext_excess_initializers_in_char_array_initializer;
1212 unsigned DK = ExtraInitsIsError ? diag::err_excess_initializers
1213 : diag::ext_excess_initializers;
1221 !isa<InitListExpr>(IList->
getInit(0)))
1227 if (CXXRD && CXXRD->hasUserDeclaredConstructor()) {
1230 bool HasEquivCtor =
false;
1232 auto *CD = SemaRef.LookupDefaultConstructor(CXXRD);
1233 HasEquivCtor = CD && !CD->isDeleted();
1236 if (!HasEquivCtor) {
1238 diag::warn_cxx2a_compat_aggregate_init_with_ctors)
1248 bool SubobjectIsDesignatorContext,
1251 unsigned &StructuredIndex,
1252 bool TopLevelObject) {
1256 CheckComplexType(Entity, IList, DeclType, Index,
1257 StructuredList, StructuredIndex);
1259 CheckScalarType(Entity, IList, DeclType, Index,
1260 StructuredList, StructuredIndex);
1262 CheckVectorType(Entity, IList, DeclType, Index,
1263 StructuredList, StructuredIndex);
1266 "non-aggregate records should be handed in CheckSubElementType");
1271 if (
auto *CXXRD = dyn_cast<CXXRecordDecl>(RD))
1272 Bases = CXXRD->bases();
1273 CheckStructUnionTypes(Entity, IList, DeclType, Bases, RD->field_begin(),
1274 SubobjectIsDesignatorContext, Index, StructuredList,
1275 StructuredIndex, TopLevelObject);
1278 SemaRef.Context.getTypeSize(SemaRef.Context.getSizeType()),
1280 CheckArrayType(Entity, IList, DeclType, Zero,
1281 SubobjectIsDesignatorContext, Index,
1282 StructuredList, StructuredIndex);
1287 SemaRef.Diag(IList->
getBeginLoc(), diag::err_illegal_initializer_type)
1291 CheckReferenceType(Entity, IList, DeclType, Index,
1292 StructuredList, StructuredIndex);
1295 SemaRef.Diag(IList->
getBeginLoc(), diag::err_init_objc_class) << DeclType;
1299 CheckScalarType(Entity, IList, DeclType, Index, StructuredList,
1303 SemaRef.Diag(IList->
getBeginLoc(), diag::err_illegal_initializer_type)
1314 unsigned &StructuredIndex) {
1318 return CheckReferenceType(Entity, IList, ElemType, Index,
1319 StructuredList, StructuredIndex);
1321 if (
InitListExpr *SubInitList = dyn_cast<InitListExpr>(expr)) {
1322 if (SubInitList->getNumInits() == 1 &&
1323 IsStringInit(SubInitList->getInit(0), ElemType, SemaRef.Context) ==
1327 expr = SubInitList->getInit(0);
1330 }
else if (isa<ImplicitValueInitExpr>(expr)) {
1333 assert(SemaRef.Context.hasSameType(expr->
getType(), ElemType) &&
1334 "found implicit initialization for the wrong type");
1335 UpdateStructuredListElement(StructuredList, StructuredIndex, expr);
1340 if (SemaRef.getLangOpts().CPlusPlus || isa<InitListExpr>(
expr)) {
1366 if (Seq || isa<InitListExpr>(expr)) {
1372 UpdateStructuredListElement(StructuredList, StructuredIndex,
1376 }
else if (StructuredList) {
1377 UpdateStructuredListElement(StructuredList, StructuredIndex,
1387 return CheckScalarType(Entity, IList, ElemType, Index,
1388 StructuredList, StructuredIndex);
1390 SemaRef.Context.getAsArrayType(ElemType)) {
1400 UpdateStructuredListElement(StructuredList, StructuredIndex, expr);
1420 if (SemaRef.CheckSingleAssignmentConstraints(
1425 ExprRes = SemaRef.DefaultFunctionArrayLvalueConversion(ExprRes.
get());
1429 UpdateStructuredListElement(StructuredList, StructuredIndex,
1445 if ((!SemaRef.getLangOpts().OpenCL && ElemType->
isVectorType()) ||
1447 CheckImplicitInitList(Entity, IList, ElemType, Index, StructuredList,
1456 SemaRef.PerformCopyInitialization(Entity,
SourceLocation(), expr,
1460 "expected non-aggregate initialization to fail");
1472 unsigned &StructuredIndex) {
1473 assert(Index == 0 &&
"Index in explicit init list must be zero");
1483 return CheckScalarType(Entity, IList, DeclType, Index, StructuredList,
1488 if (!SemaRef.getLangOpts().CPlusPlus && !VerifyOnly)
1489 SemaRef.Diag(IList->
getBeginLoc(), diag::ext_complex_component_init)
1497 for (
unsigned i = 0; i < 2; ++i) {
1499 CheckSubElementType(ElementEntity, IList, elementType, Index,
1500 StructuredList, StructuredIndex);
1508 unsigned &StructuredIndex) {
1512 SemaRef.getLangOpts().CPlusPlus11
1513 ? diag::warn_cxx98_compat_empty_scalar_initializer
1514 : diag::err_empty_scalar_initializer)
1516 hadError = !SemaRef.getLangOpts().CPlusPlus11;
1523 if (
InitListExpr *SubIList = dyn_cast<InitListExpr>(expr)) {
1527 SemaRef.Diag(SubIList->getBeginLoc(),
1528 diag::ext_many_braces_around_scalar_init)
1531 CheckScalarType(Entity, SubIList, DeclType, Index, StructuredList,
1534 }
else if (isa<DesignatedInitExpr>(expr)) {
1536 SemaRef.Diag(expr->
getBeginLoc(), diag::err_designator_for_scalar_init)
1546 if (SemaRef.CanPerformCopyInitialization(Entity, expr))
1547 Result = getDummyInit();
1556 Expr *ResultExpr =
nullptr;
1563 if (ResultExpr != expr && !VerifyOnly) {
1566 IList->
setInit(Index, ResultExpr);
1572 UpdateStructuredListElement(StructuredList, StructuredIndex, ResultExpr);
1580 unsigned &StructuredIndex) {
1588 diag::err_init_reference_member_uninitialized)
1597 if (isa<InitListExpr>(expr) && !SemaRef.getLangOpts().CPlusPlus11) {
1599 SemaRef.Diag(IList->
getBeginLoc(), diag::err_init_non_aggr_init_list)
1609 if (SemaRef.CanPerformCopyInitialization(Entity,expr))
1610 Result = getDummyInit();
1630 UpdateStructuredListElement(StructuredList, StructuredIndex, expr);
1638 unsigned &StructuredIndex) {
1641 unsigned numEltsInit = 0;
1646 CheckEmptyInitializable(
1652 if (!SemaRef.getLangOpts().OpenCL) {
1659 if (SemaRef.CanPerformCopyInitialization(Entity, Init))
1660 Result = getDummyInit();
1665 SemaRef.PerformCopyInitialization(Entity, Init->
getBeginLoc(), Init,
1669 Expr *ResultExpr =
nullptr;
1675 if (ResultExpr != Init && !VerifyOnly) {
1678 IList->
setInit(Index, ResultExpr);
1684 UpdateStructuredListElement(StructuredList, StructuredIndex,
1693 for (
unsigned i = 0; i < maxElements; ++i, ++numEltsInit) {
1696 CheckEmptyInitializable(ElementEntity, IList->
getEndLoc());
1701 CheckSubElementType(ElementEntity, IList, elementType, Index,
1702 StructuredList, StructuredIndex);
1708 bool isBigEndian = SemaRef.Context.getTargetInfo().isBigEndian();
1723 diag::warn_neon_vector_initializer_non_portable);
1725 const char *typeCode;
1726 unsigned typeSize = SemaRef.Context.getTypeSize(elementType);
1735 llvm_unreachable(
"Invalid element type!");
1738 SemaRef.Context.getTypeSize(VT) > 64
1739 ? diag::note_neon_vector_initializer_non_portable_q
1740 : diag::note_neon_vector_initializer_non_portable)
1741 << typeCode << typeSize;
1751 for (
unsigned i = 0; i < maxElements; ++i) {
1760 CheckSubElementType(ElementEntity, IList, elementType, Index,
1761 StructuredList, StructuredIndex);
1769 VecType = SemaRef.Context.getExtVectorType(elementType, numIElts);
1771 VecType = SemaRef.Context.getVectorType(elementType, numIElts,
1773 CheckSubElementType(ElementEntity, IList, VecType, Index,
1774 StructuredList, StructuredIndex);
1775 numEltsInit += numIElts;
1780 if (numEltsInit != maxElements) {
1783 diag::err_vector_incorrect_num_initializers)
1784 << (numEltsInit < maxElements) << maxElements << numEltsInit;
1807 SemaRef.
PDiag(diag::err_access_dtor_temp)
1816 bool SubobjectIsDesignatorContext,
1819 unsigned &StructuredIndex) {
1831 if (Index < IList->getNumInits()) {
1842 if (StructuredList) {
1843 UpdateStructuredListElement(StructuredList, StructuredIndex,
1845 StructuredList->
resizeInits(SemaRef.Context, StructuredIndex);
1856 SemaRef.Diag(VAT->getSizeExpr()->getBeginLoc(),
1857 diag::err_variable_object_no_init)
1858 << VAT->getSizeExpr()->getSourceRange();
1867 elementIndex.isUnsigned());
1868 bool maxElementsKnown =
false;
1870 maxElements = CAT->getSize();
1871 elementIndex = elementIndex.extOrTrunc(maxElements.getBitWidth());
1872 elementIndex.setIsUnsigned(maxElements.isUnsigned());
1873 maxElementsKnown =
true;
1877 while (Index < IList->getNumInits()) {
1883 if (!SubobjectIsDesignatorContext)
1888 if (CheckDesignatedInitializer(Entity, IList, DIE, 0,
1889 DeclType,
nullptr, &elementIndex, Index,
1890 StructuredList, StructuredIndex,
true,
1896 if (elementIndex.getBitWidth() > maxElements.getBitWidth())
1897 maxElements = maxElements.extend(elementIndex.getBitWidth());
1898 else if (elementIndex.getBitWidth() < maxElements.getBitWidth())
1899 elementIndex = elementIndex.extend(maxElements.getBitWidth());
1900 elementIndex.setIsUnsigned(maxElements.isUnsigned());
1904 if (!maxElementsKnown && elementIndex > maxElements)
1905 maxElements = elementIndex;
1912 if (maxElementsKnown && elementIndex == maxElements)
1919 CheckSubElementType(ElementEntity, IList, elementType, Index,
1920 StructuredList, StructuredIndex);
1925 if (!maxElementsKnown && elementIndex > maxElements)
1926 maxElements = elementIndex;
1935 SemaRef.Diag(IList->
getBeginLoc(), diag::ext_typecheck_zero_array_size);
1938 DeclType = SemaRef.Context.getConstantArrayType(
1946 if ((maxElementsKnown && elementIndex < maxElements) ||
1948 CheckEmptyInitializable(
1957 bool TopLevelObject) {
1959 unsigned FlexArrayDiag;
1960 if (isa<InitListExpr>(InitExpr) &&
1961 cast<InitListExpr>(InitExpr)->getNumInits() == 0) {
1963 FlexArrayDiag = diag::ext_flexible_array_init;
1964 }
else if (SemaRef.getLangOpts().CPlusPlus) {
1967 FlexArrayDiag = diag::err_flexible_array_init;
1968 }
else if (!TopLevelObject) {
1970 FlexArrayDiag = diag::err_flexible_array_init;
1973 FlexArrayDiag = diag::err_flexible_array_init;
1974 }
else if (cast<VarDecl>(Entity.
getDecl())->hasLocalStorage()) {
1976 FlexArrayDiag = diag::err_flexible_array_init;
1979 FlexArrayDiag = diag::ext_flexible_array_init;
1983 SemaRef.Diag(InitExpr->
getBeginLoc(), FlexArrayDiag)
1985 SemaRef.Diag(Field->
getLocation(), diag::note_flexible_array_member)
1989 return FlexArrayDiag != diag::ext_flexible_array_init;
1992 void InitListChecker::CheckStructUnionTypes(
1995 bool SubobjectIsDesignatorContext,
unsigned &Index,
1996 InitListExpr *StructuredList,
unsigned &StructuredIndex,
1997 bool TopLevelObject) {
2014 QualType ET = SemaRef.Context.getBaseElementType(FD->getType());
2022 if (isa<CXXRecordDecl>(RD) &&
2023 cast<CXXRecordDecl>(RD)->hasInClassInitializer()) {
2024 if (!StructuredList)
2027 Field != FieldEnd; ++Field) {
2028 if (Field->hasInClassInitializer()) {
2039 Field != FieldEnd; ++Field) {
2040 if (!Field->isUnnamedBitfield()) {
2041 CheckEmptyInitializable(
2052 bool InitializedSomething =
false;
2055 for (
auto &Base : Bases) {
2060 if (Init && isa<DesignatedInitExpr>(Init))
2065 SemaRef.Context, &Base,
false, &Entity);
2067 CheckSubElementType(BaseEntity, IList, Base.
getType(), Index,
2068 StructuredList, StructuredIndex);
2069 InitializedSomething =
true;
2071 CheckEmptyInitializable(BaseEntity, InitLoc);
2087 bool CheckForMissingFields =
2089 bool HasDesignatedInit =
false;
2091 while (Index < IList->getNumInits()) {
2099 if (!SubobjectIsDesignatorContext)
2102 HasDesignatedInit =
true;
2106 if (CheckDesignatedInitializer(Entity, IList, DIE, 0,
2107 DeclType, &Field,
nullptr, Index,
2108 StructuredList, StructuredIndex,
2109 true, TopLevelObject))
2111 else if (!VerifyOnly) {
2114 while (std::next(F) != Field)
2116 QualType ET = SemaRef.Context.getBaseElementType(F->getType());
2123 InitializedSomething =
true;
2127 CheckForMissingFields =
false;
2131 if (Field == FieldEnd) {
2137 if (InitializedSomething && DeclType->
isUnionType())
2141 if (Field->getType()->isIncompleteArrayType())
2144 if (Field->isUnnamedBitfield()) {
2153 InvalidUse = !SemaRef.CanUseDecl(*Field, TreatUnavailableAsInvalid);
2155 InvalidUse = SemaRef.DiagnoseUseOfDecl(
2165 QualType ET = SemaRef.Context.getBaseElementType(Field->getType());
2174 CheckSubElementType(MemberEntity, IList, Field->getType(), Index,
2175 StructuredList, StructuredIndex);
2176 InitializedSomething =
true;
2180 StructuredList->setInitializedFieldInUnion(*Field);
2187 if (!VerifyOnly && InitializedSomething && CheckForMissingFields &&
2188 Field != FieldEnd && !Field->getType()->isIncompleteArrayType() &&
2194 if (!it->isUnnamedBitfield() && !it->hasInClassInitializer()) {
2196 diag::warn_missing_field_initializers) << *it;
2204 if (!StructuredList && Field != FieldEnd && !DeclType->
isUnionType() &&
2205 !Field->getType()->isIncompleteArrayType()) {
2206 for (; Field != FieldEnd && !hadError; ++Field) {
2207 if (!Field->isUnnamedBitfield() && !Field->hasInClassInitializer())
2208 CheckEmptyInitializable(
2221 QualType ET = SemaRef.Context.getBaseElementType(I->getType());
2229 if (Field == FieldEnd || !Field->getType()->isIncompleteArrayType() ||
2233 if (CheckFlexibleArrayInit(Entity, IList->
getInit(Index), *Field,
2243 if (isa<InitListExpr>(IList->
getInit(Index)))
2244 CheckSubElementType(MemberEntity, IList, Field->getType(), Index,
2245 StructuredList, StructuredIndex);
2247 CheckImplicitInitList(MemberEntity, IList, Field->getType(), Index,
2248 StructuredList, StructuredIndex);
2264 PE = IndirectField->
chain_end(); PI != PE; ++PI) {
2272 assert(isa<FieldDecl>(*PI));
2273 Replacements.back().setField(cast<FieldDecl>(*PI));
2280 &Replacements[0] + Replacements.size());
2287 for (
unsigned I = 0; I < NumIndexExprs; ++I)
2301 explicit FieldInitializerValidatorCCC(
RecordDecl *RD)
2304 bool ValidateCandidate(
const TypoCorrection &candidate)
override {
2309 std::unique_ptr<CorrectionCandidateCallback> clone()
override {
2310 return std::make_unique<FieldInitializerValidatorCCC>(*this);
2366 unsigned &StructuredIndex,
2367 bool FinishSubobjectInit,
2368 bool TopLevelObject) {
2369 if (DesigIdx == DIE->
size()) {
2376 assert(isa<InitListExpr>(Init) &&
2377 "designator result in direct non-list initialization?");
2382 if (StructuredList) {
2385 : Seq.Perform(SemaRef, Entity, Kind, Init);
2386 UpdateStructuredListElement(StructuredList, StructuredIndex,
2394 bool prevHadError = hadError;
2399 unsigned OldIndex = Index;
2402 CheckSubElementType(Entity, IList, CurrentObjectType, Index,
2403 StructuredList, StructuredIndex);
2409 IList->
setInit(OldIndex, DIE);
2411 return hadError && !prevHadError;
2415 bool IsFirstDesignator = (DesigIdx == 0);
2416 if (IsFirstDesignator ? FullyStructuredList : StructuredList) {
2419 if (IsFirstDesignator)
2420 StructuredList = FullyStructuredList;
2422 Expr *ExistingInit = StructuredIndex < StructuredList->getNumInits() ?
2423 StructuredList->getInit(StructuredIndex) :
nullptr;
2424 if (!ExistingInit && StructuredList->hasArrayFiller())
2425 ExistingInit = StructuredList->getArrayFiller();
2428 StructuredList = getStructuredSubobjectInit(
2429 IList, Index, CurrentObjectType, StructuredList, StructuredIndex,
2445 diagnoseInitOverride(ExistingInit,
2451 dyn_cast<DesignatedInitUpdateExpr>(ExistingInit))
2452 StructuredList = E->getUpdater();
2457 StructuredList->updateInit(SemaRef.Context, StructuredIndex, DIUE);
2466 StructuredList =
nullptr;
2488 SemaRef.Diag(Loc, diag::err_field_designator_non_aggr)
2489 << SemaRef.getLangOpts().CPlusPlus << CurrentObjectType;
2499 if (
auto *FD = dyn_cast<FieldDecl>(ND)) {
2503 if (
auto *IFD = dyn_cast<IndirectFieldDecl>(ND)) {
2509 KnownField = cast<FieldDecl>(*IFD->chain_begin());
2520 if (!Lookup.empty()) {
2521 SemaRef.Diag(D->
getFieldLoc(), diag::err_field_designator_nonfield)
2523 SemaRef.Diag(Lookup.front()->getLocation(),
2524 diag::note_field_designator_found);
2531 FieldInitializerValidatorCCC CCC(RT->
getDecl());
2536 SemaRef.diagnoseTypo(
2538 SemaRef.PDiag(diag::err_field_designator_unknown_suggest)
2539 << FieldName << CurrentObjectType);
2540 KnownField = Corrected.getCorrectionDeclAs<
FieldDecl>();
2544 SemaRef.Diag(D->
getFieldLoc(), diag::err_field_designator_unknown)
2545 << FieldName << CurrentObjectType;
2552 unsigned NumBases = 0;
2553 if (
auto *CXXRD = dyn_cast<CXXRecordDecl>(RT->
getDecl()))
2554 NumBases = CXXRD->getNumBases();
2556 unsigned FieldIndex = NumBases;
2559 if (FI->isUnnamedBitfield())
2575 if (StructuredList) {
2576 FieldDecl *CurrentField = StructuredList->getInitializedFieldInUnion();
2578 assert(StructuredList->getNumInits() == 1
2579 &&
"A union should never have more than one initializer!");
2581 Expr *ExistingInit = StructuredList->getInit(0);
2584 diagnoseInitOverride(
2589 StructuredList->resizeInits(SemaRef.Context, 0);
2590 StructuredList->setInitializedFieldInUnion(
nullptr);
2593 StructuredList->setInitializedFieldInUnion(*Field);
2600 InvalidUse = !SemaRef.CanUseDecl(*Field, TreatUnavailableAsInvalid);
2602 InvalidUse = SemaRef.DiagnoseUseOfDecl(*Field, D->
getFieldLoc());
2623 if (IsFirstDesignator && !VerifyOnly && SemaRef.getLangOpts().CPlusPlus &&
2626 (*NextField)->getFieldIndex() > Field->getFieldIndex() + 1)) {
2631 if (FI->isUnnamedBitfield())
2641 SemaRef.Diag(DIE->
getBeginLoc(), diag::ext_designated_init_reordered)
2645 if (StructuredList && OldIndex <= StructuredList->getNumInits()) {
2646 if (
Expr *PrevInit = StructuredList->getInit(OldIndex)) {
2647 SemaRef.Diag(PrevInit->getBeginLoc(),
2648 diag::note_previous_field_init)
2662 if (StructuredList && FieldIndex >= StructuredList->getNumInits())
2663 StructuredList->resizeInits(SemaRef.Context, FieldIndex + 1);
2666 if (Field->getType()->isIncompleteArrayType()) {
2667 bool Invalid =
false;
2668 if ((DesigIdx + 1) != DIE->
size()) {
2675 diag::err_designator_into_flexible_array_member)
2677 SemaRef.Diag(Field->getLocation(), diag::note_flexible_array_member)
2683 if (!hadError && !isa<InitListExpr>(DIE->
getInit()) &&
2684 !isa<StringLiteral>(DIE->
getInit())) {
2688 diag::err_flexible_array_init_needs_braces)
2690 SemaRef.Diag(Field->getLocation(), diag::note_flexible_array_member)
2697 if (!Invalid && CheckFlexibleArrayInit(Entity, DIE->
getInit(), *Field,
2707 bool prevHadError = hadError;
2708 unsigned newStructuredIndex = FieldIndex;
2709 unsigned OldIndex = Index;
2714 CheckSubElementType(MemberEntity, IList, Field->getType(), Index,
2715 StructuredList, newStructuredIndex);
2717 IList->
setInit(OldIndex, DIE);
2718 if (hadError && !prevHadError) {
2723 StructuredIndex = FieldIndex;
2728 QualType FieldType = Field->getType();
2729 unsigned newStructuredIndex = FieldIndex;
2733 if (CheckDesignatedInitializer(MemberEntity, IList, DIE, DesigIdx + 1,
2734 FieldType,
nullptr,
nullptr, Index,
2735 StructuredList, newStructuredIndex,
2736 FinishSubobjectInit,
false))
2747 if (IsFirstDesignator) {
2750 StructuredIndex = FieldIndex;
2754 if (!FinishSubobjectInit)
2762 bool prevHadError = hadError;
2767 CheckStructUnionTypes(Entity, IList, CurrentObjectType, NoBases, Field,
2768 false, Index, StructuredList, FieldIndex);
2769 return hadError && !prevHadError;
2787 const ArrayType *AT = SemaRef.Context.getAsArrayType(CurrentObjectType);
2790 SemaRef.Diag(D->
getLBracketLoc(), diag::err_array_designator_non_array)
2791 << CurrentObjectType;
2796 Expr *IndexExpr =
nullptr;
2801 DesignatedEndIndex = DesignatedStartIndex;
2805 DesignatedStartIndex =
2807 DesignatedEndIndex =
2816 if (DesignatedStartIndex.getZExtValue()!=DesignatedEndIndex.getZExtValue()&&
2818 FullyStructuredList->sawArrayRangeDesignator();
2821 if (isa<ConstantArrayType>(AT)) {
2822 llvm::APSInt MaxElements(cast<ConstantArrayType>(AT)->getSize(),
false);
2823 DesignatedStartIndex
2824 = DesignatedStartIndex.extOrTrunc(MaxElements.getBitWidth());
2825 DesignatedStartIndex.setIsUnsigned(MaxElements.isUnsigned());
2827 = DesignatedEndIndex.extOrTrunc(MaxElements.getBitWidth());
2828 DesignatedEndIndex.setIsUnsigned(MaxElements.isUnsigned());
2829 if (DesignatedEndIndex >= MaxElements) {
2832 diag::err_array_designator_too_large)
2833 << DesignatedEndIndex.toString(10) << MaxElements.toString(10)
2839 unsigned DesignatedIndexBitWidth =
2841 DesignatedStartIndex =
2842 DesignatedStartIndex.extOrTrunc(DesignatedIndexBitWidth);
2843 DesignatedEndIndex =
2844 DesignatedEndIndex.extOrTrunc(DesignatedIndexBitWidth);
2845 DesignatedStartIndex.setIsUnsigned(
true);
2846 DesignatedEndIndex.setIsUnsigned(
true);
2849 bool IsStringLiteralInitUpdate =
2850 StructuredList && StructuredList->isStringLiteralInit();
2851 if (IsStringLiteralInitUpdate && VerifyOnly) {
2854 StructuredList =
nullptr;
2855 }
else if (IsStringLiteralInitUpdate) {
2868 unsigned PromotedCharTyWidth = Context.
getTypeSize(PromotedCharTy);
2872 uint64_t StrLen = SL->getLength();
2873 if (cast<ConstantArrayType>(AT)->getSize().ult(StrLen))
2874 StrLen = cast<ConstantArrayType>(AT)->getSize().getZExtValue();
2875 StructuredList->resizeInits(Context, StrLen);
2879 for (
unsigned i = 0, e = StrLen; i != e; ++i) {
2880 llvm::APInt CodeUnit(PromotedCharTyWidth, SL->getCodeUnit(i));
2882 Context, CodeUnit, PromotedCharTy, SubExpr->
getExprLoc());
2883 if (CharTy != PromotedCharTy)
2886 StructuredList->updateInit(Context, i, Init);
2894 uint64_t StrLen = Str.size();
2895 if (cast<ConstantArrayType>(AT)->getSize().ult(StrLen))
2896 StrLen = cast<ConstantArrayType>(AT)->getSize().getZExtValue();
2897 StructuredList->resizeInits(Context, StrLen);
2901 for (
unsigned i = 0, e = StrLen; i != e; ++i) {
2902 llvm::APInt CodeUnit(PromotedCharTyWidth, Str[i]);
2904 Context, CodeUnit, PromotedCharTy, SubExpr->
getExprLoc());
2905 if (CharTy != PromotedCharTy)
2908 StructuredList->updateInit(Context, i, Init);
2915 if (StructuredList &&
2916 DesignatedEndIndex.getZExtValue() >= StructuredList->getNumInits())
2917 StructuredList->resizeInits(SemaRef.Context,
2918 DesignatedEndIndex.getZExtValue() + 1);
2924 unsigned ElementIndex = DesignatedStartIndex.getZExtValue();
2925 unsigned OldIndex = Index;
2930 while (DesignatedStartIndex <= DesignatedEndIndex) {
2936 if (CheckDesignatedInitializer(
2937 ElementEntity, IList, DIE, DesigIdx + 1, ElementType,
nullptr,
2938 nullptr, Index, StructuredList, ElementIndex,
2939 FinishSubobjectInit && (DesignatedStartIndex == DesignatedEndIndex),
2944 ++DesignatedStartIndex;
2945 ElementIndex = DesignatedStartIndex.getZExtValue();
2950 if (IsFirstDesignator) {
2951 if (NextElementIndex)
2952 *NextElementIndex = DesignatedStartIndex;
2953 StructuredIndex = ElementIndex;
2957 if (!FinishSubobjectInit)
2961 bool prevHadError = hadError;
2962 CheckArrayType(Entity, IList, CurrentObjectType, DesignatedStartIndex,
2964 StructuredList, ElementIndex);
2965 return hadError && !prevHadError;
2971 InitListChecker::getStructuredSubobjectInit(
InitListExpr *IList,
unsigned Index,
2974 unsigned StructuredIndex,
2976 bool IsFullyOverwritten) {
2977 if (!StructuredList)
2980 Expr *ExistingInit =
nullptr;
2981 if (StructuredIndex < StructuredList->getNumInits())
2982 ExistingInit = StructuredList->
getInit(StructuredIndex);
2993 if (!IsFullyOverwritten)
3016 diagnoseInitOverride(ExistingInit, InitRange);
3019 unsigned ExpectedNumInits = 0;
3020 if (Index < IList->getNumInits()) {
3021 if (
auto *Init = dyn_cast_or_null<InitListExpr>(IList->
getInit(Index)))
3022 ExpectedNumInits = Init->getNumInits();
3028 createInitListExpr(CurrentObjectType, InitRange, ExpectedNumInits);
3032 StructuredList->
updateInit(SemaRef.Context, StructuredIndex, Result);
3037 InitListChecker::createInitListExpr(
QualType CurrentObjectType,
3039 unsigned ExpectedNumInits) {
3045 QualType ResultType = CurrentObjectType;
3051 unsigned NumElements = 0;
3054 = SemaRef.Context.getAsArrayType(CurrentObjectType)) {
3056 NumElements = CAType->getSize().getZExtValue();
3059 if (NumElements > ExpectedNumInits)
3063 NumElements = VType->getNumElements();
3065 NumElements = numStructUnionElements(CurrentObjectType);
3075 void InitListChecker::UpdateStructuredListElement(
InitListExpr *StructuredList,
3076 unsigned &StructuredIndex,
3079 if (!StructuredList)
3083 StructuredIndex, expr)) {
3096 InitListChecker Check(*
this, Entity, From, Type,
true,
3099 return !Check.HadError();
3118 if (Value.isSigned() && Value.isNegative())
3119 return S.
Diag(Loc, diag::err_array_designator_negative)
3122 Value.setIsUnsigned(
true);
3132 bool Invalid =
false;
3153 Designators.push_back(ASTDesignator(InitExpressions.size(),
3156 InitExpressions.push_back(Index);
3170 if (!StartDependent)
3176 if (!StartIndex || !EndIndex)
3180 if (StartDependent || EndDependent) {
3182 }
else if (StartValue.getBitWidth() > EndValue.getBitWidth())
3183 EndValue = EndValue.extend(StartValue.getBitWidth());
3184 else if (StartValue.getBitWidth() < EndValue.getBitWidth())
3185 StartValue = StartValue.extend(EndValue.getBitWidth());
3187 if (!StartDependent && !EndDependent && EndValue < StartValue) {
3189 << StartValue.toString(10) << EndValue.toString(10)
3193 Designators.push_back(ASTDesignator(InitExpressions.size(),
3197 InitExpressions.push_back(StartIndex);
3198 InitExpressions.push_back(EndIndex);
3213 EqualOrColonLoc, GNUSyntax,
3221 InitializedEntity::InitializedEntity(
ASTContext &Context,
unsigned Index,
3223 :
Parent(&Parent), Index(Index)
3226 Kind = EK_ArrayElement;
3227 Type = AT->getElementType();
3229 Kind = EK_VectorElement;
3230 Type = VT->getElementType();
3233 assert(CT &&
"Unexpected type");
3234 Kind = EK_ComplexElement;
3242 bool IsInheritedVirtualBase,
3245 Result.Kind = EK_Base;
3248 if (IsInheritedVirtualBase)
3249 Result.
Base |= 0x01;
3251 Result.Type = Base->
getType();
3258 case EK_Parameter_CF_Audited: {
3266 return Variable.VariableOrMember->getDeclName();
3268 case EK_LambdaCapture:
3272 case EK_StmtExprResult:
3278 case EK_ArrayElement:
3279 case EK_VectorElement:
3280 case EK_ComplexElement:
3281 case EK_BlockElement:
3282 case EK_LambdaToBlockConversionBlockElement:
3283 case EK_CompoundLiteralInit:
3284 case EK_RelatedResult:
3288 llvm_unreachable(
"Invalid EntityKind!");
3296 return Variable.VariableOrMember;
3299 case EK_Parameter_CF_Audited:
3303 case EK_StmtExprResult:
3309 case EK_ArrayElement:
3310 case EK_VectorElement:
3311 case EK_ComplexElement:
3312 case EK_BlockElement:
3313 case EK_LambdaToBlockConversionBlockElement:
3314 case EK_LambdaCapture:
3315 case EK_CompoundLiteralInit:
3316 case EK_RelatedResult:
3320 llvm_unreachable(
"Invalid EntityKind!");
3327 return LocAndNRVO.NRVO;
3329 case EK_StmtExprResult:
3332 case EK_Parameter_CF_Audited:
3337 case EK_CompoundLiteralInit:
3340 case EK_ArrayElement:
3341 case EK_VectorElement:
3342 case EK_ComplexElement:
3343 case EK_BlockElement:
3344 case EK_LambdaToBlockConversionBlockElement:
3345 case EK_LambdaCapture:
3346 case EK_RelatedResult:
3353 unsigned InitializedEntity::dumpImpl(raw_ostream &OS)
const {
3354 assert(getParent() !=
this);
3355 unsigned Depth = getParent() ? getParent()->dumpImpl(OS) : 0;
3356 for (
unsigned I = 0; I !=
Depth; ++I)
3360 case EK_Variable: OS <<
"Variable";
break;
3361 case EK_Parameter: OS <<
"Parameter";
break;
3362 case EK_Parameter_CF_Audited: OS <<
"CF audited function Parameter";
3364 case EK_Result: OS <<
"Result";
break;
3365 case EK_StmtExprResult: OS <<
"StmtExprResult";
break;
3366 case EK_Exception: OS <<
"Exception";
break;
3367 case EK_Member: OS <<
"Member";
break;
3368 case EK_Binding: OS <<
"Binding";
break;
3369 case EK_New: OS <<
"New";
break;
3370 case EK_Temporary: OS <<
"Temporary";
break;
3371 case EK_CompoundLiteralInit: OS <<
"CompoundLiteral";
break;
3372 case EK_RelatedResult: OS <<
"RelatedResult";
break;
3373 case EK_Base: OS <<
"Base";
break;
3374 case EK_Delegating: OS <<
"Delegating";
break;
3375 case EK_ArrayElement: OS <<
"ArrayElement " << Index;
break;
3376 case EK_VectorElement: OS <<
"VectorElement " << Index;
break;
3377 case EK_ComplexElement: OS <<
"ComplexElement " << Index;
break;
3378 case EK_BlockElement: OS <<
"Block";
break;
3379 case EK_LambdaToBlockConversionBlockElement:
3380 OS <<
"Block (lambda)";
3382 case EK_LambdaCapture:
3383 OS <<
"LambdaCapture ";
3388 if (
auto *D = getDecl()) {
3390 D->printQualifiedName(OS);
3393 OS <<
" '" << getType().getAsString() <<
"'\n";
3399 dumpImpl(llvm::errs());
3408 case SK_ResolveAddressOfOverloadedFunction:
3409 case SK_CastDerivedToBaseRValue:
3410 case SK_CastDerivedToBaseXValue:
3411 case SK_CastDerivedToBaseLValue:
3412 case SK_BindReference:
3413 case SK_BindReferenceToTemporary:
3415 case SK_ExtraneousCopyToTemporary:
3416 case SK_UserConversion:
3417 case SK_QualificationConversionRValue:
3418 case SK_QualificationConversionXValue:
3419 case SK_QualificationConversionLValue:
3420 case SK_AtomicConversion:
3421 case SK_ListInitialization:
3422 case SK_UnwrapInitList:
3423 case SK_RewrapInitList:
3424 case SK_ConstructorInitialization:
3425 case SK_ConstructorInitializationFromList:
3426 case SK_ZeroInitialization:
3427 case SK_CAssignment:
3429 case SK_ObjCObjectConversion:
3430 case SK_ArrayLoopIndex:
3431 case SK_ArrayLoopInit:
3433 case SK_GNUArrayInit:
3434 case SK_ParenthesizedArrayInit:
3435 case SK_PassByIndirectCopyRestore:
3436 case SK_PassByIndirectRestore:
3437 case SK_ProduceObjCObject:
3438 case SK_StdInitializerList:
3439 case SK_StdInitializerListConstructorCall:
3440 case SK_OCLSamplerInit:
3441 case SK_OCLZeroOpaqueType:
3444 case SK_ConversionSequence:
3445 case SK_ConversionSequenceNoNarrowing:
3452 for (
auto I = Steps.rbegin(); I != Steps.rend(); ++I) {
3453 if (I->Kind == SK_BindReference)
3455 if (I->Kind == SK_BindReferenceToTemporary)
3465 switch (getFailureKind()) {
3466 case FK_TooManyInitsForReference:
3467 case FK_ParenthesizedListInitForReference:
3468 case FK_ArrayNeedsInitList:
3469 case FK_ArrayNeedsInitListOrStringLiteral:
3470 case FK_ArrayNeedsInitListOrWideStringLiteral:
3471 case FK_NarrowStringIntoWideCharArray:
3472 case FK_WideStringIntoCharArray:
3473 case FK_IncompatWideStringIntoWideChar:
3474 case FK_PlainStringIntoUTF8Char:
3475 case FK_UTF8StringIntoPlainChar:
3476 case FK_AddressOfOverloadFailed:
3477 case FK_NonConstLValueReferenceBindingToTemporary:
3478 case FK_NonConstLValueReferenceBindingToBitfield:
3479 case FK_NonConstLValueReferenceBindingToVectorElement:
3480 case FK_NonConstLValueReferenceBindingToUnrelated:
3481 case FK_RValueReferenceBindingToLValue:
3482 case FK_ReferenceAddrspaceMismatchTemporary:
3483 case FK_ReferenceInitDropsQualifiers:
3484 case FK_ReferenceInitFailed:
3485 case FK_ConversionFailed:
3486 case FK_ConversionFromPropertyFailed:
3487 case FK_TooManyInitsForScalar:
3488 case FK_ParenthesizedListInitForScalar:
3489 case FK_ReferenceBindingToInitList:
3490 case FK_InitListBadDestinationType:
3491 case FK_DefaultInitOfConst:
3493 case FK_ArrayTypeMismatch:
3494 case FK_NonConstantArrayInit:
3495 case FK_ListInitializationFailed:
3496 case FK_VariableLengthArrayHasInitializer:
3497 case FK_PlaceholderType:
3498 case FK_ExplicitConstructor:
3499 case FK_AddressOfUnaddressableFunction:
3502 case FK_ReferenceInitOverloadFailed:
3503 case FK_UserConversionOverloadFailed:
3504 case FK_ConstructorOverloadFailed:
3505 case FK_ListConstructorOverloadFailed:
3509 llvm_unreachable(
"Invalid EntityKind!");
3513 return !Steps.empty() && Steps.back().Kind == SK_ConstructorInitialization;
3520 bool HadMultipleCandidates) {
3522 S.
Kind = SK_ResolveAddressOfOverloadedFunction;
3543 bool BindingTemporary) {
3545 S.
Kind = BindingTemporary? SK_BindReferenceToTemporary : SK_BindReference;
3552 S.
Kind = SK_FinalCopy;
3559 S.
Kind = SK_ExtraneousCopyToTemporary;
3568 bool HadMultipleCandidates) {
3570 S.
Kind = SK_UserConversion;
3581 S.
Kind = SK_QualificationConversionRValue;
3584 S.
Kind = SK_QualificationConversionRValue;
3587 S.
Kind = SK_QualificationConversionXValue;
3590 S.
Kind = SK_QualificationConversionLValue;
3599 S.
Kind = SK_AtomicConversion;
3606 bool TopLevelOfInitList) {
3608 S.
Kind = TopLevelOfInitList ? SK_ConversionSequenceNoNarrowing
3609 : SK_ConversionSequence;
3617 S.
Kind = SK_ListInitialization;
3624 bool HadMultipleCandidates,
bool FromInitList,
bool AsInitList) {
3626 S.
Kind = FromInitList ? AsInitList ? SK_StdInitializerListConstructorCall
3627 : SK_ConstructorInitializationFromList
3628 : SK_ConstructorInitialization;
3638 S.
Kind = SK_ZeroInitialization;
3645 S.
Kind = SK_CAssignment;
3652 S.
Kind = SK_StringInit;
3659 S.
Kind = SK_ObjCObjectConversion;
3666 S.
Kind = IsGNUExtension ? SK_GNUArrayInit : SK_ArrayInit;
3673 S.
Kind = SK_ArrayLoopIndex;
3675 Steps.insert(Steps.begin(), S);
3677 S.
Kind = SK_ArrayLoopInit;
3684 S.
Kind = SK_ParenthesizedArrayInit;
3692 s.
Kind = (shouldCopy ? SK_PassByIndirectCopyRestore
3693 : SK_PassByIndirectRestore);
3700 S.
Kind = SK_ProduceObjCObject;
3707 S.
Kind = SK_StdInitializerList;
3714 S.
Kind = SK_OCLSamplerInit;
3721 S.
Kind = SK_OCLZeroOpaqueType;
3729 "Can only rewrap trivial init lists.");
3731 S.Kind = SK_UnwrapInitList;
3733 Steps.insert(Steps.begin(), S);
3735 S.Kind = SK_RewrapInitList;
3737 S.WrappingSyntacticList = Syntactic;
3743 setSequenceKind(FailedSequence);
3744 this->Failure = Failure;
3745 this->FailedOverloadResult =
Result;
3766 if (!Init.empty()) {
3786 "consuming an object of unretainable type?");
3807 bool TreatUnavailableAsInvalid);
3818 bool TreatUnavailableAsInvalid) {
3839 TreatUnavailableAsInvalid);
3869 bool CopyInitializing,
bool AllowExplicit,
3870 bool OnlyListConstructors,
bool IsListInit,
3871 bool SecondStepOfCopyInit =
false) {
3877 if (!Info.Constructor || Info.Constructor->isInvalidDecl())
3894 bool SuppressUserConversions =
3895 SecondStepOfCopyInit ||
3896 (IsListInit && Args.size() == 1 && isa<InitListExpr>(Args[0]) &&
3899 if (Info.ConstructorTmpl)
3901 Info.ConstructorTmpl, Info.FoundDecl,
3902 nullptr, Args, CandidateSet, SuppressUserConversions,
3903 false, AllowExplicit);
3912 bool AllowExplicitConv = AllowExplicit && !CopyInitializing &&
3916 CandidateSet, SuppressUserConversions,
3917 false, AllowExplicit,
3933 if (S.
getLangOpts().CPlusPlus17 && Args.size() == 1 &&
3934 !SecondStepOfCopyInit) {
3939 for (
auto I = Conversions.begin(), E = Conversions.end(); I != E; ++I) {
3949 Conv = cast<CXXConversionDecl>(D);
3953 ConvTemplate, I.getPair(), ActingDC,
Initializer, DestType,
3954 CandidateSet, AllowExplicit, AllowExplicit,
3958 DestType, CandidateSet, AllowExplicit,
3985 bool IsListInit =
false,
3986 bool IsInitListCopy =
false) {
3987 assert(((!IsListInit && !IsInitListCopy) ||
3988 (Args.size() == 1 && isa<InitListExpr>(Args[0]))) &&
3989 "IsListInit/IsInitListCopy must come with a single initializer list " 3992 (IsListInit || IsInitListCopy) ? cast<InitListExpr>(Args[0]) :
nullptr;
4016 UnwrappedArgs.size() == 1 && UnwrappedArgs[0]->isRValue() &&
4026 assert(DestRecordType &&
"Constructor initialization requires record type");
4028 = cast<CXXRecordDecl>(DestRecordType->
getDecl());
4046 bool AsInitializerList =
false;
4058 AsInitializerList =
true;
4064 CandidateSet, DestType, Ctors, Best,
4065 CopyInitialization, AllowExplicit,
4076 AsInitializerList =
false;
4078 CandidateSet, DestType, Ctors, Best,
4079 CopyInitialization, AllowExplicit,
4091 bool HadMultipleCandidates = (CandidateSet.size() > 1);
4095 if (
auto *CD = dyn_cast<CXXConversionDecl>(Best->Function)) {
4097 QualType ConvType = CD->getConversionType();
4099 "should not have selected this conversion function");
4101 HadMultipleCandidates);
4138 Best->FoundDecl, CtorDecl, DestArrayType, HadMultipleCandidates,
4139 IsListInit | IsInitListCopy, AsInitializerList);
4152 bool HadMultipleCandidates =
false;
4155 UnqualifiedTargetType,
4157 &HadMultipleCandidates)) {
4159 HadMultipleCandidates);
4160 SourceType = Fn->getType();
4192 bool TreatUnavailableAsInvalid) {
4232 T1Quals, cv2T2, T2, T2Quals, Sequence);
4247 TreatUnavailableAsInvalid);
4264 bool TreatUnavailableAsInvalid) {
4276 TreatUnavailableAsInvalid);
4302 Expr *InitListAsExpr = InitList;
4312 if (!isa<VariableArrayType>(DestAT) &&
4322 TreatUnavailableAsInvalid);
4355 TreatUnavailableAsInvalid))
4359 Expr *InitListAsExpr = InitList;
4361 DestType, Sequence,
true);
4379 ET && ET->getDecl()->isFixed() &&
4435 TreatUnavailableAsInvalid);
4442 InitListChecker CheckInitList(S, Entity, InitList,
4443 DestType,
true, TreatUnavailableAsInvalid);
4444 if (CheckInitList.HadError()) {
4457 Expr *Initializer,
bool AllowRValues,
bool IsLValueRef,
4466 "Must have incompatible references when binding via conversion");
4477 bool AllowExplicitCtors =
false;
4489 if (!Info.Constructor)
4492 if (!Info.Constructor->isInvalidDecl() &&
4493 Info.Constructor->isConvertingConstructor(
true)) {
4494 if (Info.ConstructorTmpl)
4496 Info.ConstructorTmpl, Info.FoundDecl,
4497 nullptr, Initializer, CandidateSet,
4499 false, AllowExplicitCtors);
4502 Info.Constructor, Info.FoundDecl, Initializer, CandidateSet,
4504 false, AllowExplicitCtors);
4519 for (
auto I = Conversions.begin(), E = Conversions.end(); I != E; ++I) {
4522 if (isa<UsingShadowDecl>(D))
4523 D = cast<UsingShadowDecl>(D)->getTargetDecl();
4530 Conv = cast<CXXConversionDecl>(D);
4538 if ((AllowRValues ||
4539 Conv->getConversionType()->isLValueReferenceType())) {
4542 ConvTemplate, I.getPair(), ActingDC,
Initializer, DestType,
4544 false, AllowExplicitConvs);
4547 Conv, I.getPair(), ActingDC,
Initializer, DestType, CandidateSet,
4548 false, AllowExplicitConvs);
4570 if (isa<CXXConversionDecl>(Function))
4583 bool HadMultipleCandidates = (CandidateSet.
size() > 1);
4585 HadMultipleCandidates);
4595 assert(!isa<CXXConstructorDecl>(Function) &&
4596 "should not have conversion after constructor");
4600 ICS.
Standard = Best->FinalConversion;
4621 if (RefConv & Sema::ReferenceConversions::DerivedToBase)
4627 else if (RefConv & Sema::ReferenceConversions::Qualification) {
4662 T1Quals, cv2T2, T2, T2Quals, Sequence);
4705 if (isLValueRef || T1Function) {
4712 if (RefConv & (Sema::ReferenceConversions::DerivedToBase |
4716 if (RefConv & (Sema::ReferenceConversions::Qualification))
4720 if (RefConv & Sema::ReferenceConversions::DerivedToBase)
4724 }
else if (RefConv & (Sema::ReferenceConversions::Qualification |
4748 (isLValueRef || InitCategory.
isRValue())) {
4750 S, Entity, Kind, Initializer, isRValueRef,
4751 isLValueRef, Sequence);
4782 switch (RefRelationship) {
4786 FK_NonConstLValueReferenceBindingToBitfield;
4789 FK_NonConstLValueReferenceBindingToVectorElement;
4791 llvm_unreachable(
"unexpected kind of compatible initializer");
4844 auto T1QualsIgnoreAS = T1Quals;
4845 auto T2QualsIgnoreAS = T2Quals;
4848 T2QualsIgnoreAS.removeAddressSpace();
4851 if (T1QualsIgnoreAS != T2QualsIgnoreAS)
4861 cv1T4 = cv1T4WithAS;
4866 if (RefConv & Sema::ReferenceConversions::DerivedToBase)
4870 else if (RefConv & Sema::ReferenceConversions::Qualification) {
4886 S, Entity, Kind, Initializer,
true,
4887 isLValueRef, Sequence);
4897 isRValueRef && InitCategory.
isLValue()) {
4956 (T1CVRQuals | T2CVRQuals) != T1CVRQuals) ||
5001 assert((!InitList || InitList->
getNumInits() == 0) &&
5002 "Shouldn't use value-init for non-empty init lists");
5013 if (
CXXRecordDecl *ClassDecl = dyn_cast<CXXRecordDecl>(RT->getDecl())) {
5014 bool NeedZeroInitialization =
true;
5029 NeedZeroInitialization =
false;
5037 if (NeedZeroInitialization)
5051 ClassDecl->hasUninitializedReferenceMember()) {
5059 Expr *InitListAsExpr = InitList;
5061 bool InitListSyntax = InitList;
5066 S, Entity, Kind, Args, T, Entity.
getType(), Sequence, InitListSyntax);
5088 if (DestType->isRecordType() && S.
getLangOpts().CPlusPlus) {
5099 if (DestType.isConstQualified() && S.
getLangOpts().CPlusPlus) {
5106 if (DestType.getQualifiers().hasObjCLifetime()) {
5120 bool TopLevelOfInitList) {
5121 assert(!DestType->
isReferenceType() &&
"References are handled elsewhere");
5123 assert((DestType->
isRecordType() || SourceType->isRecordType()) &&
5124 "Must have a class type to perform a user-defined conversion");
5140 = cast<CXXRecordDecl>(DestRecordType->getDecl());
5146 if (!Info.Constructor)
5149 if (!Info.Constructor->isInvalidDecl() &&
5150 Info.Constructor->isConvertingConstructor(
true)) {
5151 if (Info.ConstructorTmpl)
5153 Info.ConstructorTmpl, Info.FoundDecl,
5154 nullptr, Initializer, CandidateSet,
5156 false, AllowExplicit);
5159 Initializer, CandidateSet,
5161 false, AllowExplicit);
5177 = cast<CXXRecordDecl>(SourceRecordType->getDecl());
5179 const auto &Conversions =
5181 for (
auto I = Conversions.begin(), E = Conversions.end(); I != E; ++I) {
5184 if (isa<UsingShadowDecl>(D))
5185 D = cast<UsingShadowDecl>(D)->getTargetDecl();
5192 Conv = cast<CXXConversionDecl>(D);
5196 ConvTemplate, I.getPair(), ActingDC,
Initializer, DestType,
5197 CandidateSet, AllowExplicit, AllowExplicit);
5200 DestType, CandidateSet, AllowExplicit,
5218 bool HadMultipleCandidates = (CandidateSet.
size() > 1);
5220 if (isa<CXXConstructorDecl>(Function)) {
5226 HadMultipleCandidates);
5255 HadMultipleCandidates);
5278 if (Best->FinalConversion.First || Best->FinalConversion.Second ||
5279 Best->FinalConversion.Third) {
5282 ICS.
Standard = Best->FinalConversion;
5300 isa<CXXBoolLiteralExpr>(Init) &&
5301 !cast<CXXBoolLiteralExpr>(Init)->getValue() &&
5310 bool isAddressOf,
bool &isWeakAccess) {
5316 if (op->getOpcode() == UO_AddrOf)
5321 }
else if (
CastExpr *ce = dyn_cast<CastExpr>(e)) {
5322 switch (ce->getCastKind()) {
5325 case CK_LValueBitCast:
5329 case CK_ArrayToPointerDecay:
5332 case CK_NullToPointer:
5340 }
else if (isa<DeclRefExpr>(e)) {
5344 isWeakAccess =
true;
5348 VarDecl *var = dyn_cast<
VarDecl>(cast<DeclRefExpr>(e)->getDecl());
5362 }
else if (isa<ArraySubscriptExpr>(e)) {
5378 bool isWeakAccess =
false;
5382 if (S.
getLangOpts().ObjCAutoRefCount && isWeakAccess)
5388 << ((
unsigned) iik - 1)
5413 Expr *Initializer) {
5414 bool ArrayDecay =
false;
5419 ArgPointee = ArgArrayType->getElementType();
5431 bool ShouldCopy =
true;
5436 if (ArrayDecay || Initializer->
isGLValue()) {
5460 Expr *Initializer) {
5478 Expr *Initializer) {
5502 "cl_intel_device_side_avc_motion_estimation") &&
5504 if (DestType->isOCLIntelSubgroupAVCMcePayloadType() ||
5505 DestType->isOCLIntelSubgroupAVCMceResultType())
5521 bool TopLevelOfInitList,
5522 bool TreatUnavailableAsInvalid)
5525 TreatUnavailableAsInvalid);
5532 if (!DRE || !isa<FunctionDecl>(DRE->getDecl()))
5536 cast<FunctionDecl>(DRE->getDecl()));
5553 return isa<DecompositionDecl>(Entity.
getDecl());
5579 bool TopLevelOfInitList,
5580 bool TreatUnavailableAsInvalid) {
5587 for (
unsigned I = 0, E = Args.size(); I != E; ++I)
5588 if (Args[I]->getType()->isNonOverloadPlaceholderType()) {
5595 Args[I] = result.
get();
5616 Expr *Initializer =
nullptr;
5617 if (Args.size() == 1) {
5618 Initializer = Args[0];
5621 DestType, Initializer->
getType(),
5624 Args[0] = Initializer;
5626 if (!isa<InitListExpr>(Initializer))
5627 SourceType = Initializer->
getType();
5633 if (
InitListExpr *InitList = dyn_cast_or_null<InitListExpr>(Initializer)) {
5635 TreatUnavailableAsInvalid);
5647 if (Args.size() != 1)
5653 else if (isa<InitListExpr>(Args[0]))
5679 if (Initializer && isa<VariableArrayType>(DestAT)) {
5711 if (Initializer && isa<ConstantArrayType>(DestAT) &&
5729 Expr *OVEAsExpr = &OVE;
5731 TreatUnavailableAsInvalid);
5741 isa<CompoundLiteralExpr>(Initializer->
IgnoreParens()) &&
5759 *
this, TreatUnavailableAsInvalid);
5761 }
else if (DestAT->getElementType()->isCharType())
5773 bool allowObjCWritebackConversion = S.
getLangOpts().ObjCAutoRefCount &&
5783 if (allowObjCWritebackConversion &&
5810 DestType, DestType, *
this);
5819 TopLevelOfInitList);
5823 assert(Args.size() >= 1 &&
"Zero-argument case handled above");
5826 if (Args.size() > 1) {
5829 }
else if (isa<InitListExpr>(Args[0])) {
5839 bool NeedAtomicConversion =
false;
5843 Atomic->getValueType())) {
5844 DestType = Atomic->getValueType();
5845 NeedAtomicConversion =
true;
5850 TopLevelOfInitList);
5852 if (!
Failed() && NeedAtomicConversion)
5869 allowObjCWritebackConversion);
5877 bool ShouldCopy =
true;
5893 }
else if (ICS.
isBad()) {
5914 for (
auto &S : Steps)
5966 llvm_unreachable(
"Invalid EntityKind!");
5998 llvm_unreachable(
"missed an InitializedEntity kind?");
6030 llvm_unreachable(
"missed an InitializedEntity kind?");
6035 Expr *Initializer) {
6067 llvm_unreachable(
"missed an InitializedEntity kind?");
6094 bool IsExtraneousCopy) {
6101 Class = cast<CXXRecordDecl>(Record->getDecl());
6119 S, Loc, CurInitExpr, CandidateSet, T, Ctors, Best,
6130 ? diag::ext_rvalue_to_reference_temp_copy_no_viable
6131 : diag::err_temp_copy_no_viable)
6149 S.
Diag(Loc, diag::err_temp_copy_deleted)
6156 bool HadMultipleCandidates = CandidateSet.
size() > 1;
6165 if (IsExtraneousCopy) {
6176 for (
unsigned I = 1, N = Constructor->
getNumParams(); I != N; ++I) {
6179 diag::err_call_incomplete_argument))
6219 Best->Function->getParamDecl(0)->getType().getNonReferenceType(),
6226 HadMultipleCandidates,
6244 Expr *CurInitExpr) {
6263 S, Loc, CurInitExpr, CandidateSet, CurInitExpr->
getType(), Ctors, Best,
6275 Best->FoundDecl, Entity, Diag);
6296 void InitializationSequence::PrintInitLocationNote(
Sema &S,
6311 diag::note_method_return_type_change)
6335 return NumArgs != 1;
6347 bool &ConstructorInitRequiresZeroInit,
6348 bool IsListInitialization,
6349 bool IsStdInitListInitialization,
6352 unsigned NumArgs = Args.size();
6367 assert(Constructor->
getParent() &&
"No parent class for constructor.");
6384 bool AllowExplicitConv =
6392 Loc, ConstructorArgs,
6394 IsListInitialization))
6411 if (
auto *Shadow = dyn_cast<ConstructorUsingShadowDecl>(
6422 ConstructorArgs, ParenOrBraceRange, HadMultipleCandidates,
6423 IsListInitialization, IsStdInitListInitialization,
6424 ConstructorInitRequiresZeroInit);
6440 if (IsListInitialization)
6441 ParenOrBraceRange =
SourceRange(LBraceLoc, RBraceLoc);
6452 HadMultipleCandidates,
6453 IsListInitialization,
6454 IsStdInitListInitialization,
6455 ConstructorInitRequiresZeroInit,
6463 HadMultipleCandidates,
6464 IsListInitialization,
6465 IsStdInitListInitialization,
6466 ConstructorInitRequiresZeroInit,
6514 using LifetimeResult =
6515 llvm::PointerIntPair<const InitializedEntity *, 3, LifetimeKind>;
6528 return {Entity, LK_Extended};
6548 : LK_MemInitializer};
6553 return {Entity, LK_Extended};
6560 return {
nullptr, LK_FullExpression};
6566 return {
nullptr, LK_Return};
6571 return {
nullptr, LK_StmtExprResult};
6577 return {
nullptr, LK_New};
6585 return {
nullptr, LK_FullExpression};
6609 return {
nullptr, LK_FullExpression};
6613 return {
nullptr, LK_FullExpression};
6615 llvm_unreachable(
"unknown entity kind");
6621 RK_ReferenceBinding,
6624 RK_StdInitializerList,
6632 using Local =
Expr*;
6637 struct IndirectLocalPathEntry {
6648 const Decl *D =
nullptr;
6649 IndirectLocalPathEntry() {}
6650 IndirectLocalPathEntry(EntryKind K,
Expr *E) :
Kind(K), E(E) {}
6651 IndirectLocalPathEntry(EntryKind K,
Expr *E,
const Decl *D)
6652 :
Kind(K), E(E), D(D) {}
6657 struct RevertToOldSizeRAII {
6658 IndirectLocalPath &Path;
6659 unsigned OldSize = Path.size();
6660 RevertToOldSizeRAII(IndirectLocalPath &Path) : Path(Path) {}
6661 ~RevertToOldSizeRAII() { Path.resize(OldSize); }
6664 using LocalVisitor = llvm::function_ref<
bool(IndirectLocalPath &Path, Local L,
6670 if (E.Kind == IndirectLocalPathEntry::VarInit && E.D == VD)
6676 return llvm::any_of(Path, [=](IndirectLocalPathEntry E) {
6677 return E.Kind == IndirectLocalPathEntry::DefaultInit ||
6678 E.Kind == IndirectLocalPathEntry::VarInit;
6683 Expr *Init, LocalVisitor Visit,
6684 bool RevisitSubinits,
6685 bool EnableLifetimeWarnings);
6690 bool EnableLifetimeWarnings);
6694 return RD->hasAttr<T>();
6705 if (
const auto *ND = dyn_cast<NamespaceDecl>(DC))
6707 StringRef Name = II->getName();
6708 if (Name.size() >= 2 && Name.front() ==
'_' &&
6717 if (
auto *Conv = dyn_cast_or_null<CXXConversionDecl>(Callee))
6718 if (isRecordWithAttr<PointerAttr>(Conv->getConversionType()))
6729 return llvm::StringSwitch<bool>(Callee->
getName())
6730 .Cases(
"begin",
"rbegin",
"cbegin",
"crbegin",
true)
6731 .Cases(
"end",
"rend",
"cend",
"crend",
true)
6732 .Cases(
"c_str",
"data",
"get",
true)
6734 .Cases(
"find",
"equal_range",
"lower_bound",
"upper_bound",
true)
6739 return OO == OverloadedOperatorKind::OO_Subscript ||
6740 OO == OverloadedOperatorKind::OO_Star;
6742 return llvm::StringSwitch<bool>(Callee->
getName())
6743 .Cases(
"front",
"back",
"at",
"top",
"value",
true)
6755 if (!isRecordWithAttr<PointerAttr>(
QualType(RD->getTypeForDecl(), 0)) &&
6756 !isRecordWithAttr<OwnerAttr>(
QualType(RD->getTypeForDecl(), 0)))
6760 return llvm::StringSwitch<bool>(FD->
getName())
6761 .Cases(
"begin",
"rbegin",
"cbegin",
"crbegin",
true)
6762 .Cases(
"end",
"rend",
"cend",
"crend",
true)
6766 return llvm::StringSwitch<bool>(FD->
getName())
6767 .Cases(
"get",
"any_cast",
true)
6774 LocalVisitor Visit) {
6775 auto VisitPointerArg = [&](
const Decl *D,
Expr *Arg,
bool Value) {
6778 if (isa<MemberExpr>(Arg->IgnoreImpCasts()))
6782 for (
auto It = Path.rbegin(),
End = Path.rend(); It !=
End; ++It) {
6783 if (It->Kind == IndirectLocalPathEntry::GslReferenceInit)
6785 if (It->Kind == IndirectLocalPathEntry::GslPointerInit)
6790 Path.push_back({
Value ? IndirectLocalPathEntry::GslPointerInit
6791 : IndirectLocalPathEntry::GslReferenceInit,
6793 if (Arg->isGLValue())
6803 if (
auto *MCE = dyn_cast<CXXMemberCallExpr>(Call)) {
6804 const auto *MD = cast_or_null<CXXMethodDecl>(MCE->getDirectCallee());
6806 VisitPointerArg(MD, MCE->getImplicitObjectArgument(),
6807 !MD->getReturnType()->isReferenceType());
6809 }
else if (
auto *OCE = dyn_cast<CXXOperatorCallExpr>(Call)) {
6813 VisitPointerArg(Callee, OCE->getArg(0),
6816 }
else if (
auto *CE = dyn_cast<CallExpr>(Call)) {
6819 VisitPointerArg(Callee, CE->getArg(0),
6824 if (
auto *CCE = dyn_cast<CXXConstructExpr>(Call)) {
6825 const auto *Ctor = CCE->getConstructor();
6827 if (CCE->getNumArgs() > 0 && RD->
hasAttr<PointerAttr>())
6828 VisitPointerArg(Ctor->getParamDecl(0), CCE->getArgs()[0],
true);
6850 LocalVisitor Visit) {
6854 if (
auto *CE = dyn_cast<CallExpr>(Call)) {
6855 Callee = CE->getDirectCallee();
6856 Args = llvm::makeArrayRef(CE->getArgs(), CE->getNumArgs());
6858 auto *CCE = cast<CXXConstructExpr>(Call);
6859 Callee = CCE->getConstructor();
6860 Args = llvm::makeArrayRef(CCE->getArgs(), CCE->getNumArgs());
6865 Expr *ObjectArg =
nullptr;
6867 ObjectArg = Args[0];
6868 Args = Args.slice(1);
6869 }
else if (
auto *MCE = dyn_cast<CXXMemberCallExpr>(Call)) {
6870 ObjectArg = MCE->getImplicitObjectArgument();
6873 auto VisitLifetimeBoundArg = [&](
const Decl *D,
Expr *Arg) {
6874 Path.push_back({IndirectLocalPathEntry::LifetimeBoundCall, Arg, D});
6875 if (Arg->isGLValue())
6886 VisitLifetimeBoundArg(Callee, ObjectArg);
6888 for (
unsigned I = 0,
6889 N = std::min<unsigned>(Callee->
getNumParams(), Args.size());
6892 VisitLifetimeBoundArg(Callee->
getParamDecl(I), Args[I]);
6901 bool EnableLifetimeWarnings) {
6902 RevertToOldSizeRAII RAII(Path);
6909 if (
auto *FE = dyn_cast<FullExpr>(Init))
6910 Init = FE->getSubExpr();
6912 if (
InitListExpr *ILE = dyn_cast<InitListExpr>(Init)) {
6924 if (
CastExpr *CE = dyn_cast<CastExpr>(Init))
6925 if (CE->getSubExpr()->isGLValue())
6926 Init = CE->getSubExpr();
6930 if (
auto *ASE = dyn_cast<ArraySubscriptExpr>(Init)) {
6931 Init = ASE->getBase();
6933 if (ICE && ICE->getCastKind() == CK_ArrayToPointerDecay)
6934 Init = ICE->getSubExpr();
6939 EnableLifetimeWarnings);
6944 if (
auto *DIE = dyn_cast<CXXDefaultInitExpr>(Init)) {
6946 {IndirectLocalPathEntry::DefaultInit, DIE, DIE->getField()});
6947 Init = DIE->getExpr();
6949 }
while (Init != Old);
6951 if (
auto *MTE = dyn_cast<MaterializeTemporaryExpr>(Init)) {
6952 if (Visit(Path, Local(MTE), RK))
6954 EnableLifetimeWarnings);
6957 if (isa<CallExpr>(Init)) {
6958 if (EnableLifetimeWarnings)
6964 case Stmt::DeclRefExprClass: {
6967 auto *DRE = cast<DeclRefExpr>(Init);
6968 auto *VD = dyn_cast<
VarDecl>(DRE->getDecl());
6969 if (VD && VD->hasLocalStorage() &&
6970 !DRE->refersToEnclosingVariableOrCapture()) {
6971 if (!VD->getType()->isReferenceType()) {
6972 Visit(Path, Local(DRE), RK);
6973 }
else if (isa<ParmVarDecl>(DRE->getDecl())) {
6977 }
else if (VD->getInit() && !
isVarOnPath(Path, VD)) {
6978 Path.push_back({IndirectLocalPathEntry::VarInit, DRE, VD});
6980 RK_ReferenceBinding, Visit,
6981 EnableLifetimeWarnings);
6987 case Stmt::UnaryOperatorClass: {
6994 EnableLifetimeWarnings);
6998 case Stmt::OMPArraySectionExprClass: {
7000 cast<OMPArraySectionExpr>(Init)->getBase(),
7001 Visit,
true, EnableLifetimeWarnings);
7005 case Stmt::ConditionalOperatorClass:
7006 case Stmt::BinaryConditionalOperatorClass: {
7007 auto *
C = cast<AbstractConditionalOperator>(Init);
7008 if (!
C->getTrueExpr()->getType()->isVoidType())
7010 EnableLifetimeWarnings);
7011 if (!
C->getFalseExpr()->getType()->isVoidType())
7013 EnableLifetimeWarnings);
7027 Expr *Init, LocalVisitor Visit,
7028 bool RevisitSubinits,
7029 bool EnableLifetimeWarnings) {
7030 RevertToOldSizeRAII RAII(Path);
7038 if (
auto *DIE = dyn_cast<CXXDefaultInitExpr>(Init)) {
7039 Path.push_back({IndirectLocalPathEntry::DefaultInit, DIE, DIE->getField()});
7040 Init = DIE->getExpr();
7043 if (
auto *FE = dyn_cast<FullExpr>(Init))
7044 Init = FE->getSubExpr();
7050 Init = BTE->getSubExpr();
7055 if (
auto *CE = dyn_cast<CastExpr>(Init)) {
7056 switch (CE->getCastKind()) {
7057 case CK_LValueToRValue:
7060 Path.push_back({IndirectLocalPathEntry::LValToRVal, CE});
7062 Path, Init, RK_ReferenceBinding,
7063 [&](IndirectLocalPath &Path, Local L,
ReferenceKind RK) ->
bool {
7064 if (
auto *DRE = dyn_cast<DeclRefExpr>(L)) {
7065 auto *VD = dyn_cast<
VarDecl>(DRE->getDecl());
7066 if (VD && VD->getType().isConstQualified() && VD->getInit() &&
7068 Path.push_back({IndirectLocalPathEntry::VarInit, DRE, VD});
7070 EnableLifetimeWarnings);
7072 }
else if (
auto *MTE = dyn_cast<MaterializeTemporaryExpr>(L)) {
7073 if (MTE->getType().isConstQualified())
7075 true, EnableLifetimeWarnings);
7078 }, EnableLifetimeWarnings);
7086 case CK_BaseToDerived:
7087 case CK_DerivedToBase:
7088 case CK_UncheckedDerivedToBase:
7091 case CK_UserDefinedConversion:
7092 case CK_ConstructorConversion:
7093 case CK_IntegralToPointer:
7094 case CK_PointerToIntegral:
7095 case CK_VectorSplat:
7096 case CK_IntegralCast:
7097 case CK_CPointerToObjCPointerCast:
7098 case CK_BlockPointerToObjCPointerCast:
7099 case CK_AnyPointerToBlockPointerCast:
7100 case CK_AddressSpaceConversion:
7103 case CK_ArrayToPointerDecay:
7106 Path.push_back({IndirectLocalPathEntry::AddressOf, CE});
7108 RK_ReferenceBinding, Visit,
7109 EnableLifetimeWarnings);
7115 Init = CE->getSubExpr();
7117 }
while (Old != Init);
7122 if (
auto *ILE = dyn_cast<CXXStdInitializerListExpr>(Init))
7124 RK_StdInitializerList, Visit,
7125 EnableLifetimeWarnings);
7127 if (
InitListExpr *ILE = dyn_cast<InitListExpr>(Init)) {
7131 if (!RevisitSubinits)
7137 EnableLifetimeWarnings);
7140 for (
unsigned I = 0, N = ILE->
getNumInits(); I != N; ++I)
7143 EnableLifetimeWarnings);
7148 assert(RD->isAggregate() &&
"aggregate init on non-aggregate");
7156 RK_ReferenceBinding, Visit,
7157 EnableLifetimeWarnings);
7160 for (; Index < RD->getNumBases() && Index < ILE->
getNumInits(); ++Index)
7163 EnableLifetimeWarnings);
7164 for (
const auto *I : RD->fields()) {
7167 if (I->isUnnamedBitfield())
7170 if (I->getType()->isReferenceType())
7172 RK_ReferenceBinding, Visit,
7173 EnableLifetimeWarnings);
7180 EnableLifetimeWarnings);
7190 if (
auto *
LE = dyn_cast<LambdaExpr>(Init)) {
7191 for (
Expr *E :
LE->capture_inits()) {
7196 Visit, EnableLifetimeWarnings);
7199 EnableLifetimeWarnings);
7203 if (isa<CallExpr>(Init) || isa<CXXConstructExpr>(Init)) {
7204 if (EnableLifetimeWarnings)
7210 case Stmt::UnaryOperatorClass: {
7211 auto *UO = cast<UnaryOperator>(Init);
7214 if (UO->getOpcode() == UO_AddrOf) {
7218 if (isa<MaterializeTemporaryExpr>(UO->getSubExpr()))
7221 Path.push_back({IndirectLocalPathEntry::AddressOf, UO});
7223 RK_ReferenceBinding, Visit,
7224 EnableLifetimeWarnings);
7229 case Stmt::BinaryOperatorClass: {
7231 auto *BO = cast<BinaryOperator>(Init);
7233 if (!BO->getType()->isPointerType() || (BOK != BO_Add && BOK != BO_Sub))
7236 if (BO->getLHS()->getType()->isPointerType())
7238 EnableLifetimeWarnings);
7239 else if (BO->getRHS()->getType()->isPointerType())
7241 EnableLifetimeWarnings);
7245 case Stmt::ConditionalOperatorClass:
7246 case Stmt::BinaryConditionalOperatorClass: {
7247 auto *
C = cast<AbstractConditionalOperator>(Init);
7250 if (!
C->getTrueExpr()->getType()->isVoidType())
7252 EnableLifetimeWarnings);
7253 if (!
C->getFalseExpr()->getType()->isVoidType())
7255 EnableLifetimeWarnings);
7259 case Stmt::BlockExprClass:
7260 if (cast<BlockExpr>(Init)->getBlockDecl()->hasCaptures()) {
7262 Visit(Path, Local(cast<BlockExpr>(Init)), RK_ReferenceBinding);
7266 case Stmt::AddrLabelExprClass:
7268 Visit(Path, Local(cast<AddrLabelExpr>(Init)), RK_ReferenceBinding);
7279 for (
auto Elem : Path) {
7280 if (Elem.Kind != IndirectLocalPathEntry::DefaultInit)
7289 for (
unsigned N = Path.size(); I != N; ++I) {
7290 switch (Path[I].Kind) {
7291 case IndirectLocalPathEntry::AddressOf:
7292 case IndirectLocalPathEntry::LValToRVal:
7293 case IndirectLocalPathEntry::LifetimeBoundCall:
7294 case IndirectLocalPathEntry::GslReferenceInit:
7295 case IndirectLocalPathEntry::GslPointerInit:
7300 case IndirectLocalPathEntry::VarInit:
7301 if (cast<VarDecl>(Path[I].D)->isImplicit())
7304 case IndirectLocalPathEntry::DefaultInit:
7305 return Path[I].E->getSourceRange();
7312 for (
auto It = Path.rbegin(),
End = Path.rend(); It !=
End; ++It) {
7313 if (It->Kind == IndirectLocalPathEntry::VarInit)
7315 if (It->Kind == IndirectLocalPathEntry::AddressOf)
7317 return It->Kind == IndirectLocalPathEntry::GslPointerInit ||
7318 It->Kind == IndirectLocalPathEntry::GslReferenceInit;
7331 if (LK == LK_FullExpression)
7334 auto TemporaryVisitor = [&](IndirectLocalPath &Path, Local L,
7341 bool IsGslPtrInitWithGslTempOwner =
false;
7342 bool IsLocalGslOwner =
false;
7344 if (isa<DeclRefExpr>(L)) {
7350 IsLocalGslOwner = isRecordWithAttr<OwnerAttr>(L->getType());
7355 isRecordWithAttr<OwnerAttr>(MTE->getType());
7359 if (!IsGslPtrInitWithGslTempOwner)
7365 case LK_FullExpression:
7366 llvm_unreachable(
"already handled this");
7378 if (IsGslPtrInitWithGslTempOwner && DiagLoc.
isValid()) {
7379 Diag(DiagLoc, diag::warn_dangling_lifetime_pointer) << DiagRange;
7387 MTE->setExtendingDecl(ExtendingEntity->
getDecl(),
7400 Diag(DiagLoc, diag::warn_unsupported_lifetime_extension)
7409 Diag(DiagLoc, diag::warn_dangling_variable)
7417 case LK_MemInitializer: {
7418 if (isa<MaterializeTemporaryExpr>(L)) {
7422 if (
auto *ExtendingDecl =
7423 ExtendingEntity ? ExtendingEntity->
getDecl() :
nullptr) {
7424 if (IsGslPtrInitWithGslTempOwner) {
7425 Diag(DiagLoc, diag::warn_dangling_lifetime_pointer_member)
7426 << ExtendingDecl << DiagRange;
7427 Diag(ExtendingDecl->getLocation(),
7428 diag::note_ref_or_ptr_member_declared_here)
7432 bool IsSubobjectMember = ExtendingEntity != &Entity;
7434 ? diag::err_dangling_member
7435 : diag::warn_dangling_member)
7436 << ExtendingDecl << IsSubobjectMember << RK << DiagRange;
7441 Path.back().Kind != IndirectLocalPathEntry::DefaultInit) {
7442 Diag(ExtendingDecl->getLocation(),
7443 diag::note_lifetime_extending_member_declared_here)
7444 << RK << IsSubobjectMember;
7468 auto *VD = DRE ? dyn_cast<
VarDecl>(DRE->getDecl()) :
nullptr;
7476 ExtendingEntity ? ExtendingEntity->
getDecl() :
nullptr) {
7478 Diag(DiagLoc, IsPointer ? diag::warn_init_ptr_member_to_parameter_addr
7479 : diag::warn_bind_ref_member_to_parameter)
7480 << Member << VD << isa<ParmVarDecl>(VD) << DiagRange;
7481 Diag(Member->getLocation(),
7482 diag::note_ref_or_ptr_member_declared_here)
7483 << (
unsigned)IsPointer;
7490 if (isa<MaterializeTemporaryExpr>(L)) {
7491 if (IsGslPtrInitWithGslTempOwner)
7492 Diag(DiagLoc, diag::warn_dangling_lifetime_pointer) << DiagRange;
7494 Diag(DiagLoc, RK == RK_ReferenceBinding
7495 ? diag::warn_new_dangling_reference
7496 : diag::warn_new_dangling_initializer_list)
7505 case LK_StmtExprResult:
7506 if (
auto *DRE = dyn_cast<DeclRefExpr>(L)) {
7509 if (LK == LK_StmtExprResult)
7511 Diag(DiagLoc, diag::warn_ret_stack_addr_ref)
7513 << isa<ParmVarDecl>(DRE->getDecl()) << DiagRange;
7514 }
else if (isa<BlockExpr>(L)) {
7515 Diag(DiagLoc, diag::err_ret_local_block) << DiagRange;
7516 }
else if (isa<AddrLabelExpr>(L)) {
7519 if (LK == LK_StmtExprResult)
7521 Diag(DiagLoc, diag::warn_ret_addr_label) << DiagRange;
7523 Diag(DiagLoc, diag::warn_ret_local_temp_addr_ref)
7529 for (
unsigned I = 0; I != Path.size(); ++I) {
7530 auto Elem = Path[I];
7532 switch (Elem.Kind) {
7533 case IndirectLocalPathEntry::AddressOf:
7534 case IndirectLocalPathEntry::LValToRVal:
7539 case IndirectLocalPathEntry::LifetimeBoundCall:
7540 case IndirectLocalPathEntry::GslPointerInit:
7541 case IndirectLocalPathEntry::GslReferenceInit:
7545 case IndirectLocalPathEntry::DefaultInit: {
7546 auto *FD = cast<FieldDecl>(Elem.D);
7547 Diag(FD->getLocation(), diag::note_init_with_default_member_initalizer)
7552 case IndirectLocalPathEntry::VarInit:
7553 const VarDecl *VD = cast<VarDecl>(Elem.D);
7567 bool EnableLifetimeWarnings = !getDiagnostics().isIgnored(
7573 EnableLifetimeWarnings);
7576 EnableLifetimeWarnings);
7583 const Expr *PostInit);
7587 bool IsReturnStmt) {
7598 unsigned DiagID = 0;
7628 if (VD->
hasAttr<BlocksAttr>())
7641 if (isa<ParmVarDecl>(VD))
7642 DiagID = diag::warn_redundant_move_on_return;
7644 DiagID = diag::warn_pessimizing_move_on_return;
7646 DiagID = diag::warn_pessimizing_move_on_initialization;
7688 if (UO->getOpcode() == UO_Deref &&
7689 UO->getSubExpr()->IgnoreParenCasts()->
7692 S.
PDiag(diag::warn_binding_null_to_reference)
7693 << UO->getSubExpr()->getSourceRange());
7699 bool BoundToLvalueReference) {
7700 auto MTE =
new (Context)
7709 Cleanup.setExprNeedsCleanups(
false);
7718 if (!E->
isRValue() || !getLangOpts().CPlusPlus11)
7725 if (RequireCompleteType(E->
getExprLoc(), T, diag::err_incomplete_type))
7728 return CreateMaterializeTemporaryExpr(E->
getType(), E,
false);
7740 if (!PointeeTy.isNull() &&
7741 PointeeTy.getAddressSpace() != ExprPointeeTy.getAddressSpace())
7742 CK = CK_AddressSpaceConversion;
7744 CK = CK_AddressSpaceConversion;
7747 return ImpCastExprToType(E, Ty, CK, VK,
nullptr, CCK);
7759 if (!ZeroInitializationFixit.empty()) {
7760 unsigned DiagID = diag::err_default_init_const;
7762 if (S.
getLangOpts().MSVCCompat && D->hasAttr<SelectAnyAttr>())
7763 DiagID = diag::ext_default_init_const;
7772 ZeroInitializationFixit);
7791 if (isa<InitListExpr>((
Expr *)Args[0])) {
7795 if (
auto *DD = dyn_cast_or_null<DeclaratorDecl>(Entity.
getDecl())) {
7797 TypeLoc TL = TInfo->getTypeLoc();
7800 Brackets = ArrayLoc.getBracketsRange();
7807 ArrayT->getSizeModifier(),
7808 ArrayT->getIndexTypeCVRQualifiers(),
7832 Args.size() == 1 && isa<InitListExpr>(Args[0]) &&
7837 Expr *Init = Args[0];
7838 S.
Diag(Init->
getBeginLoc(), diag::warn_cxx98_compat_reference_list_init)
7850 S.
Diag(Args[0]->getBeginLoc(), diag::err_opencl_atomic_init)
7870 switch (Steps.front().Kind) {
7903 assert(Args.size() == 1);
7921 CurInit.
get() && isa<InitListExpr>(CurInit.
get()));
7926 auto checkAbstractType = [&](
QualType T) ->
bool {
7931 diag::err_allocation_of_abstract_type);
7936 bool ConstructorInitRequiresZeroInit =
false;
7967 SourceType,
Step->
Type, CurInit.
get()->getBeginLoc(),
7968 CurInit.
get()->getSourceRange(), &BasePath, IgnoreBaseAccess))
7979 CurInit.
get(), &BasePath, VK);
7993 if (CurInit.
get()->getType()->isFunctionProtoType()) {
7994 if (
auto *DRE = dyn_cast<DeclRefExpr>(CurInit.
get()->IgnoreParens())) {
7995 if (
auto *FD = dyn_cast<FunctionDecl>(DRE->getDecl())) {
7997 DRE->getBeginLoc()))
8008 assert(CurInit.
get()->isRValue() &&
"not a temporary");
8054 bool CreatedObject =
false;
8065 Loc, ConstructorArgs))
8070 FoundFn, Constructor,
8072 HadMultipleCandidates,
8086 CastKind = CK_ConstructorConversion;
8087 CreatedObject =
true;
8097 HadMultipleCandidates);
8101 CastKind = CK_UserDefinedConversion;
8102 CreatedObject = Conversion->getReturnType()->isRecordType();
8105 if (CreatedObject && checkAbstractType(CurInit.
get()->getType()))
8110 CurInit.
get()->getValueKind());
8126 S.
PDiag(diag::err_access_dtor_temp) << T);
8149 assert(CurInit.
get()->isRValue() &&
"cannot convert glvalue to atomic");
8157 if (
const auto *FromPtrType =
8160 if (FromPtrType->getPointeeType()->hasAttr(attr::NoDeref) &&
8161 !ToPtrType->getPointeeType()->hasAttr(attr::NoDeref)) {
8162 S.
Diag(CurInit.
get()->getExprLoc(),
8163 diag::warn_noderef_to_dereferenceable_pointer)
8164 << CurInit.
get()->getSourceRange();
8182 CurInit = CurInitExprRes;
8203 InitListChecker PerformInitList(S, InitEntity,
8204 InitList, Ty,
false,
8206 if (PerformInitList.HadError())
8214 if ((*ResultType)->isRValueReferenceType())
8216 else if ((*ResultType)->isLValueReferenceType())
8223 PerformInitList.getFullyStructuredList();
8227 : StructuredInitList;
8244 assert(Args.size() == 1 &&
"expected a single argument for list init");
8246 S.
Diag(InitList->getExprLoc(), diag::warn_cxx98_compat_ctor_list_init)
8247 << InitList->getSourceRange();
8248 MultiExprArg Arg(InitList->getInits(), InitList->getNumInits());
8252 ConstructorInitRequiresZeroInit,
8255 InitList->getLBraceLoc(),
8256 InitList->getRBraceLoc());
8261 CurInit = cast<InitListExpr>(CurInit.
get())->getInit(0);
8290 bool IsStdInitListInit =
8297 S, UseTemporary ? TempEntity : Entity, Kind,
8299 ConstructorInitRequiresZeroInit,
8310 if (NextStep != StepEnd &&
8315 ConstructorInitRequiresZeroInit =
true;
8355 CurInit = CurInitExprRes;
8360 InitialCurInit.
get(),
8363 PrintInitLocationNote(S, Entity);
8365 }
else if (Complained)
8366 PrintInitLocationNote(S, Entity);
8379 CK_ObjCObjectLValueCast,
8380 CurInit.
get()->getValueKind());
8392 ArrayLoopCommonExprs.push_back(BaseExpr);
8397 assert(!ArrayLoopCommonExprs.empty() &&
8398 "mismatched SK_ArrayLoopIndex and SK_ArrayLoopInit");
8399 Expr *Common = ArrayLoopCommonExprs.pop_back_val();
8410 << CurInit.
get()->getSourceRange();
8422 IncompleteDest->getElementType(),
8423 ConstantSource->getSize(),
8424 ConstantSource->getSizeExpr(),
8435 << CurInit.
get()->getSourceRange();
8453 S.
Diag(CurInit.get()->getExprLoc(),
8454 diag::warn_cxx98_compat_initializer_list_init)
8455 << CurInit.get()->getSourceRange();
8459 CurInit.get()->getType(), CurInit.get(),
8489 "Sampler initialization on non-sampler type.");
8491 QualType SourceType = Init->getType();
8498 }
else if (
const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Init)) {
8499 auto Var = cast<VarDecl>(DRE->getDecl());
8502 if (!Var->hasGlobalStorage()) {
8504 CK_LValueToRValue, Init,
8514 if (!Var->getInit() || !isa<ImplicitCastExpr>(Var->getInit()))
8516 Init = cast<ImplicitCastExpr>(
const_cast<Expr*
>(
8517 Var->getInit()))->getSubExpr();
8518 SourceType = Init->getType();
8525 if (!Init->isConstantInitializer(S.
Context,
false))
8536 Init->EvaluateAsInt(EVResult, S.
Context);
8538 const uint64_t SamplerValue = Result.getLimitedValue();
8545 unsigned AddressingMode = (0x0E & SamplerValue) >> 1;
8546 unsigned FilterMode = (0x30 & SamplerValue) >> 4;
8547 if (FilterMode != 1 && FilterMode != 2 &&
8549 "cl_intel_device_side_avc_motion_estimation"))
8551 diag::warn_sampler_initializer_invalid_bits)
8553 if (AddressingMode > 4)
8555 diag::warn_sampler_initializer_invalid_bits)
8556 <<
"Addressing Mode";
8562 CK_IntToOCLSampler);
8568 "Wrong type for initialization of OpenCL opaque type.");
8571 CK_ZeroToOCLOpaqueType,
8572 CurInit.get()->getValueKind());
8580 if (
auto *Init = CurInit.
get())
8585 cast<FieldDecl>(Entity.
getDecl())->isBitField())
8587 cast<FieldDecl>(Entity.
getDecl()),
8591 if (
const Expr *E = CurInit.
get()) {
8604 S.
Diag(Loc, diag::err_reference_without_init)
8613 for (
const auto *FI : RD->
fields()) {
8614 if (FI->isUnnamedBitfield())
8618 S.
Diag(Loc, diag::note_value_initialization_here) << RD;
8623 for (
const auto &BI : RD->
bases()) {
8625 S.
Diag(Loc, diag::note_value_initialization_here) << RD;
8680 if (
auto *D = Entity.
getDecl())
8681 Loc = D->getLocation();
8682 S.
Diag(Loc, diag::note_in_reference_temporary_list_initializer) << T;
8686 InitListChecker DiagnoseInitList(S, Entity, InitList, DestType,
8689 assert(DiagnoseInitList.HadError() &&
8690 "Inconsistent init list check result.");
8703 if (Args.size() == 1) {
8705 if (List && List->getNumInits() == 1)
8706 OnlyArg = List->getInit(0);
8725 assert(Diagnosed &&
"couldn't find uninitialized reference to diagnose");
8729 <<
SourceRange(Args.front()->getBeginLoc(), Args.back()->getEndLoc());
8733 << 1 << Entity.
getType() << Args[0]->getSourceRange();
8746 S.
Diag(Kind.
getLocation(), diag::err_array_init_narrow_string_into_wchar);
8749 S.
Diag(Kind.
getLocation(), diag::err_array_init_wide_string_into_char);
8753 diag::err_array_init_incompat_wide_string_into_wchar);
8757 diag::err_array_init_plain_string_into_char8_t);
8758 S.
Diag(Args.front()->getBeginLoc(),
8759 diag::note_array_init_plain_string_into_char8_t)
8764 diag::err_array_init_utf8_string_into_char)
8771 ? diag::err_array_init_different_type
8772 : diag::err_array_init_non_constant_array))
8775 << Args[0]->getSourceRange();
8793 auto *FD = cast<FunctionDecl>(cast<DeclRefExpr>(OnlyArg)->getDecl());
8801 switch (FailedOverloadResult) {
8804 FailedCandidateSet.NoteCandidates(
8808 ? (S.
PDiag(diag::err_typecheck_ambiguous_condition)
8809 << OnlyArg->
getType() << DestType
8810 << Args[0]->getSourceRange())
8811 : (S.
PDiag(diag::err_ref_init_ambiguous)
8812 << DestType << OnlyArg->
getType()
8813 << Args[0]->getSourceRange())),
8821 diag::err_typecheck_nonviable_condition_incomplete,
8822 OnlyArg->
getType(), Args[0]->getSourceRange()))
8825 << OnlyArg->
getType() << Args[0]->getSourceRange()
8828 FailedCandidateSet.NoteCandidates(S, Args, Cands);
8834 << Args[0]->getSourceRange();
8837 = FailedCandidateSet.BestViableFunction(S, Kind.
getLocation(), Best);
8841 llvm_unreachable(
"Inconsistent overload resolution?");
8847 llvm_unreachable(
"Conversion did not fail!");
8852 if (isa<InitListExpr>(Args[0])) {
8854 diag::err_lvalue_reference_bind_to_initlist)
8857 << Args[0]->getSourceRange();
8865 ? diag::err_lvalue_reference_bind_to_temporary
8866 : diag::err_lvalue_reference_bind_to_unrelated)
8870 << Args[0]->getSourceRange();
8875 FieldDecl *BitField = Args[0]->getSourceBitField();
8879 << (BitField !=
nullptr)
8880 << Args[0]->getSourceRange();
8887 S.
Diag(Kind.
getLocation(), diag::err_reference_bind_to_vector_element)
8889 << Args[0]->getSourceRange();
8895 << Args[0]->getSourceRange();
8899 S.
Diag(Kind.
getLocation(), diag::err_reference_bind_temporary_addrspace)
8912 << NonRefType << SourceType << 1
8916 << NonRefType << SourceType << 0
8923 << NonRefType << SourceType << 2
8934 << Args[0]->getSourceRange();
8945 << Args[0]->getSourceRange();
8963 assert(Args.size() > 1 &&
"Expected multiple initializers!");
8964 R =
SourceRange(Args.front()->getEndLoc(), Args.back()->getEndLoc());
8969 S.
Diag(Kind.
getLocation(), diag::err_builtin_func_cast_more_than_one_arg)
8979 << 0 << Entity.
getType() << Args[0]->getSourceRange();
8997 SourceRange(Args.front()->getBeginLoc(), Args.back()->getEndLoc());
9000 assert(Args.size() == 1 &&
9001 "List construction from other than 1 argument.");
9003 Args =
MultiExprArg(InitList->getInits(), InitList->getNumInits());
9008 switch (FailedOverloadResult) {
9010 FailedCandidateSet.NoteCandidates(
9012 S.
PDiag(diag::err_ovl_ambiguous_init)
9013 << DestType << ArgsRange),
9030 InheritedFrom = Inherited.getShadowDecl()->getNominatedBaseClass();
9033 << (InheritedFrom ? 2 : Constructor->
isImplicit() ? 1 : 0)
9046 << (InheritedFrom ? 2 : Constructor->
isImplicit() ? 1 : 0)
9052 diag::note_member_declared_at);
9056 S.
Diag(Record->getDecl()->getLocation(),
9057 diag::note_previous_decl)
9063 FailedCandidateSet.NoteCandidates(
9066 S.
PDiag(diag::err_ovl_no_viable_function_in_init)
9067 << DestType << ArgsRange),
9074 = FailedCandidateSet.BestViableFunction(S, Kind.
getLocation(), Best);
9077 << DestType << ArgsRange;
9078 llvm_unreachable(
"Inconsistent overload resolution?");
9088 << DestType << ArgsRange;
9091 << DestType << ArgsRange;
9098 llvm_unreachable(
"Conversion did not fail!");
9126 diag::err_init_incomplete_type);
9146 = FailedCandidateSet.BestViableFunction(S, Kind.
getLocation(), Best);
9148 assert(Ovl ==
OR_Success &&
"Inconsistent overload resolution");
9151 diag::note_explicit_ctor_deduction_guide_here) <<
false;
9156 PrintInitLocationNote(S, Entity);
9163 OS <<
"Failed sequence: ";
9166 OS <<
"too many initializers for reference";
9170 OS <<
"parenthesized list init for reference";
9174 OS <<
"array requires initializer list";
9178 OS <<
"address of unaddressable function was taken";
9182 OS <<
"array requires initializer list or string literal";
9186 OS <<
"array requires initializer list or wide string literal";
9190 OS <<
"narrow string into wide char array";
9194 OS <<
"wide string into char array";
9198 OS <<
"incompatible wide string into wide char array";
9202 OS <<
"plain string literal into char8_t array";
9206 OS <<
"u8 string literal into char array";
9210 OS <<
"array type mismatch";
9214 OS <<
"non-constant array initializer";
9218 OS <<
"address of overloaded function failed";
9222 OS <<
"overload resolution for reference initialization failed";
9226 OS <<
"non-const lvalue reference bound to temporary";
9230 OS <<
"non-const lvalue reference bound to bit-field";
9234 OS <<
"non-const lvalue reference bound to vector element";
9238 OS <<
"non-const lvalue reference bound to unrelated type";
9242 OS <<
"rvalue reference bound to an lvalue";
9246 OS <<
"reference initialization drops qualifiers";
9250 OS <<
"reference with mismatching address space bound to temporary";
9254 OS <<
"reference initialization failed";
9258 OS <<
"conversion failed";
9262 OS <<
"conversion from property failed";
9266 OS <<
"too many initializers for scalar";
9270 OS <<
"parenthesized list init for reference";
9274 OS <<
"referencing binding to initializer list";
9278 OS <<
"initializer list for non-aggregate, non-scalar type";
9282 OS <<
"overloading failed for user-defined conversion";
9286 OS <<
"constructor overloading failed";
9290 OS <<
"default initialization of a const variable";
9294 OS <<
"initialization of incomplete type";
9298 OS <<
"list initialization checker failure";
9302 OS <<
"variable length array has an initializer";
9306 OS <<
"initializer expression isn't contextually valid";
9310 OS <<
"list constructor overloading failed";
9314 OS <<
"list copy initialization chose explicit constructor";
9322 OS <<
"Dependent sequence\n";
9326 OS <<
"Normal sequence: ";
9337 OS <<
"resolve address of overloaded function";
9341 OS <<
"derived-to-base (rvalue)";
9345 OS <<
"derived-to-base (xvalue)";
9349 OS <<
"derived-to-base (lvalue)";
9353 OS <<
"bind reference to lvalue";
9357 OS <<
"bind reference to a temporary";
9361 OS <<
"final copy in class direct-initialization";
9365 OS <<
"extraneous C++03 copy to temporary";
9369 OS <<
"user-defined conversion via " << *S->Function.Function;
9373 OS <<
"qualification conversion (rvalue)";
9377 OS <<
"qualification conversion (xvalue)";
9381 OS <<
"qualification conversion (lvalue)";
9385 OS <<
"non-atomic-to-atomic conversion";
9389 OS <<
"implicit conversion sequence (";
9395 OS <<
"implicit conversion sequence with narrowing prohibited (";
9401 OS <<
"list aggregate initialization";
9405 OS <<
"unwrap reference initializer list";
9409 OS <<
"rewrap reference initializer list";
9413 OS <<
"constructor initialization";
9417 OS <<
"list initialization via constructor";
9421 OS <<
"zero initialization";
9425 OS <<
"C assignment";
9429 OS <<
"string initialization";
9433 OS <<
"Objective-C object conversion";
9437 OS <<
"indexing for array initialization loop";
9441 OS <<
"array initialization loop";
9445 OS <<
"array initialization";
9449 OS <<
"array initialization (GNU extension)";
9453 OS <<
"parenthesized array initialization";
9457 OS <<
"pass by indirect copy and restore";
9461 OS <<
"pass by indirect restore";
9465 OS <<
"Objective-C object retension";
9469 OS <<
"std::initializer_list from initializer list";
9473 OS <<
"list initialization from std::initializer_list";
9477 OS <<
"OpenCL sampler_t from integer constant";
9481 OS <<
"OpenCL opaque type from zero";
9485 OS <<
" [" << S->Type.getAsString() <<
']';
9496 return L.CPlusPlus11 &&
9504 const Expr *PostInit) {
9534 ? diag::ext_init_list_type_narrowing
9535 : diag::warn_init_list_type_narrowing)
9545 ? diag::ext_init_list_constant_narrowing
9546 : diag::warn_init_list_constant_narrowing)
9556 ? diag::ext_init_list_variable_narrowing
9557 : diag::warn_init_list_variable_narrowing)
9565 llvm::raw_svector_ostream OS(StaticCast);
9566 OS <<
"static_cast<";
9573 OS << *TT->getDecl();
9582 S.
Diag(PostInit->
getBeginLoc(), diag::note_init_list_narrowing_silence)
9599 assert(InitE &&
"No initialization expression");
9604 return !Seq.Failed();
9611 bool TopLevelOfInitList,
9612 bool AllowExplicit) {
9617 assert(InitE &&
"No initialization expression?");
9627 const bool ShouldTrackCopy =
9629 if (ShouldTrackCopy) {
9630 if (llvm::find(CurrentParameterCopyTypes, Entity.
getType()) !=
9631 CurrentParameterCopyTypes.end()) {
9632 Seq.SetOverloadFailure(
9638 const auto LastStep = Seq.step_end() - 1;
9639 assert(LastStep->Kind ==
9641 const FunctionDecl *Function = LastStep->Function.Function;
9643 llvm::find_if(Seq.getFailedCandidateSet(),
9645 return Candidate.Viable &&
9646 Candidate.Function == Function &&
9647 Candidate.Conversions.size() > 0;
9649 if (Candidate != Seq.getFailedCandidateSet().end() &&
9651 Candidate->Viable =
false;
9658 CurrentParameterCopyTypes.push_back(Entity.
getType());
9663 if (ShouldTrackCopy)
9664 CurrentParameterCopyTypes.pop_back();
9672 auto NotSpecialization = [&] (
const CXXRecordDecl *Candidate) {
9676 return !(NotSpecialization(RD) && RD->
forallBases(NotSpecialization));
9684 assert(DeducedTST &&
"not a deduced template specialization type");
9695 diag::err_deduced_non_class_template_specialization_type)
9698 Diag(TD->getLocation(), diag::note_template_decl_here);
9705 diag::warn_cxx14_compat_class_template_argument_deduction)
9725 LookupResult Guides(*
this, NameInfo, LookupOrdinaryName);
9726 LookupQualifiedName(Guides, Template->getDeclContext());
9730 Guides.suppressDiagnostics();
9735 ? dyn_cast<InitListExpr>(Inits[0])
9751 bool HasAnyDeductionGuide =
false;
9754 auto tryToResolveOverload =
9757 HasAnyDeductionGuide =
false;
9759 for (
auto I = Guides.begin(), E = Guides.end(); I != E; ++I) {
9765 auto *GD = dyn_cast_or_null<CXXDeductionGuideDecl>(
9766 TD ? TD->getTemplatedDecl() : dyn_cast<
FunctionDecl>(D));
9770 if (!GD->isImplicit())
9771 HasAnyDeductionGuide =
true;
9778 if (!AllowExplicit) {
9785 if (GD->getMinRequiredArguments() > 1 ||
9786 (GD->getNumParams() == 0 && !GD->isVariadic()))
9793 if (OnlyListConstructors && !isInitListConstructor(GD))
9808 bool SuppressUserConversions = Kind.
isCopyInit();
9811 AddTemplateOverloadCandidate(TD, I.getPair(),
nullptr,
9812 Inits, Candidates, SuppressUserConversions,
9816 AddOverloadCandidate(GD, I.getPair(),
Inits, Candidates,
9817 SuppressUserConversions,
9818 false, AllowExplicit);
9820 return Candidates.BestViableFunction(*
this, Kind.
getLocation(), Best);
9828 bool TryListConstructors =
true;
9834 auto *FD = dyn_cast<
FunctionDecl>(D->getUnderlyingDecl());
9835 if (FD && FD->getMinRequiredArguments() == 0) {
9836 TryListConstructors =
false;
9848 if (!isa<InitListExpr>(E) && RD &&
9851 TryListConstructors =
false;
9854 if (TryListConstructors)
9855 Result = tryToResolveOverload(
true);
9864 Result = tryToResolveOverload(
false);
9871 Candidates.NoteCandidates(
9874 PDiag(diag::err_deduced_class_template_ctor_ambiguous)
9881 cast<ClassTemplateDecl>(Template)->getTemplatedDecl();
9884 Candidates.NoteCandidates(
9887 PDiag(Complete ? diag::err_deduced_class_template_ctor_no_viable
9888 : diag::err_deduced_class_template_incomplete)
9897 NoteDeletedFunction(Best->Function);
9906 cast<CXXDeductionGuideDecl>(Best->Function)->isExplicit()) {
9907 bool IsDeductionGuide = !Best->Function->isImplicit();
9910 Diag(Best->Function->getLocation(),
9911 diag::note_explicit_ctor_deduction_guide_here)
9912 << IsDeductionGuide;
9918 DiagnoseUseOfDecl(Best->Function, Kind.
getLocation());
9919 MarkFunctionReferenced(Kind.
getLocation(), Best->Function);
9927 SubstAutoType(TSInfo->
getType(), Best->Function->getReturnType());
9929 diag::warn_cxx14_compat_class_template_argument_deduction)
9934 if (!HasAnyDeductionGuide) {
9936 diag::warn_ctad_maybe_unsupported)
9938 Diag(Template->getLocation(), diag::note_suppress_ctad_maybe_unsupported);
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.
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.
PointerType - C99 6.7.5.1 - Pointer Declarators.
SourceLocation getBeginLoc() const LLVM_READONLY
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.
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.
Stmt - This represents one statement.
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)
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee...
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.
SourceLocation getBeginLoc() const LLVM_READONLY
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.
unsigned getFieldIndex() const
Returns the index of this field within its record, as appropriate for passing to ASTRecordLayout::get...
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.
SourceLocation getEndLoc() const LLVM_READONLY
QualType withConst() const
Incompatible - We reject this conversion outright, it is invalid to represent it in the AST...
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...
constexpr XRayInstrMask Function
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.
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...
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 isDirectInit() const
Whether this designated initializer should result in direct-initialization of the designated subobjec...
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.
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).
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.
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)
ReferenceCompareResult CompareReferenceRelationship(SourceLocation Loc, QualType T1, QualType T2, ReferenceConversions *Conv=nullptr)
CompareReferenceRelationship - Compare the two types T1 and T2 to determine whether they are referenc...
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...
static CXXTemporaryObjectExpr * Create(const ASTContext &Ctx, CXXConstructorDecl *Cons, QualType Ty, TypeSourceInfo *TSI, ArrayRef< Expr *> Args, SourceRange ParenOrBraceRange, bool HadMultipleCandidates, bool ListInitialization, bool StdInitListInitialization, bool ZeroInitialization)
const CXXBaseSpecifier * getBaseSpecifier() const
Retrieve the base specifier.
OpenCLOptions & getOpenCLOptions()
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?
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
Base wrapper for a particular "section" of type source info.
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)
static bool hasAnyDesignatedInits(const InitListExpr *IL)
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
SourceLocation getBeginLoc() const LLVM_READONLY
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 Zero(InterpState &S, CodePtr OpPC)
ExprResult ActOnDesignatedInitializer(Designation &Desig, SourceLocation EqualOrColonLoc, bool GNUSyntax, ExprResult Init)
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...
Reference with mismatching address space binding to temporary.
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.
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 ...
ReferenceConversions
The conversions that would be performed on an lvalue of type T2 when binding a reference of type T1 t...
Represents the results of name lookup.
SourceLocation getEndLoc() const LLVM_READONLY
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...
void setDestAS(LangAS AS)
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.
APValue Val
Val - This is the value the expression can be folded to.
static bool pathContainsInit(IndirectLocalPath &Path)
static bool TryOCLZeroOpaqueTypeInitialization(Sema &S, InitializationSequence &Sequence, QualType DestType, Expr *Initializer)
Ref_Compatible - The two types are reference-compatible.
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...
static bool isInStlNamespace(const Decl *D)
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
Skip past any parentheses and casts which might surround this expression until reaching a fixed point...
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.
llvm::iterator_range< conversion_iterator > getVisibleConversionFunctions() const
Get all conversion functions visible in current class, including conversion function templates...
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
LLVM_READONLY bool isUppercase(unsigned char c)
Return true if this character is an uppercase ASCII letter: [A-Z].
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.
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.
static bool shouldTrackImplicitObjectArg(const CXXMethodDecl *Callee)
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)
Expr * IgnoreImpCasts() LLVM_READONLY
Skip past any implicit casts which might surround this expression until reaching a fixed point...
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.
ValueDecl * getExtendingDecl()
Get the declaration which triggered the lifetime-extension of this temporary, if any.
Non-const lvalue reference binding to a bit-field.
OverloadedOperatorKind getOverloadedOperator() const
getOverloadedOperator - Which C++ overloaded operator this function represents, if any...
CXXConstructorDecl * getConstructor() const
Get the constructor that this expression will (ultimately) call.
Cannot resolve the address of an overloaded function.
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.
CXXSpecialMember getSpecialMember(const CXXMethodDecl *MD)
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.
bool isEnabled(llvm::StringRef Ext) const
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...
Initializing wide char array with incompatible wide string literal.
bool CanPerformAggregateInitializationForOverloadResolution(const InitializedEntity &Entity, InitListExpr *From)
Determine whether we can perform aggregate initialization for the purposes of overload resolution...
SourceLocation getBeginLoc() const
Get the begin source location.
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
Type source information for an attributed type.
Implicit conversion failed.
llvm::MutableArrayRef< Designator > designators()
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
This represents one expression.
bool isCopyOrMoveConstructor(unsigned &TypeQuals) const
Determine whether this is a copy or move constructor.
void setRBraceLoc(SourceLocation Loc)
std::string getAsString(const ASTContext &Ctx, QualType Ty) const
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.
const CXXRecordDecl * getPointeeCXXRecordDecl() const
If this is a pointer or reference to a RecordType, return the CXXRecordDecl that the type refers to...
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>.
bool isObjCRetainableType() const
__UINTPTR_TYPE__ uintptr_t
An unsigned integer type with the property that any valid pointer to void can be converted to this ty...
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...
void AddProduceObjCObjectStep(QualType T)
Add a step to "produce" an Objective-C object (by retaining it).
static bool isRecordWithAttr(QualType Type)
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...
DeclContext * getParent()
getParent - Returns the containing DeclContext.
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].
SourceLocation getBeginLoc() const LLVM_READONLY
SourceLocation getLocation() const
Retrieve the location at which initialization is occurring.
Common base class for placeholders for types that get replaced by placeholder type deduction: C++11 a...
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.
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
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
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.
SourceLocation getEndLoc() const LLVM_READONLY
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.
bool hasQualifiers() const
Return true if the set contains any qualifiers.
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...
Initialize an opaque OpenCL type (event_t, queue_t, etc.) with zero.
QualType getWideCharType() const
Return the type of wide characters.
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
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
void AddOCLZeroOpaqueTypeStep(QualType T)
Add a step to initialzie an OpenCL opaque type (event_t, queue_t, etc.) from a zero constant...
void runWithSufficientStackSpace(SourceLocation Loc, llvm::function_ref< void()> Fn)
Run some code with "sufficient" stack space.
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.
LangAS getAddressSpace() const
Return the address space of this type.
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
static bool pathOnlyInitializesGslPointer(IndirectLocalPath &Path)
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)
Requests that only tied-for-best candidates be shown.
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.
std::pair< SourceLocation, PartialDiagnostic > PartialDiagnosticAt
A partial diagnostic along with the source location where this diagnostic occurs. ...
Represents a static or instance method of a struct/union/class.
const ConstantArrayType * getAsConstantArrayType(QualType T) const
void AddConversionCandidate(CXXConversionDecl *Conversion, DeclAccessPair FoundDecl, CXXRecordDecl *ActingContext, Expr *From, QualType ToType, OverloadCandidateSet &CandidateSet, bool AllowObjCConversionOnExplicit, bool AllowExplicit, bool AllowResultConversion=true)
AddConversionCandidate - Add a C++ conversion function as a candidate in the candidate set (C++ [over...
Initialization of some unused destination type with an initializer list.
bool isStdNamespace() const
static void visitLocalsRetainedByReferenceBinding(IndirectLocalPath &Path, Expr *Init, ReferenceKind RK, LocalVisitor Visit, bool EnableLifetimeWarnings)
Visit the locals that would be reachable through a reference bound to the glvalue expression Init...
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.
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
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.
bool DiagnoseUseOfDecl(NamedDecl *D, ArrayRef< SourceLocation > Locs, const ObjCInterfaceDecl *UnknownObjCClass=nullptr, bool ObjCPropertyAccess=false, bool AvoidPartialAvailabilityChecks=false, ObjCInterfaceDecl *ClassReciever=nullptr)
Determine whether the use of this declaration is valid, and emit any corresponding diagnostics...
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.
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...
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...
SourceLocation getEndLoc() const LLVM_READONLY
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.
QualType getType() const
Retrieve type being initialized.
Dataflow Directional Tag Classes.
static bool NarrowingErrs(const LangOptions &L)
bool isExplicit() const
Return true if the declartion is already resolved to be explicit.
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.
SourceLocation getBeginLoc() const LLVM_READONLY
A single step in the initialization sequence.
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
EvalResult is a struct with detailed info about an evaluated expression.
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...
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
The name of a declaration.
StmtClass getStmtClass() const
VectorKind getVectorKind() const
const CXXRecordDecl * getParent() const
Return 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).
Qualifiers withoutAddressSpace() const
bool InitField(InterpState &S, CodePtr OpPC, uint32_t I)
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
Skip past any parentheses and implicit casts which might surround this expression until reaching a fi...
Expr * getArrayRangeEnd(const Designator &D) const
static bool isRValueRef(QualType ParamType)
SourceRange getSourceRange() const LLVM_READONLY
Get the full source range.
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...
Expr * IgnoreImplicit() LLVM_READONLY
Skip past any implicit AST nodes which might surround this expression until reaching a fixed point...
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.
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.
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)
QualType getThisObjectType() const
Return the type of the object pointed by this.
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.
void AddTemplateOverloadCandidate(FunctionTemplateDecl *FunctionTemplate, DeclAccessPair FoundDecl, TemplateArgumentListInfo *ExplicitTemplateArgs, ArrayRef< Expr *> Args, OverloadCandidateSet &CandidateSet, bool SuppressUserConversions=false, bool PartialOverloading=false, bool AllowExplicit=true, ADLCallKind IsADLCandidate=ADLCallKind::NotADL, OverloadCandidateParamOrder PO={})
Add a C++ function template specialization as a candidate in the candidate set, using template argume...
QualType getConstantArrayType(QualType EltTy, const llvm::APInt &ArySize, const Expr *SizeExpr, ArrayType::ArraySizeModifier ASM, unsigned IndexTypeQuals) const
Return the unique reference to the type for a constant array of the specified element type...
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...
bool hasAddressSpace() const
Check if this type has any address space qualifier.
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)
void NoteCandidates(PartialDiagnosticAt PA, Sema &S, OverloadCandidateDisplayKind OCD, ArrayRef< Expr *> Args, StringRef Opc="", SourceLocation Loc=SourceLocation(), llvm::function_ref< bool(OverloadCandidate &)> Filter=[](OverloadCandidate &) { return true;})
When overload resolution fails, prints diagnostic messages containing the candidates in the candidate...
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.
static void handleGslAnnotatedTypes(IndirectLocalPath &Path, Expr *Call, LocalVisitor Visit)
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...
ExprResult PerformQualificationConversion(Expr *E, QualType Ty, ExprValueKind VK=VK_RValue, CheckedConversionKind CCK=CCK_ImplicitConversion)
Direct-initialization from a reference-related object in the final stage of class copy-initialization...
DesignatorKind getKind() const
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 void updateGNUCompoundLiteralRValue(Expr *E)
Fix a compound literal initializing an array so it's correctly marked as an rvalue.
ChooseExpr - GNU builtin-in function __builtin_choose_expr.
static bool hasAnyTypeDependentArguments(ArrayRef< Expr *> Exprs)
hasAnyTypeDependentArguments - Determines if any of the expressions in Exprs is type-dependent.
bool LE(InterpState &S, CodePtr OpPC)
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.
void AddOverloadCandidate(FunctionDecl *Function, DeclAccessPair FoundDecl, ArrayRef< Expr *> Args, OverloadCandidateSet &CandidateSet, bool SuppressUserConversions=false, bool PartialOverloading=false, bool AllowExplicit=true, bool AllowExplicitConversion=false, ADLCallKind IsADLCandidate=ADLCallKind::NotADL, ConversionSequenceList EarlyConversions=None, OverloadCandidateParamOrder PO={})
AddOverloadCandidate - Adds the given function to the set of candidate functions, using the given fun...
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
static bool isAddressSpaceSupersetOf(LangAS A, LangAS B)
Returns true if address space A is equal to or a superset of B.
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...
__DEVICE__ int min(int __a, int __b)
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)
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
unsigned getCVRQualifiers() const
Reference binding to a temporary.
bool isOCLIntelSubgroupAVCType() const
static Qualifiers fromCVRMask(unsigned CVR)
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.
void AddTemplateConversionCandidate(FunctionTemplateDecl *FunctionTemplate, DeclAccessPair FoundDecl, CXXRecordDecl *ActingContext, Expr *From, QualType ToType, OverloadCandidateSet &CandidateSet, bool AllowObjCConversionOnExplicit, bool AllowExplicit, bool AllowResultConversion=true)
Adds a conversion function template specialization candidate to the overload set, using template argu...
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.
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...
ImplicitConversionKind First
First – The first conversion can be an lvalue-to-rvalue conversion, array-to-pointer conversion...
void addAddressSpace(LangAS space)
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).
static bool IsZeroInitializer(Expr *Initializer, Sema &S)
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
Return the number of arguments to the constructor call.
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.
SourceLocation getBeginLoc() const LLVM_READONLY
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)
static bool checkDestructorReference(QualType ElementType, SourceLocation Loc, Sema &SemaRef)
Check if the type of a class element has an accessible destructor, and marks it referenced.
Describes an entity that is being initialized.
bool isInStdNamespace() const
static void visitLocalsRetainedByInitializer(IndirectLocalPath &Path, Expr *Init, LocalVisitor Visit, bool RevisitSubinits, bool EnableLifetimeWarnings)
Visit the locals that would be reachable through an object initialized by the prvalue expression Init...
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.
void removeAddressSpace()
SourceLocation getBegin() const
const LangOptions & getLangOpts() const
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.
bool isDependent() const
Determines whether this is a dependent template name.
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 bool shouldTrackFirstArgument(const FunctionDecl *FD)
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 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
Skip past any parentheses which might surround this expression until reaching a fixed point...
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.
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.