24 #include "llvm/ADT/APInt.h"
25 #include "llvm/ADT/SmallString.h"
26 #include "llvm/Support/ErrorHandling.h"
27 #include "llvm/Support/raw_ostream.h"
30 using namespace clang;
62 if (!isa<ConstantArrayType>(AT) && !isa<IncompleteArrayType>(AT))
121 llvm_unreachable(
"missed a StringLiteral kind?");
137 if (isa<StringLiteral>(E) || isa<ObjCEncodeExpr>(E))
139 else if (
ParenExpr *PE = dyn_cast<ParenExpr>(E))
140 E = PE->getSubExpr();
142 E = UO->getSubExpr();
144 E = GSE->getResultExpr();
146 llvm_unreachable(
"unexpected expr in string literal init");
153 auto *ConstantArrayTy =
155 uint64_t StrLength = ConstantArrayTy->getSize().getZExtValue();
160 llvm::APInt ConstVal(32, StrLength);
185 if (StrLength > CAT->
getSize().getZExtValue())
186 S.
Diag(Str->getLocStart(),
187 diag::err_initializer_string_for_char_array_too_long)
188 << Str->getSourceRange();
191 if (StrLength-1 > CAT->
getSize().getZExtValue())
192 S.
Diag(Str->getLocStart(),
193 diag::ext_initializer_string_for_char_array_too_long)
194 << Str->getSourceRange();
237 class InitListChecker {
241 bool TreatUnavailableAsInvalid;
242 llvm::DenseMap<InitListExpr *, InitListExpr *> SyntacticToSemantic;
248 unsigned &StructuredIndex);
252 bool TopLevelObject =
false);
255 bool SubobjectIsDesignatorContext,
258 unsigned &StructuredIndex,
259 bool TopLevelObject =
false);
264 unsigned &StructuredIndex);
269 unsigned &StructuredIndex);
274 unsigned &StructuredIndex);
279 unsigned &StructuredIndex);
283 unsigned &StructuredIndex);
288 bool SubobjectIsDesignatorContext,
unsigned &Index,
290 unsigned &StructuredIndex,
291 bool TopLevelObject =
false);
294 llvm::APSInt elementIndex,
295 bool SubobjectIsDesignatorContext,
unsigned &Index,
297 unsigned &StructuredIndex);
303 llvm::APSInt *NextElementIndex,
306 unsigned &StructuredIndex,
307 bool FinishSubobjectInit,
308 bool TopLevelObject);
312 unsigned StructuredIndex,
314 bool IsFullyOverwritten =
false);
315 void UpdateStructuredListElement(
InitListExpr *StructuredList,
316 unsigned &StructuredIndex,
318 int numArrayElements(
QualType DeclType);
319 int numStructUnionElements(
QualType DeclType);
325 bool TreatUnavailableAsInvalid);
349 bool FillWithNoInit);
350 void FillInEmptyInitForField(
unsigned Init,
FieldDecl *Field,
353 bool FillWithNoInit =
false);
356 bool FillWithNoInit =
false);
359 bool TopLevelObject);
366 bool TreatUnavailableAsInvalid);
367 bool HadError() {
return hadError; }
371 InitListExpr *getFullyStructuredList()
const {
return FullyStructuredList; }
380 bool TreatUnavailableAsInvalid) {
391 bool EmptyInitList = SemaRef.
getLangOpts().CPlusPlus11 &&
404 InitExpr = VerifyOnly ? &DummyInitList :
new (SemaRef.
Context)
420 if (!InitSeq && EmptyInitList && InitSeq.getFailureKind() ==
424 InitSeq.getFailedCandidateSet()
425 .BestViableFunction(SemaRef, Kind.
getLocation(), Best);
427 assert(O ==
OR_Success &&
"Inconsistent overload resolution");
434 bool IsInStd =
false;
435 for (
NamespaceDecl *ND = dyn_cast<NamespaceDecl>(R->getDeclContext());
436 ND && !IsInStd; ND = dyn_cast<
NamespaceDecl>(ND->getParent())) {
441 if (IsInStd && llvm::StringSwitch<bool>(R->getName())
442 .Cases(
"basic_string",
"deque",
"forward_list",
true)
443 .Cases(
"list",
"map",
"multimap",
"multiset",
true)
444 .Cases(
"priority_queue",
"queue",
"set",
"stack",
true)
445 .Cases(
"unordered_map",
"unordered_set",
"vector",
true)
447 InitSeq.InitializeFrom(
451 TreatUnavailableAsInvalid);
455 SemaRef.
Diag(CtorDecl->getLocation(),
456 diag::warn_invalid_initializer_from_system_header);
459 diag::note_used_in_initialization_here);
461 SemaRef.
Diag(Loc, diag::note_used_in_initialization_here);
468 InitSeq.Diagnose(SemaRef, Entity, Kind, SubInit);
471 diag::note_in_omitted_aggregate_initializer)
474 SemaRef.
Diag(Loc, diag::note_in_omitted_aggregate_initializer)
480 return VerifyOnly ?
ExprResult(static_cast<Expr *>(
nullptr))
481 : InitSeq.Perform(SemaRef, Entity, Kind, SubInit);
487 "CheckEmptyInitializable is only inteded for verification mode.");
488 if (PerformEmptyInit(SemaRef, Loc, Entity,
true,
493 void InitListChecker::FillInEmptyInitForBase(
496 bool &RequiresSecondPass,
bool FillWithNoInit) {
497 assert(Init < ILE->getNumInits() &&
"should have been expanded");
500 SemaRef.
Context, &Base,
false, &ParentEntity);
505 : PerformEmptyInit(SemaRef, ILE->
getLocEnd(), BaseEntity,
507 TreatUnavailableAsInvalid);
515 dyn_cast<InitListExpr>(ILE->
getInit(Init))) {
516 FillInEmptyInitializations(BaseEntity, InnerILE,
517 RequiresSecondPass, FillWithNoInit);
519 dyn_cast<DesignatedInitUpdateExpr>(ILE->
getInit(Init))) {
520 FillInEmptyInitializations(BaseEntity, InnerDIUE->getUpdater(),
521 RequiresSecondPass,
true);
525 void InitListChecker::FillInEmptyInitForField(
unsigned Init,
FieldDecl *Field,
528 bool &RequiresSecondPass,
529 bool FillWithNoInit) {
536 if (!RType->getDecl()->isUnion())
537 assert(Init < NumInits &&
"This ILE should have been expanded");
539 if (Init >= NumInits || !ILE->
getInit(Init)) {
540 if (FillWithNoInit) {
562 RequiresSecondPass =
true;
572 SemaRef.
Diag(Loc, diag::err_init_reference_member_uninitialized)
575 SemaRef.
Diag(Field->getLocation(),
576 diag::note_uninit_reference_member);
581 ExprResult MemberInit = PerformEmptyInit(SemaRef, Loc, MemberEntity,
583 TreatUnavailableAsInvalid);
591 }
else if (Init < NumInits) {
593 }
else if (!isa<ImplicitValueInitExpr>(MemberInit.
get())) {
599 RequiresSecondPass =
true;
602 = dyn_cast<InitListExpr>(ILE->
getInit(Init)))
603 FillInEmptyInitializations(MemberEntity, InnerILE,
604 RequiresSecondPass, FillWithNoInit);
606 = dyn_cast<DesignatedInitUpdateExpr>(ILE->
getInit(Init)))
607 FillInEmptyInitializations(MemberEntity, InnerDIUE->getUpdater(),
608 RequiresSecondPass,
true);
617 bool &RequiresSecondPass,
618 bool FillWithNoInit) {
620 "Should not have void type");
626 Entity, ILE, RequiresSecondPass, FillWithNoInit);
627 else if (RDecl->
isUnion() && isa<CXXRecordDecl>(RDecl) &&
628 cast<CXXRecordDecl>(RDecl)->hasInClassInitializer()) {
629 for (
auto *Field : RDecl->
fields()) {
631 FillInEmptyInitForField(0, Field, Entity, ILE, RequiresSecondPass,
640 unsigned NumElems = numStructUnionElements(ILE->getType());
643 if (ILE->getNumInits() < NumElems)
644 ILE->resizeInits(SemaRef.
Context, NumElems);
648 if (
auto *CXXRD = dyn_cast<CXXRecordDecl>(RDecl)) {
649 for (
auto &Base : CXXRD->bases()) {
653 FillInEmptyInitForBase(Init, Base, Entity, ILE, RequiresSecondPass,
659 for (
auto *Field : RDecl->
fields()) {
666 FillInEmptyInitForField(Init, Field, Entity, ILE, RequiresSecondPass,
685 unsigned NumInits = ILE->getNumInits();
686 unsigned NumElements = NumInits;
688 ElementType = AType->getElementType();
690 NumElements = CAType->getSize().getZExtValue();
694 ElementType = VType->getElementType();
695 NumElements = VType->getNumElements();
699 ElementType = ILE->getType();
701 for (
unsigned Init = 0; Init != NumElements; ++Init) {
709 Expr *InitExpr = (Init < NumInits ? ILE->getInit(Init) :
nullptr);
710 if (!InitExpr && Init < NumInits && ILE->hasArrayFiller())
711 ILE->setInit(Init, ILE->getArrayFiller());
712 else if (!InitExpr && !ILE->hasArrayFiller()) {
713 Expr *Filler =
nullptr;
718 ExprResult ElementInit = PerformEmptyInit(SemaRef, ILE->getLocEnd(),
721 TreatUnavailableAsInvalid);
732 }
else if (Init < NumInits) {
736 ILE->setArrayFiller(Filler);
738 ILE->setInit(Init, Filler);
743 ILE->setArrayFiller(Filler);
747 if (!isa<ImplicitValueInitExpr>(Filler) && !isa<NoInitExpr>(Filler)) {
752 ILE->updateInit(SemaRef.
Context, Init, Filler);
753 RequiresSecondPass =
true;
757 = dyn_cast_or_null<InitListExpr>(InitExpr))
758 FillInEmptyInitializations(ElementEntity, InnerILE, RequiresSecondPass,
761 = dyn_cast_or_null<DesignatedInitUpdateExpr>(InitExpr))
762 FillInEmptyInitializations(ElementEntity, InnerDIUE->getUpdater(),
763 RequiresSecondPass,
true);
770 bool TreatUnavailableAsInvalid)
771 : SemaRef(S), VerifyOnly(VerifyOnly),
772 TreatUnavailableAsInvalid(TreatUnavailableAsInvalid) {
778 FullyStructuredList =
779 getStructuredSubobjectInit(IL, 0, T,
nullptr, 0, IL->getSourceRange());
780 CheckExplicitInitList(Entity, IL, T, FullyStructuredList,
783 if (!hadError && !VerifyOnly) {
784 bool RequiresSecondPass =
false;
785 FillInEmptyInitializations(Entity, FullyStructuredList, RequiresSecondPass);
786 if (RequiresSecondPass && !hadError)
787 FillInEmptyInitializations(Entity, FullyStructuredList,
792 int InitListChecker::numArrayElements(
QualType DeclType) {
794 int maxElements = 0x7FFFFFFF;
797 maxElements =
static_cast<int>(CAT->getSize().getZExtValue());
802 int InitListChecker::numStructUnionElements(
QualType DeclType) {
804 int InitializableMembers = 0;
805 if (
auto *CXXRD = dyn_cast<CXXRecordDecl>(structDecl))
806 InitializableMembers += CXXRD->getNumBases();
807 for (
const auto *Field : structDecl->
fields())
809 ++InitializableMembers;
812 return std::min(InitializableMembers, 1);
826 unsigned &StructuredIndex) {
830 maxElements = numArrayElements(T);
832 maxElements = numStructUnionElements(T);
836 llvm_unreachable(
"CheckImplicitInitList(): Illegal type");
838 if (maxElements == 0) {
840 SemaRef.
Diag(ParentIList->
getInit(Index)->getLocStart(),
841 diag::err_implicit_empty_initializer);
849 = getStructuredSubobjectInit(ParentIList, Index, T, StructuredList,
852 ParentIList->getSourceRange().getEnd()));
853 unsigned StructuredSubobjectInitIndex = 0;
856 unsigned StartIndex = Index;
857 CheckListElementTypes(Entity, ParentIList, T,
859 StructuredSubobjectInitList,
860 StructuredSubobjectInitIndex);
863 StructuredSubobjectInitList->
setType(T);
865 unsigned EndIndex = (Index == StartIndex? StartIndex : Index - 1);
868 if (EndIndex < ParentIList->getNumInits() &&
869 ParentIList->
getInit(EndIndex)) {
871 = ParentIList->
getInit(EndIndex)->getSourceRange().getEnd();
878 diag::warn_missing_braces)
879 << StructuredSubobjectInitList->getSourceRange()
880 << FixItHint::CreateInsertion(
882 << FixItHint::CreateInsertion(
884 StructuredSubobjectInitList->
getLocEnd()),
903 case InitializedEntity::EK_VectorElement:
904 case InitializedEntity::EK_ComplexElement:
905 case InitializedEntity::EK_ArrayElement:
906 case InitializedEntity::EK_Parameter:
907 case InitializedEntity::EK_Parameter_CF_Audited:
908 case InitializedEntity::EK_Result:
910 DiagID = diag::warn_braces_around_scalar_init;
913 case InitializedEntity::EK_Member:
917 DiagID = diag::warn_braces_around_scalar_init;
920 case InitializedEntity::EK_Variable:
921 case InitializedEntity::EK_LambdaCapture:
926 case InitializedEntity::EK_New:
927 case InitializedEntity::EK_Temporary:
928 case InitializedEntity::EK_CompoundLiteralInit:
932 case InitializedEntity::EK_RelatedResult:
936 case InitializedEntity::EK_Exception:
937 case InitializedEntity::EK_Base:
938 case InitializedEntity::EK_Delegating:
939 case InitializedEntity::EK_BlockElement:
940 llvm_unreachable(
"unexpected braced scalar init");
946 << FixItHint::CreateRemoval(Braces.
getBegin())
947 << FixItHint::CreateRemoval(Braces.
getEnd());
959 bool TopLevelObject) {
961 SyntacticToSemantic[IList] = StructuredList;
965 unsigned Index = 0, StructuredIndex = 0;
966 CheckListElementTypes(Entity, IList, T,
true,
967 Index, StructuredList, StructuredIndex, TopLevelObject);
973 StructuredList->
setType(ExprTy);
978 if (Index < IList->getNumInits()) {
989 if (StructuredIndex == 1 &&
992 unsigned DK = diag::ext_excess_initializers_in_char_array_initializer;
994 DK = diag::err_excess_initializers_in_char_array_initializer;
998 SemaRef.
Diag(IList->
getInit(Index)->getLocStart(), DK)
999 << IList->
getInit(Index)->getSourceRange();
1011 unsigned DK = diag::ext_excess_initializers;
1013 DK = diag::err_excess_initializers;
1016 if (SemaRef.
getLangOpts().OpenCL && initKind == 1) {
1017 DK = diag::err_excess_initializers;
1021 SemaRef.
Diag(IList->
getInit(Index)->getLocStart(), DK)
1022 << initKind << IList->
getInit(Index)->getSourceRange();
1034 bool SubobjectIsDesignatorContext,
1037 unsigned &StructuredIndex,
1038 bool TopLevelObject) {
1042 CheckComplexType(Entity, IList, DeclType, Index,
1043 StructuredList, StructuredIndex);
1045 CheckScalarType(Entity, IList, DeclType, Index,
1046 StructuredList, StructuredIndex);
1048 CheckVectorType(Entity, IList, DeclType, Index,
1049 StructuredList, StructuredIndex);
1052 "non-aggregate records should be handed in CheckSubElementType");
1057 if (
auto *CXXRD = dyn_cast<CXXRecordDecl>(RD))
1058 Bases = CXXRD->bases();
1059 CheckStructUnionTypes(Entity, IList, DeclType, Bases, RD->field_begin(),
1060 SubobjectIsDesignatorContext, Index, StructuredList,
1061 StructuredIndex, TopLevelObject);
1066 CheckArrayType(Entity, IList, DeclType, Zero,
1067 SubobjectIsDesignatorContext, Index,
1068 StructuredList, StructuredIndex);
1073 SemaRef.
Diag(IList->
getLocStart(), diag::err_illegal_initializer_type)
1077 CheckReferenceType(Entity, IList, DeclType, Index,
1078 StructuredList, StructuredIndex);
1086 SemaRef.
Diag(IList->
getLocStart(), diag::err_illegal_initializer_type)
1097 unsigned &StructuredIndex) {
1101 return CheckReferenceType(Entity, IList, ElemType, Index,
1102 StructuredList, StructuredIndex);
1104 if (
InitListExpr *SubInitList = dyn_cast<InitListExpr>(expr)) {
1105 if (SubInitList->getNumInits() == 1 &&
1108 expr = SubInitList->getInit(0);
1111 = getStructuredSubobjectInit(IList, Index, ElemType,
1112 StructuredList, StructuredIndex,
1113 SubInitList->getSourceRange(),
true);
1114 CheckExplicitInitList(Entity, SubInitList, ElemType,
1115 InnerStructuredList);
1117 if (!hadError && !VerifyOnly) {
1118 bool RequiresSecondPass =
false;
1119 FillInEmptyInitializations(Entity, InnerStructuredList,
1120 RequiresSecondPass);
1121 if (RequiresSecondPass && !hadError)
1122 FillInEmptyInitializations(Entity, InnerStructuredList,
1123 RequiresSecondPass);
1130 }
else if (isa<ImplicitValueInitExpr>(expr)) {
1134 "found implicit initialization for the wrong type");
1136 UpdateStructuredListElement(StructuredList, StructuredIndex, expr);
1148 InitializationKind::CreateCopy(expr->getLocStart(),
SourceLocation());
1158 if (Seq || isa<InitListExpr>(expr)) {
1161 Seq.Perform(SemaRef, Entity, Kind, expr);
1165 UpdateStructuredListElement(StructuredList, StructuredIndex,
1176 return CheckScalarType(Entity, IList, ElemType, Index,
1177 StructuredList, StructuredIndex);
1187 UpdateStructuredListElement(StructuredList, StructuredIndex, expr);
1209 ElemType, ExprRes, !VerifyOnly) != Sema::Incompatible) {
1217 UpdateStructuredListElement(StructuredList, StructuredIndex,
1234 CheckImplicitInitList(Entity, IList, ElemType, Index, StructuredList,
1254 unsigned &StructuredIndex) {
1255 assert(Index == 0 &&
"Index in explicit init list must be zero");
1265 return CheckScalarType(Entity, IList, DeclType, Index, StructuredList,
1270 if (!SemaRef.
getLangOpts().CPlusPlus && !VerifyOnly)
1272 << IList->getSourceRange();
1277 InitializedEntity::InitializeElement(SemaRef.
Context, 0, Entity);
1279 for (
unsigned i = 0; i < 2; ++i) {
1281 CheckSubElementType(ElementEntity, IList, elementType, Index,
1282 StructuredList, StructuredIndex);
1290 unsigned &StructuredIndex) {
1295 diag::warn_cxx98_compat_empty_scalar_initializer :
1296 diag::err_empty_scalar_initializer)
1297 << IList->getSourceRange();
1305 if (
InitListExpr *SubIList = dyn_cast<InitListExpr>(expr)) {
1309 SemaRef.
Diag(SubIList->getLocStart(),
1310 diag::ext_many_braces_around_scalar_init)
1311 << SubIList->getSourceRange();
1313 CheckScalarType(Entity, SubIList, DeclType, Index, StructuredList,
1316 }
else if (isa<DesignatedInitExpr>(expr)) {
1318 SemaRef.
Diag(expr->getLocStart(),
1319 diag::err_designator_for_scalar_init)
1320 << DeclType << expr->getSourceRange();
1338 Expr *ResultExpr =
nullptr;
1345 if (ResultExpr != expr) {
1347 IList->
setInit(Index, ResultExpr);
1353 UpdateStructuredListElement(StructuredList, StructuredIndex, ResultExpr);
1361 unsigned &StructuredIndex) {
1369 diag::err_init_reference_member_uninitialized)
1371 << IList->getSourceRange();
1379 if (isa<InitListExpr>(expr) && !SemaRef.
getLangOpts().CPlusPlus11) {
1382 << DeclType << IList->getSourceRange();
1409 UpdateStructuredListElement(StructuredList, StructuredIndex, expr);
1417 unsigned &StructuredIndex) {
1420 unsigned numEltsInit = 0;
1426 CheckEmptyInitializable(
1427 InitializedEntity::InitializeElement(SemaRef.
Context, 0, Entity),
1448 Expr *ResultExpr =
nullptr;
1454 if (ResultExpr != Init) {
1456 IList->
setInit(Index, ResultExpr);
1462 UpdateStructuredListElement(StructuredList, StructuredIndex,
1469 InitializedEntity::InitializeElement(SemaRef.
Context, 0, Entity);
1471 for (
unsigned i = 0; i < maxElements; ++i, ++numEltsInit) {
1475 CheckEmptyInitializable(ElementEntity, IList->
getLocEnd());
1480 CheckSubElementType(ElementEntity, IList, elementType, Index,
1481 StructuredList, StructuredIndex);
1489 if (isBigEndian && (T->
getVectorKind() == VectorType::NeonVector ||
1502 diag::warn_neon_vector_initializer_non_portable);
1504 const char *typeCode;
1514 llvm_unreachable(
"Invalid element type!");
1518 diag::note_neon_vector_initializer_non_portable_q :
1519 diag::note_neon_vector_initializer_non_portable)
1520 << typeCode << typeSize;
1527 InitializedEntity::InitializeElement(SemaRef.
Context, 0, Entity);
1530 for (
unsigned i = 0; i < maxElements; ++i) {
1539 CheckSubElementType(ElementEntity, IList, elementType, Index,
1540 StructuredList, StructuredIndex);
1552 CheckSubElementType(ElementEntity, IList, VecType, Index,
1553 StructuredList, StructuredIndex);
1554 numEltsInit += numIElts;
1559 if (numEltsInit != maxElements) {
1562 diag::err_vector_incorrect_num_initializers)
1563 << (numEltsInit < maxElements) << maxElements << numEltsInit;
1570 llvm::APSInt elementIndex,
1571 bool SubobjectIsDesignatorContext,
1574 unsigned &StructuredIndex) {
1578 if (Index < IList->getNumInits()) {
1588 UpdateStructuredListElement(StructuredList, StructuredIndex,
1601 SemaRef.
Diag(VAT->getSizeExpr()->getLocStart(),
1602 diag::err_variable_object_no_init)
1603 << VAT->getSizeExpr()->getSourceRange();
1611 llvm::APSInt maxElements(elementIndex.getBitWidth(),
1612 elementIndex.isUnsigned());
1613 bool maxElementsKnown =
false;
1615 maxElements = CAT->getSize();
1616 elementIndex = elementIndex.extOrTrunc(maxElements.getBitWidth());
1617 elementIndex.setIsUnsigned(maxElements.isUnsigned());
1618 maxElementsKnown =
true;
1622 while (Index < IList->getNumInits()) {
1628 if (!SubobjectIsDesignatorContext)
1633 if (CheckDesignatedInitializer(Entity, IList, DIE, 0,
1634 DeclType,
nullptr, &elementIndex, Index,
1635 StructuredList, StructuredIndex,
true,
1641 if (elementIndex.getBitWidth() > maxElements.getBitWidth())
1642 maxElements = maxElements.extend(elementIndex.getBitWidth());
1643 else if (elementIndex.getBitWidth() < maxElements.getBitWidth())
1644 elementIndex = elementIndex.extend(maxElements.getBitWidth());
1645 elementIndex.setIsUnsigned(maxElements.isUnsigned());
1649 if (!maxElementsKnown && elementIndex > maxElements)
1650 maxElements = elementIndex;
1657 if (maxElementsKnown && elementIndex == maxElements)
1661 InitializedEntity::InitializeElement(SemaRef.
Context, StructuredIndex,
1664 CheckSubElementType(ElementEntity, IList, elementType, Index,
1665 StructuredList, StructuredIndex);
1670 if (!maxElementsKnown && elementIndex > maxElements)
1671 maxElements = elementIndex;
1676 llvm::APSInt Zero(maxElements.getBitWidth(), maxElements.isUnsigned());
1677 if (maxElements == Zero) {
1681 diag::ext_typecheck_zero_array_size);
1685 ArrayType::Normal, 0);
1687 if (!hadError && VerifyOnly) {
1691 if (maxElementsKnown && elementIndex < maxElements)
1692 CheckEmptyInitializable(InitializedEntity::InitializeElement(
1701 bool TopLevelObject) {
1703 unsigned FlexArrayDiag;
1704 if (isa<InitListExpr>(InitExpr) &&
1705 cast<InitListExpr>(InitExpr)->getNumInits() == 0) {
1707 FlexArrayDiag = diag::ext_flexible_array_init;
1711 FlexArrayDiag = diag::err_flexible_array_init;
1712 }
else if (!TopLevelObject) {
1714 FlexArrayDiag = diag::err_flexible_array_init;
1715 }
else if (Entity.
getKind() != InitializedEntity::EK_Variable) {
1717 FlexArrayDiag = diag::err_flexible_array_init;
1718 }
else if (cast<VarDecl>(Entity.
getDecl())->hasLocalStorage()) {
1720 FlexArrayDiag = diag::err_flexible_array_init;
1723 FlexArrayDiag = diag::ext_flexible_array_init;
1727 SemaRef.
Diag(InitExpr->getLocStart(),
1729 << InitExpr->getLocStart();
1730 SemaRef.
Diag(Field->getLocation(), diag::note_flexible_array_member)
1734 return FlexArrayDiag != diag::ext_flexible_array_init;
1737 void InitListChecker::CheckStructUnionTypes(
1740 bool SubobjectIsDesignatorContext,
unsigned &Index,
1741 InitListExpr *StructuredList,
unsigned &StructuredIndex,
1742 bool TopLevelObject) {
1747 if (structDecl->isInvalidDecl()) {
1758 if (isa<CXXRecordDecl>(RD) && cast<CXXRecordDecl>(RD)->hasInClassInitializer()) {
1762 Field != FieldEnd; ++Field) {
1763 if (Field->hasInClassInitializer()) {
1774 Field != FieldEnd; ++Field) {
1775 if (!Field->isUnnamedBitfield()) {
1777 CheckEmptyInitializable(
1778 InitializedEntity::InitializeMember(*Field, &Entity),
1788 bool InitializedSomething =
false;
1791 for (
auto &Base : Bases) {
1797 if (Init && isa<DesignatedInitExpr>(Init))
1801 SemaRef.
Context, &Base,
false, &Entity);
1803 CheckSubElementType(BaseEntity, IList, Base.
getType(), Index,
1804 StructuredList, StructuredIndex);
1805 InitializedSomething =
true;
1806 }
else if (VerifyOnly) {
1807 CheckEmptyInitializable(BaseEntity, InitLoc);
1817 bool CheckForMissingFields =
true;
1818 while (Index < IList->getNumInits()) {
1825 if (!SubobjectIsDesignatorContext)
1830 if (CheckDesignatedInitializer(Entity, IList, DIE, 0,
1831 DeclType, &Field,
nullptr, Index,
1832 StructuredList, StructuredIndex,
1833 true, TopLevelObject))
1836 InitializedSomething =
true;
1840 CheckForMissingFields =
false;
1844 if (Field == FieldEnd) {
1850 if (InitializedSomething && DeclType->
isUnionType())
1854 if (Field->getType()->isIncompleteArrayType())
1857 if (Field->isUnnamedBitfield()) {
1866 InvalidUse = !SemaRef.
CanUseDecl(*Field, TreatUnavailableAsInvalid);
1869 IList->
getInit(Index)->getLocStart());
1878 InitializedEntity::InitializeMember(*Field, &Entity);
1879 CheckSubElementType(MemberEntity, IList, Field->getType(), Index,
1880 StructuredList, StructuredIndex);
1881 InitializedSomething =
true;
1885 StructuredList->setInitializedFieldInUnion(*Field);
1892 if (!VerifyOnly && InitializedSomething && CheckForMissingFields &&
1893 Field != FieldEnd && !Field->getType()->isIncompleteArrayType() &&
1899 if (!it->isUnnamedBitfield() && !it->hasInClassInitializer()) {
1900 SemaRef.
Diag(IList->getSourceRange().getEnd(),
1901 diag::warn_missing_field_initializers) << *it;
1908 if (VerifyOnly && Field != FieldEnd && !DeclType->
isUnionType() &&
1909 !Field->getType()->isIncompleteArrayType()) {
1911 for (; Field != FieldEnd && !hadError; ++Field) {
1912 if (!Field->isUnnamedBitfield() && !Field->hasInClassInitializer())
1913 CheckEmptyInitializable(
1914 InitializedEntity::InitializeMember(*Field, &Entity),
1919 if (Field == FieldEnd || !Field->getType()->isIncompleteArrayType() ||
1923 if (CheckFlexibleArrayInit(Entity, IList->
getInit(Index), *Field,
1931 InitializedEntity::InitializeMember(*Field, &Entity);
1933 if (isa<InitListExpr>(IList->
getInit(Index)))
1934 CheckSubElementType(MemberEntity, IList, Field->getType(), Index,
1935 StructuredList, StructuredIndex);
1937 CheckImplicitInitList(MemberEntity, IList, Field->getType(), Index,
1938 StructuredList, StructuredIndex);
1954 PE = IndirectField->
chain_end(); PI != PE; ++PI) {
1962 assert(isa<FieldDecl>(*PI));
1963 Replacements.back().setField(cast<FieldDecl>(*PI));
1970 &Replacements[0] + Replacements.size());
1977 for (
unsigned I = 0;
I < NumIndexExprs; ++
I)
1991 explicit FieldInitializerValidatorCCC(
RecordDecl *RD)
1996 return FD && FD->getDeclContext()->getRedeclContext()->Equals(Record);
2047 llvm::APSInt *NextElementIndex,
2050 unsigned &StructuredIndex,
2051 bool FinishSubobjectInit,
2052 bool TopLevelObject) {
2053 if (DesigIdx == DIE->
size()) {
2055 bool prevHadError = hadError;
2060 unsigned OldIndex = Index;
2063 CheckSubElementType(Entity, IList, CurrentObjectType, Index,
2064 StructuredList, StructuredIndex);
2070 IList->
setInit(OldIndex, DIE);
2072 return hadError && !prevHadError;
2076 bool IsFirstDesignator = (DesigIdx == 0);
2078 assert((IsFirstDesignator || StructuredList) &&
2079 "Need a non-designated initializer list to start from");
2083 if (IsFirstDesignator)
2084 StructuredList = SyntacticToSemantic.lookup(IList);
2086 Expr *ExistingInit = StructuredIndex < StructuredList->
getNumInits() ?
2087 StructuredList->
getInit(StructuredIndex) :
nullptr;
2093 getStructuredSubobjectInit(IList, Index, CurrentObjectType,
2094 StructuredList, StructuredIndex,
2097 else if (
InitListExpr *Result = dyn_cast<InitListExpr>(ExistingInit))
2098 StructuredList = Result;
2101 dyn_cast<DesignatedInitUpdateExpr>(ExistingInit))
2102 StructuredList =
E->getUpdater();
2120 if (ExistingInit->getSourceRange().isValid()) {
2133 diag::warn_subobject_initializer_overrides)
2136 SemaRef.
Diag(ExistingInit->getLocStart(),
2137 diag::note_previous_initializer)
2139 << ExistingInit->getSourceRange();
2143 assert(StructuredList &&
"Expected a structured initializer list");
2162 SemaRef.
Diag(Loc, diag::err_field_designator_non_aggr)
2163 << SemaRef.
getLangOpts().CPlusPlus << CurrentObjectType;
2173 if (
auto *FD = dyn_cast<FieldDecl>(ND)) {
2177 if (
auto *IFD = dyn_cast<IndirectFieldDecl>(ND)) {
2183 KnownField = cast<FieldDecl>(*IFD->chain_begin());
2194 if (!Lookup.empty()) {
2197 SemaRef.
Diag(Lookup.front()->getLocation(),
2198 diag::note_field_designator_found);
2207 Sema::LookupMemberName,
nullptr,
nullptr,
2208 llvm::make_unique<FieldInitializerValidatorCCC>(RT->
getDecl()),
2209 Sema::CTK_ErrorRecovery, RT->
getDecl())) {
2212 SemaRef.
PDiag(diag::err_field_designator_unknown_suggest)
2213 << FieldName << CurrentObjectType);
2214 KnownField = Corrected.getCorrectionDeclAs<
FieldDecl>();
2219 << FieldName << CurrentObjectType;
2226 unsigned FieldIndex = 0;
2228 if (FI->isUnnamedBitfield())
2248 &&
"A union should never have more than one initializer!");
2252 diag::warn_initializer_overrides)
2255 SemaRef.
Diag(ExistingInit->getLocStart(),
2256 diag::note_previous_initializer)
2258 << ExistingInit->getSourceRange();
2272 InvalidUse = !SemaRef.
CanUseDecl(*Field, TreatUnavailableAsInvalid);
2291 if (Field->getType()->isIncompleteArrayType()) {
2293 if ((DesigIdx + 1) != DIE->
size()) {
2300 diag::err_designator_into_flexible_array_member)
2303 SemaRef.
Diag(Field->getLocation(), diag::note_flexible_array_member)
2309 if (!hadError && !isa<InitListExpr>(DIE->
getInit()) &&
2310 !isa<StringLiteral>(DIE->
getInit())) {
2314 diag::err_flexible_array_init_needs_braces)
2315 << DIE->
getInit()->getSourceRange();
2316 SemaRef.
Diag(Field->getLocation(), diag::note_flexible_array_member)
2323 if (!Invalid && CheckFlexibleArrayInit(Entity, DIE->
getInit(), *Field,
2333 bool prevHadError = hadError;
2334 unsigned newStructuredIndex = FieldIndex;
2335 unsigned OldIndex = Index;
2339 InitializedEntity::InitializeMember(*Field, &Entity);
2340 CheckSubElementType(MemberEntity, IList, Field->getType(), Index,
2341 StructuredList, newStructuredIndex);
2343 IList->
setInit(OldIndex, DIE);
2344 if (hadError && !prevHadError) {
2349 StructuredIndex = FieldIndex;
2354 QualType FieldType = Field->getType();
2355 unsigned newStructuredIndex = FieldIndex;
2358 InitializedEntity::InitializeMember(*Field, &Entity);
2359 if (CheckDesignatedInitializer(MemberEntity, IList, DIE, DesigIdx + 1,
2360 FieldType,
nullptr,
nullptr, Index,
2361 StructuredList, newStructuredIndex,
2362 FinishSubobjectInit,
false))
2373 if (IsFirstDesignator) {
2376 StructuredIndex = FieldIndex;
2380 if (!FinishSubobjectInit)
2388 bool prevHadError = hadError;
2393 CheckStructUnionTypes(Entity, IList, CurrentObjectType, NoBases, Field,
2394 false, Index, StructuredList, FieldIndex);
2395 return hadError && !prevHadError;
2417 << CurrentObjectType;
2422 Expr *IndexExpr =
nullptr;
2423 llvm::APSInt DesignatedStartIndex, DesignatedEndIndex;
2427 DesignatedEndIndex = DesignatedStartIndex;
2431 DesignatedStartIndex =
2433 DesignatedEndIndex =
2442 if (DesignatedStartIndex.getZExtValue()!=DesignatedEndIndex.getZExtValue()&&
2444 FullyStructuredList->sawArrayRangeDesignator();
2447 if (isa<ConstantArrayType>(AT)) {
2448 llvm::APSInt MaxElements(cast<ConstantArrayType>(AT)->getSize(),
false);
2449 DesignatedStartIndex
2450 = DesignatedStartIndex.extOrTrunc(MaxElements.getBitWidth());
2451 DesignatedStartIndex.setIsUnsigned(MaxElements.isUnsigned());
2453 = DesignatedEndIndex.extOrTrunc(MaxElements.getBitWidth());
2454 DesignatedEndIndex.setIsUnsigned(MaxElements.isUnsigned());
2455 if (DesignatedEndIndex >= MaxElements) {
2457 SemaRef.
Diag(IndexExpr->getLocStart(),
2458 diag::err_array_designator_too_large)
2459 << DesignatedEndIndex.toString(10) << MaxElements.toString(10)
2460 << IndexExpr->getSourceRange();
2465 unsigned DesignatedIndexBitWidth =
2466 ConstantArrayType::getMaxSizeBits(SemaRef.
Context);
2467 DesignatedStartIndex =
2468 DesignatedStartIndex.extOrTrunc(DesignatedIndexBitWidth);
2469 DesignatedEndIndex =
2470 DesignatedEndIndex.extOrTrunc(DesignatedIndexBitWidth);
2471 DesignatedStartIndex.setIsUnsigned(
true);
2472 DesignatedEndIndex.setIsUnsigned(
true);
2475 if (!VerifyOnly && StructuredList->isStringLiteralInit()) {
2488 unsigned PromotedCharTyWidth = Context.
getTypeSize(PromotedCharTy);
2492 uint64_t StrLen = SL->getLength();
2493 if (cast<ConstantArrayType>(AT)->getSize().ult(StrLen))
2494 StrLen = cast<ConstantArrayType>(AT)->getSize().getZExtValue();
2495 StructuredList->resizeInits(Context, StrLen);
2499 for (
unsigned i = 0, e = StrLen; i != e; ++i) {
2500 llvm::APInt CodeUnit(PromotedCharTyWidth, SL->getCodeUnit(i));
2502 Context, CodeUnit, PromotedCharTy, SubExpr->
getExprLoc());
2503 if (CharTy != PromotedCharTy)
2506 StructuredList->updateInit(Context, i, Init);
2514 uint64_t StrLen = Str.size();
2515 if (cast<ConstantArrayType>(AT)->getSize().ult(StrLen))
2516 StrLen = cast<ConstantArrayType>(AT)->getSize().getZExtValue();
2517 StructuredList->resizeInits(Context, StrLen);
2521 for (
unsigned i = 0, e = StrLen; i != e; ++i) {
2522 llvm::APInt CodeUnit(PromotedCharTyWidth, Str[i]);
2524 Context, CodeUnit, PromotedCharTy, SubExpr->
getExprLoc());
2525 if (CharTy != PromotedCharTy)
2528 StructuredList->updateInit(Context, i, Init);
2536 DesignatedEndIndex.getZExtValue() >= StructuredList->getNumInits())
2537 StructuredList->resizeInits(SemaRef.
Context,
2538 DesignatedEndIndex.getZExtValue() + 1);
2544 unsigned ElementIndex = DesignatedStartIndex.getZExtValue();
2545 unsigned OldIndex = Index;
2548 InitializedEntity::InitializeElement(SemaRef.
Context, 0, Entity);
2550 while (DesignatedStartIndex <= DesignatedEndIndex) {
2556 if (CheckDesignatedInitializer(
2557 ElementEntity, IList, DIE, DesigIdx + 1, ElementType,
nullptr,
2558 nullptr, Index, StructuredList, ElementIndex,
2559 FinishSubobjectInit && (DesignatedStartIndex == DesignatedEndIndex),
2564 ++DesignatedStartIndex;
2565 ElementIndex = DesignatedStartIndex.getZExtValue();
2570 if (IsFirstDesignator) {
2571 if (NextElementIndex)
2572 *NextElementIndex = DesignatedStartIndex;
2573 StructuredIndex = ElementIndex;
2577 if (!FinishSubobjectInit)
2581 bool prevHadError = hadError;
2582 CheckArrayType(Entity, IList, CurrentObjectType, DesignatedStartIndex,
2584 StructuredList, ElementIndex);
2585 return hadError && !prevHadError;
2591 InitListChecker::getStructuredSubobjectInit(
InitListExpr *IList,
unsigned Index,
2594 unsigned StructuredIndex,
2596 bool IsFullyOverwritten) {
2599 Expr *ExistingInit =
nullptr;
2600 if (!StructuredList)
2601 ExistingInit = SyntacticToSemantic.lookup(IList);
2602 else if (StructuredIndex < StructuredList->getNumInits())
2603 ExistingInit = StructuredList->
getInit(StructuredIndex);
2605 if (
InitListExpr *Result = dyn_cast_or_null<InitListExpr>(ExistingInit))
2614 if (!IsFullyOverwritten)
2630 diag::warn_subobject_initializer_overrides)
2632 SemaRef.
Diag(ExistingInit->getLocStart(),
2633 diag::note_previous_initializer)
2635 << ExistingInit->getSourceRange();
2643 QualType ResultType = CurrentObjectType;
2649 unsigned NumElements = 0;
2650 unsigned NumInits = 0;
2651 bool GotNumInits =
false;
2652 if (!StructuredList) {
2655 }
else if (Index < IList->getNumInits()) {
2657 NumInits = SubList->getNumInits();
2665 NumElements = CAType->getSize().getZExtValue();
2668 if (GotNumInits && NumElements > NumInits)
2672 NumElements = VType->getNumElements();
2689 SyntacticToSemantic[IList] = Result;
2697 void InitListChecker::UpdateStructuredListElement(
InitListExpr *StructuredList,
2698 unsigned &StructuredIndex,
2701 if (!StructuredList)
2705 StructuredIndex, expr)) {
2713 if (PrevInit->getSourceRange().isValid()) {
2714 SemaRef.
Diag(expr->getLocStart(),
2715 diag::warn_initializer_overrides)
2716 << expr->getSourceRange();
2718 SemaRef.
Diag(PrevInit->getLocStart(),
2719 diag::note_previous_initializer)
2721 << PrevInit->getSourceRange();
2744 if (Value.isSigned() && Value.isNegative())
2745 return S.
Diag(Loc, diag::err_array_designator_negative)
2746 << Value.toString(10) << Index->getSourceRange();
2748 Value.setIsUnsigned(
true);
2758 bool Invalid =
false;
2773 llvm::APSInt IndexValue;
2779 Designators.push_back(ASTDesignator(InitExpressions.size(),
2782 InitExpressions.push_back(Index);
2790 llvm::APSInt StartValue;
2791 llvm::APSInt EndValue;
2796 if (!StartDependent)
2802 if (!StartIndex || !EndIndex)
2806 if (StartDependent || EndDependent) {
2808 }
else if (StartValue.getBitWidth() > EndValue.getBitWidth())
2809 EndValue = EndValue.extend(StartValue.getBitWidth());
2810 else if (StartValue.getBitWidth() < EndValue.getBitWidth())
2811 StartValue = StartValue.extend(EndValue.getBitWidth());
2813 if (!StartDependent && !EndDependent && EndValue < StartValue) {
2815 << StartValue.toString(10) << EndValue.toString(10)
2816 << StartIndex->getSourceRange() << EndIndex->getSourceRange();
2819 Designators.push_back(ASTDesignator(InitExpressions.size(),
2823 InitExpressions.push_back(StartIndex);
2824 InitExpressions.push_back(EndIndex);
2841 InitExpressions, Loc, GNUSyntax,
2846 << DIE->getSourceRange();
2855 InitializedEntity::InitializedEntity(
ASTContext &Context,
unsigned Index,
2857 : Parent(&Parent), Index(Index)
2860 Kind = EK_ArrayElement;
2863 Kind = EK_VectorElement;
2867 assert(CT &&
"Unexpected type");
2868 Kind = EK_ComplexElement;
2876 bool IsInheritedVirtualBase,
2880 Result.Parent = Parent;
2882 if (IsInheritedVirtualBase)
2883 Result.
Base |= 0x01;
2885 Result.Type = Base->
getType();
2919 llvm_unreachable(
"Invalid EntityKind!");
2948 llvm_unreachable(
"Invalid EntityKind!");
2978 unsigned InitializedEntity::dumpImpl(raw_ostream &OS)
const {
2981 for (
unsigned I = 0;
I !=
Depth; ++
I)
2992 case EK_New: OS <<
"New";
break;
2996 case EK_Base: OS <<
"Base";
break;
3003 OS <<
"LambdaCapture ";
3010 cast<NamedDecl>(D)->printQualifiedName(OS);
3019 dumpImpl(llvm::errs());
3112 llvm_unreachable(
"Invalid EntityKind!");
3123 bool HadMultipleCandidates) {
3146 bool BindingTemporary) {
3164 bool HadMultipleCandidates) {
3201 assert(!Ty.
hasQualifiers() &&
"rvalues may not have qualifiers");
3211 bool TopLevelOfInitList) {
3229 bool HadMultipleCandidates,
bool FromInitList,
bool AsInitList) {
3323 "Can only rewrap trivial init lists.");
3327 Steps.insert(Steps.begin(),
S);
3331 S.WrappingSyntacticList = Syntactic;
3338 this->Failure = Failure;
3339 this->FailedOverloadResult =
Result;
3354 if (VD->
getInit() || VD->getLocEnd().isMacroID())
3360 if (!Init.empty()) {
3380 "consuming an object of unretainable type?");
3400 bool TreatUnavailableAsInvalid);
3411 bool TreatUnavailableAsInvalid) {
3431 TreatUnavailableAsInvalid);
3443 bool CopyInitializing,
bool AllowExplicit,
3444 bool OnlyListConstructors,
bool IsListInit) {
3445 CandidateSet.
clear();
3449 if (!Info.Constructor)
3452 bool SuppressUserConversions =
false;
3454 if (!Info.ConstructorTmpl) {
3469 if ((CopyInitializing ||
3470 (IsListInit && Args.size() == 1 && isa<InitListExpr>(Args[0]))) &&
3471 Info.Constructor->isCopyOrMoveConstructor())
3472 SuppressUserConversions =
true;
3475 if (!Info.Constructor->isInvalidDecl() &&
3476 (AllowExplicit || !Info.Constructor->isExplicit()) &&
3478 if (Info.ConstructorTmpl)
3481 CandidateSet, SuppressUserConversions);
3489 bool AllowExplicitConv = AllowExplicit && !CopyInitializing &&
3491 Info.Constructor->isCopyOrMoveConstructor();
3493 CandidateSet, SuppressUserConversions,
3516 bool IsListInit =
false,
3517 bool IsInitListCopy =
false) {
3518 assert((!IsListInit || (Args.size() == 1 && isa<InitListExpr>(Args[0]))) &&
3519 "IsListInit must come with a single initializer list argument.");
3528 assert(DestRecordType &&
"Constructor initialization requires record type");
3530 = cast<CXXRecordDecl>(DestRecordType->
getDecl());
3548 bool AsInitializerList =
false;
3561 AsInitializerList =
true;
3567 CandidateSet, Ctors, Best,
3568 CopyInitialization, AllowExplicit,
3582 AsInitializerList =
false;
3584 CandidateSet, Ctors, Best,
3585 CopyInitialization, AllowExplicit,
3625 bool HadMultipleCandidates = (CandidateSet.size() > 1);
3627 Best->FoundDecl, CtorDecl, DestType, HadMultipleCandidates,
3628 IsListInit | IsInitListCopy, AsInitializerList);
3641 bool HadMultipleCandidates =
false;
3644 UnqualifiedTargetType,
3646 &HadMultipleCandidates)) {
3648 HadMultipleCandidates);
3649 SourceType = Fn->getType();
3681 bool TreatUnavailableAsInvalid) {
3716 bool dummy1, dummy2, dummy3;
3723 T1Quals, cv2T2, T2, T2Quals, Sequence);
3738 TreatUnavailableAsInvalid);
3755 bool TreatUnavailableAsInvalid) {
3767 TreatUnavailableAsInvalid);
3802 if (!isa<VariableArrayType>(DestAT) &&
3812 TreatUnavailableAsInvalid);
3845 TreatUnavailableAsInvalid))
3849 Expr *InitListAsExpr = InitList;
3869 ET && ET->getDecl()->isFixed() &&
3923 TreatUnavailableAsInvalid);
3930 InitListChecker CheckInitList(S, Entity, InitList,
3931 DestType,
true, TreatUnavailableAsInvalid);
3932 if (CheckInitList.HadError()) {
3956 bool ObjCConversion;
3957 bool ObjCLifetimeConversion;
3959 T1, T2, DerivedToBase,
3961 ObjCLifetimeConversion) &&
3962 "Must have incompatible references when binding via conversion");
3963 (void)DerivedToBase;
3964 (void)ObjCConversion;
3965 (void)ObjCLifetimeConversion;
3970 CandidateSet.
clear();
3986 if (!Info.Constructor)
3989 if (!Info.Constructor->isInvalidDecl() &&
3990 Info.Constructor->isConvertingConstructor(AllowExplicit)) {
3991 if (Info.ConstructorTmpl)
3994 Initializer, CandidateSet,
3998 Initializer, CandidateSet,
4003 if (T1RecordType && T1RecordType->
getDecl()->isInvalidDecl())
4014 for (
auto I = Conversions.begin(), E = Conversions.end();
I !=
E; ++
I) {
4016 CXXRecordDecl *ActingDC = cast<CXXRecordDecl>(D->getDeclContext());
4017 if (isa<UsingShadowDecl>(D))
4018 D = cast<UsingShadowDecl>(D)->getTargetDecl();
4025 Conv = cast<CXXConversionDecl>(D);
4033 if ((AllowExplicitConvs || !Conv->isExplicit()) &&
4034 (AllowRValues || Conv->getConversionType()->isLValueReferenceType())){
4037 ActingDC, Initializer,
4038 DestType, CandidateSet,
4043 Initializer, DestType, CandidateSet,
4048 if (T2RecordType && T2RecordType->
getDecl()->isInvalidDecl())
4062 Function->setReferenced();
4065 if (isa<CXXConversionDecl>(Function))
4071 bool HadMultipleCandidates = (CandidateSet.
size() > 1);
4073 T2.getNonLValueExprType(S.
Context),
4074 HadMultipleCandidates);
4079 if (T2->isLValueReferenceType())
4084 bool NewDerivedToBase =
false;
4085 bool NewObjCConversion =
false;
4086 bool NewObjCLifetimeConversion =
false;
4090 NewDerivedToBase, NewObjCConversion,
4091 NewObjCLifetimeConversion);
4099 ICS.
Standard = Best->FinalConversion;
4102 }
else if (NewDerivedToBase)
4107 else if (NewObjCConversion)
4112 if (cv1T1.
getQualifiers() != T2.getNonReferenceType().getQualifiers())
4146 T1Quals, cv2T2, T2, T2Quals, Sequence);
4174 if (IsNonAddressableType) {
4191 if (T1Quals != T2Quals) {
4214 bool DerivedToBase =
false;
4215 bool ObjCConversion =
false;
4216 bool ObjCLifetimeConversion =
false;
4220 ObjCConversion, ObjCLifetimeConversion);
4233 if (isLValueRef || T1Function) {
4250 else if (ObjCConversion)
4256 cv1T1, T1Quals, T2Quals,
4271 (isLValueRef || InitCategory.
isRValue())) {
4273 S, Entity, Kind, Initializer, isRValueRef, Sequence);
4334 else if (ObjCConversion)
4356 S, Entity, Kind, Initializer,
true, Sequence);
4367 isRValueRef && InitCategory.
isLValue()) {
4418 (T1CVRQuals | T2CVRQuals) != T1CVRQuals) {
4451 assert((!InitList || InitList->
getNumInits() == 0) &&
4452 "Shouldn't use value-init for non-empty init lists");
4464 bool NeedZeroInitialization =
true;
4471 if (ClassDecl->hasUserDeclaredConstructor())
4472 NeedZeroInitialization =
false;
4480 NeedZeroInitialization =
false;
4489 if (NeedZeroInitialization)
4503 ClassDecl->hasUninitializedReferenceMember()) {
4511 Expr *InitListAsExpr = InitList;
4513 bool InitListSyntax = InitList;
4538 if (DestType->isRecordType() && S.
getLangOpts().CPlusPlus) {
4548 if (DestType.isConstQualified() && S.
getLangOpts().CPlusPlus) {
4555 if (DestType.getQualifiers().hasObjCLifetime()) {
4569 bool TopLevelOfInitList) {
4570 assert(!DestType->
isReferenceType() &&
"References are handled elsewhere");
4572 assert((DestType->
isRecordType() || SourceType->isRecordType()) &&
4573 "Must have a class type to perform a user-defined conversion");
4578 CandidateSet.
clear();
4588 = cast<CXXRecordDecl>(DestRecordType->getDecl());
4598 Con = CopyOfCon.begin(), ConEnd = CopyOfCon.end();
4599 Con != ConEnd; ++Con) {
4602 if (!Info.Constructor)
4605 if (!Info.Constructor->isInvalidDecl() &&
4606 Info.Constructor->isConvertingConstructor(AllowExplicit)) {
4607 if (Info.ConstructorTmpl)
4610 Initializer, CandidateSet,
4614 Initializer, CandidateSet,
4631 = cast<CXXRecordDecl>(SourceRecordType->getDecl());
4633 const auto &Conversions =
4635 for (
auto I = Conversions.begin(), E = Conversions.end();
I !=
E; ++
I) {
4637 CXXRecordDecl *ActingDC = cast<CXXRecordDecl>(D->getDeclContext());
4638 if (isa<UsingShadowDecl>(D))
4639 D = cast<UsingShadowDecl>(D)->getTargetDecl();
4646 Conv = cast<CXXConversionDecl>(D);
4648 if (AllowExplicit || !Conv->isExplicit()) {
4651 ActingDC, Initializer, DestType,
4652 CandidateSet, AllowExplicit);
4655 Initializer, DestType, CandidateSet,
4673 Function->setReferenced();
4674 bool HadMultipleCandidates = (CandidateSet.
size() > 1);
4676 if (isa<CXXConstructorDecl>(Function)) {
4682 HadMultipleCandidates);
4696 HadMultipleCandidates);
4701 HadMultipleCandidates);
4705 if (Best->FinalConversion.First || Best->FinalConversion.Second ||
4706 Best->FinalConversion.Third) {
4709 ICS.
Standard = Best->FinalConversion;
4727 isa<CXXBoolLiteralExpr>(Init) &&
4728 !cast<CXXBoolLiteralExpr>(Init)->getValue() &&
4737 bool isAddressOf,
bool &isWeakAccess) {
4743 if (op->getOpcode() == UO_AddrOf)
4748 }
else if (
CastExpr *ce = dyn_cast<CastExpr>(e)) {
4749 switch (ce->getCastKind()) {
4752 case CK_LValueBitCast:
4756 case CK_ArrayToPointerDecay:
4759 case CK_NullToPointer:
4767 }
else if (isa<DeclRefExpr>(e)) {
4771 isWeakAccess =
true;
4775 VarDecl *var = dyn_cast<
VarDecl>(cast<DeclRefExpr>(e)->getDecl());
4789 }
else if (isa<ArraySubscriptExpr>(e)) {
4805 bool isWeakAccess =
false;
4809 if (S.
getLangOpts().ObjCAutoRefCount && isWeakAccess)
4815 << ((
unsigned) iik - 1)
4816 << src->getSourceRange();
4840 Expr *Initializer) {
4841 bool ArrayDecay =
false;
4846 ArgPointee = ArgArrayType->getElementType();
4858 bool ShouldCopy =
true;
4860 ShouldCopy = (param->getObjCDeclQualifier() != ParmVarDecl::OBJC_TQ_Out);
4863 if (ArrayDecay || Initializer->
isGLValue()) {
4887 Expr *Initializer) {
4907 Expr *Initializer) {
4921 bool TopLevelOfInitList,
4922 bool TreatUnavailableAsInvalid)
4925 TreatUnavailableAsInvalid);
4932 if (!DRE || !isa<FunctionDecl>(DRE->getDecl()))
4936 cast<FunctionDecl>(DRE->getDecl()));
4943 bool TopLevelOfInitList,
4944 bool TreatUnavailableAsInvalid) {
4951 for (
unsigned I = 0, E = Args.size();
I !=
E; ++
I)
4952 if (Args[
I]->getType()->isNonOverloadPlaceholderType()) {
4959 Args[
I] = result.
get();
4980 Expr *Initializer =
nullptr;
4981 if (Args.size() == 1) {
4982 Initializer = Args[0];
4985 DestType, Initializer->
getType(),
4988 Args[0] = Initializer;
4990 if (!isa<InitListExpr>(Initializer))
4991 SourceType = Initializer->
getType();
4997 if (
InitListExpr *InitList = dyn_cast_or_null<InitListExpr>(Initializer)) {
4999 TreatUnavailableAsInvalid);
5011 if (Args.size() != 1)
5037 if (Initializer && isa<VariableArrayType>(DestAT)) {
5065 isa<CompoundLiteralExpr>(Initializer->
IgnoreParens()) &&
5081 Initializer && isa<InitListExpr>(Initializer)) {
5083 *
this, TreatUnavailableAsInvalid);
5085 }
else if (DestAT->getElementType()->isCharType())
5097 bool allowObjCWritebackConversion = S.
getLangOpts().ObjCAutoRefCount &&
5104 if (allowObjCWritebackConversion &&
5132 S.
IsDerivedFrom(Initializer->getLocStart(), SourceType, DestType))))
5143 TopLevelOfInitList);
5147 if (Args.size() > 1) {
5151 assert(Args.size() == 1 &&
"Zero-argument case handled above");
5158 bool NeedAtomicConversion =
false;
5162 Atomic->getValueType())) {
5163 DestType = Atomic->getValueType();
5164 NeedAtomicConversion =
true;
5169 TopLevelOfInitList);
5171 if (!
Failed() && NeedAtomicConversion)
5188 allowObjCWritebackConversion);
5196 bool ShouldCopy =
true;
5198 ShouldCopy = (Param->getObjCDeclQualifier() != ParmVarDecl::OBJC_TQ_Out);
5212 }
else if (ICS.
isBad()) {
5233 for (
auto &S : Steps)
5252 isa<ObjCMethodDecl>(Entity.
getDecl()->getDeclContext()))
5259 isa<ObjCMethodDecl>(Entity.
getDecl()->getDeclContext()))
5282 llvm_unreachable(
"Invalid EntityKind!");
5311 llvm_unreachable(
"missed an InitializedEntity kind?");
5340 llvm_unreachable(
"missed an InitializedEntity kind?");
5348 Expr *CurInitExpr) {
5355 CI = Ctors.begin(), CE = Ctors.end(); CI != CE; ++CI) {
5358 if (!Info.Constructor)
5361 if (!Info.ConstructorTmpl) {
5363 if (Info.Constructor->isInvalidDecl() ||
5364 !Info.Constructor->isCopyOrMoveConstructor() ||
5365 !Info.Constructor->isConvertingConstructor(
true))
5369 CurInitExpr, CandidateSet);
5374 if (Info.ConstructorTmpl->isInvalidDecl())
5377 if (!Info.Constructor->isConvertingConstructor(
true))
5383 nullptr, CurInitExpr, CandidateSet,
true);
5389 Expr *Initializer) {
5398 return Entity.
getDecl()->getLocation();
5416 return Initializer->getLocStart();
5418 llvm_unreachable(
"missed an InitializedEntity kind?");
5445 bool IsExtraneousCopy) {
5452 Class = cast<CXXRecordDecl>(Record->getDecl());
5485 bool HadMultipleCandidates = (CandidateSet.
size() > 1);
5494 ? diag::ext_rvalue_to_reference_temp_copy_no_viable
5495 : diag::err_temp_copy_no_viable)
5497 << CurInitExpr->getSourceRange();
5504 S.
Diag(Loc, diag::err_temp_copy_ambiguous)
5506 << CurInitExpr->getSourceRange();
5511 S.
Diag(Loc, diag::err_temp_copy_deleted)
5513 << CurInitExpr->getSourceRange();
5525 if (IsExtraneousCopy) {
5539 diag::err_call_incomplete_argument))
5561 HadMultipleCandidates,
5579 Expr *CurInitExpr) {
5593 S, CandidateSet, cast<CXXRecordDecl>(Record->getDecl()), CurInitExpr);
5601 << CurInitExpr->getSourceRange();
5606 Best->FoundDecl, Entity, Diag);
5627 void InitializationSequence::PrintInitLocationNote(
Sema &S,
5630 if (Entity.
getDecl()->getLocation().isInvalid())
5634 S.
Diag(Entity.
getDecl()->getLocation(), diag::note_parameter_named_here)
5637 S.
Diag(Entity.
getDecl()->getLocation(), diag::note_parameter_here);
5642 diag::note_method_return_type_change)
5671 return NumArgs != 1;
5683 bool &ConstructorInitRequiresZeroInit,
5684 bool IsListInitialization,
5685 bool IsStdInitListInitialization,
5688 unsigned NumArgs = Args.size();
5703 assert(Constructor->
getParent() &&
"No parent class for constructor.");
5705 Constructor->
isTrivial() && !Constructor->isUsed(
false))
5724 Loc, ConstructorArgs,
5726 IsListInitialization))
5743 if (
auto *Shadow = dyn_cast<ConstructorUsingShadowDecl>(
5752 S.
Context, Constructor, TSInfo,
5753 ConstructorArgs, ParenOrBraceRange, HadMultipleCandidates,
5754 IsListInitialization, IsStdInitListInitialization,
5755 ConstructorInitRequiresZeroInit);
5771 if (IsListInitialization)
5772 ParenOrBraceRange =
SourceRange(LBraceLoc, RBraceLoc);
5783 HadMultipleCandidates,
5784 IsListInitialization,
5785 IsStdInitListInitialization,
5786 ConstructorInitRequiresZeroInit,
5794 HadMultipleCandidates,
5795 IsListInitialization,
5796 IsStdInitListInitialization,
5797 ConstructorInitRequiresZeroInit,
5852 llvm_unreachable(
"unknown entity kind");
5917 return FallbackDecl;
5926 llvm_unreachable(
"unknown entity kind");
5943 if (
InitListExpr *ILE = dyn_cast<InitListExpr>(Init)) {
5944 if (ILE->getNumInits() == 1 && ILE->isGLValue()) {
5946 Init = ILE->getInit(0);
5954 Init =
const_cast<Expr *
>(
5959 if (
CastExpr *CE = dyn_cast<CastExpr>(Init))
5960 if (CE->getSubExpr()->isGLValue())
5961 Init = CE->getSubExpr();
5966 }
while (Init != Old);
5971 ME->setExtendingDecl(ExtendingEntity->
getDecl(),
5987 Init =
const_cast<Expr *
>(
5991 Init = BTE->getSubExpr();
5994 dyn_cast<CXXStdInitializerListExpr>(Init)) {
5999 if (
InitListExpr *ILE = dyn_cast<InitListExpr>(Init)) {
6000 if (ILE->getType()->isArrayType()) {
6001 for (
unsigned I = 0, N = ILE->getNumInits();
I != N; ++
I)
6006 if (
CXXRecordDecl *RD = ILE->getType()->getAsCXXRecordDecl()) {
6007 assert(RD->isAggregate() &&
"aggregate init on non-aggregate");
6012 if (RD->
isUnion() && ILE->getInitializedFieldInUnion() &&
6013 ILE->getInitializedFieldInUnion()->getType()->isReferenceType())
6017 for (
const auto *
I : RD->
fields()) {
6018 if (Index >= ILE->getNumInits())
6020 if (
I->isUnnamedBitfield())
6022 Expr *SubInit = ILE->getInit(Index);
6023 if (
I->getType()->isReferenceType())
6025 else if (isa<InitListExpr>(SubInit) ||
6026 isa<CXXStdInitializerListExpr>(SubInit))
6039 const Expr *Init,
bool IsInitializerList,
6042 if (isa<FieldDecl>(ExtendingDecl)) {
6043 if (IsInitializerList) {
6044 S.
Diag(Init->
getExprLoc(), diag::warn_dangling_std_initializer_list)
6049 bool IsSubobjectMember =
false;
6053 IsSubobjectMember =
true;
6058 diag::warn_bind_ref_member_to_temporary)
6059 << ExtendingDecl << Init->getSourceRange()
6060 << IsSubobjectMember << IsInitializerList;
6061 if (IsSubobjectMember)
6062 S.
Diag(ExtendingDecl->getLocation(),
6063 diag::note_ref_subobject_of_member_declared_here);
6065 S.
Diag(ExtendingDecl->getLocation(),
6066 diag::note_ref_or_ptr_member_declared_here)
6075 const Expr *PostInit);
6079 bool IsReturnStmt) {
6090 unsigned DiagID = 0;
6109 if (!MoveFunction || !MoveFunction->isInStdNamespace() ||
6135 if (isa<ParmVarDecl>(VD))
6136 DiagID = diag::warn_redundant_move_on_return;
6138 DiagID = diag::warn_pessimizing_move_on_return;
6140 DiagID = diag::warn_pessimizing_move_on_initialization;
6182 if (UO->getOpcode() == UO_Deref &&
6183 UO->getSubExpr()->IgnoreParenCasts()->
6186 S.
PDiag(diag::warn_binding_null_to_reference)
6187 << UO->getSubExpr()->getSourceRange());
6193 bool BoundToLvalueReference) {
6217 if (!ZeroInitializationFixit.empty()) {
6218 unsigned DiagID = diag::err_default_init_const;
6220 if (S.
getLangOpts().MSVCCompat && D->hasAttr<SelectAnyAttr>())
6221 DiagID = diag::ext_default_init_const;
6230 ZeroInitializationFixit);
6249 if (isa<InitListExpr>((
Expr *)Args[0])) {
6255 TypeLoc TL = TInfo->getTypeLoc();
6258 Brackets = ArrayLoc.getBracketsRange();
6265 ArrayT->getSizeModifier(),
6266 ArrayT->getIndexTypeCVRQualifiers(),
6290 Args.size() == 1 && isa<InitListExpr>(Args[0]) &&
6295 Expr *Init = Args[0];
6296 S.
Diag(Init->getLocStart(), diag::warn_cxx98_compat_reference_list_init)
6297 << Init->getSourceRange();
6302 if (Args.size() == 1 && Args[0]->getType()->isArrayType() &&
6305 Expr *Init = Args[0];
6308 S.
Diag(Init->getLocStart(), diag::warn_temporary_array_to_pointer_decay)
6309 << Init->getSourceRange();
6325 switch (Steps.front().Kind) {
6355 assert(Args.size() == 1);
6370 bool ConstructorInitRequiresZeroInit =
false;
6401 CurInit.
get()->getLocStart(),
6402 CurInit.
get()->getSourceRange(),
6403 &BasePath, IgnoreBaseAccess))
6414 CurInit.
get(), &BasePath, VK);
6426 << (BitField !=
nullptr)
6427 << CurInit.
get()->getSourceRange();
6429 S.
Diag(BitField->getLocation(), diag::note_bitfield_decl);
6436 S.
Diag(Kind.
getLocation(), diag::err_reference_bind_to_vector_element)
6438 << CurInit.
get()->getSourceRange();
6439 PrintInitLocationNote(S, Entity);
6457 ExtendingEntity->getDecl());
6464 assert(CurInit.
get()->
isRValue() &&
"not a temporary");
6481 ExtendingEntity->getDecl());
6506 bool IsCopy =
false;
6510 bool CreatedObject =
false;
6522 Loc, ConstructorArgs))
6527 FoundFn, Constructor,
6529 HadMultipleCandidates,
6543 CastKind = CK_ConstructorConversion;
6549 CreatedObject =
true;
6564 FoundFn, Conversion);
6567 CurInit = CurInitExprRes;
6571 HadMultipleCandidates);
6575 CastKind = CK_UserDefinedConversion;
6577 CreatedObject = Conversion->getReturnType()->isRecordType();
6589 S.
PDiag(diag::err_access_dtor_temp) << T);
6599 if (MaybeBindToTemp)
6622 assert(CurInit.
get()->
isRValue() &&
"cannot convert glvalue to atomic");
6629 assert(CurInit.
get()->
isGLValue() &&
"cannot load from a prvalue");
6631 CK_LValueToRValue, CurInit.get(),
6648 CurInit = CurInitExprRes;
6665 InitListChecker PerformInitList(S, InitEntity,
6666 InitList, Ty,
false,
6668 if (PerformInitList.HadError())
6676 if ((*ResultType)->isRValueReferenceType())
6678 else if ((*ResultType)->isLValueReferenceType())
6685 PerformInitList.getFullyStructuredList();
6689 : StructuredInitList;
6703 assert(Args.size() == 1 &&
"expected a single argument for list init");
6705 S.
Diag(InitList->getExprLoc(), diag::warn_cxx98_compat_ctor_list_init)
6706 << InitList->getSourceRange();
6707 MultiExprArg Arg(InitList->getInits(), InitList->getNumInits());
6711 ConstructorInitRequiresZeroInit,
6714 InitList->getLBraceLoc(),
6715 InitList->getRBraceLoc());
6720 CurInit = cast<InitListExpr>(CurInit.
get())->getInit(0);
6746 bool IsStdInitListInit =
6749 S, UseTemporary ? TempEntity : Entity, Kind, Args, *
Step,
6750 ConstructorInitRequiresZeroInit,
6761 if (NextStep != StepEnd &&
6766 ConstructorInitRequiresZeroInit =
true;
6805 CurInit = CurInitExprRes;
6810 InitialCurInit.
get(),
6813 PrintInitLocationNote(S, Entity);
6815 }
else if (Complained)
6816 PrintInitLocationNote(S, Entity);
6829 CK_ObjCObjectLValueCast,
6838 << CurInit.
get()->getSourceRange();
6848 IncompleteDest->getElementType(),
6849 ConstantSource->getSize(),
6860 << CurInit.
get()->getSourceRange();
6878 S.
Diag(CurInit.get()->getExprLoc(),
6879 diag::warn_cxx98_compat_initializer_list_init)
6880 << CurInit.get()->getSourceRange();
6884 CurInit.get()->getType(), CurInit.get(),
6908 "Sampler initialization on non-sampler type.");
6910 QualType SourceType = CurInit.get()->getType();
6913 if (!SourceType->isSamplerT())
6917 llvm_unreachable(
"Invalid EntityKind!");
6924 "Event initialization on non-event type.");
6928 CurInit.get()->getValueKind());
6936 cast<FieldDecl>(Entity.
getDecl())->isBitField())
6938 cast<FieldDecl>(Entity.
getDecl()),
6942 if (
const Expr *E = CurInit.
get()) {
6955 S.
Diag(Loc, diag::err_reference_without_init)
6964 for (
const auto *FI : RD->
fields()) {
6965 if (FI->isUnnamedBitfield())
6969 S.
Diag(Loc, diag::note_value_initialization_here) << RD;
6974 for (
const auto &BI : RD->
bases()) {
6976 S.
Diag(Loc, diag::note_value_initialization_here) << RD;
7031 if (
auto *D = Entity.
getDecl())
7032 Loc = D->getLocation();
7033 S.
Diag(Loc, diag::note_in_reference_temporary_list_initializer) << T;
7037 InitListChecker DiagnoseInitList(S, Entity, InitList, DestType,
7040 assert(DiagnoseInitList.HadError() &&
7041 "Inconsistent init list check result.");
7063 assert(Diagnosed &&
"couldn't find uninitialized reference to diagnose");
7067 <<
SourceRange(Args.front()->getLocStart(), Args.back()->getLocEnd());
7080 S.
Diag(Kind.
getLocation(), diag::err_array_init_narrow_string_into_wchar);
7083 S.
Diag(Kind.
getLocation(), diag::err_array_init_wide_string_into_char);
7087 diag::err_array_init_incompat_wide_string_into_wchar);
7093 ? diag::err_array_init_different_type
7094 : diag::err_array_init_non_constant_array))
7096 << Args[0]->getType()
7097 << Args[0]->getSourceRange();
7115 auto *FD = cast<FunctionDecl>(cast<DeclRefExpr>(Args[0])->getDecl());
7117 Args[0]->getLocStart());
7123 switch (FailedOverloadResult) {
7127 << Args[0]->getType() << DestType
7128 << Args[0]->getSourceRange();
7131 << DestType << Args[0]->getType()
7132 << Args[0]->getSourceRange();
7140 diag::err_typecheck_nonviable_condition_incomplete,
7141 Args[0]->getType(), Args[0]->getSourceRange()))
7144 << Args[0]->getType() << Args[0]->getSourceRange()
7153 << Args[0]->getSourceRange();
7161 llvm_unreachable(
"Inconsistent overload resolution?");
7167 llvm_unreachable(
"Conversion did not fail!");
7172 if (isa<InitListExpr>(Args[0])) {
7174 diag::err_lvalue_reference_bind_to_initlist)
7177 << Args[0]->getSourceRange();
7185 ? diag::err_lvalue_reference_bind_to_temporary
7186 : diag::err_lvalue_reference_bind_to_unrelated)
7189 << Args[0]->getType()
7190 << Args[0]->getSourceRange();
7196 << Args[0]->getSourceRange();
7200 QualType SourceType = Args[0]->getType();
7209 << Args[0]->getSourceRange();
7216 << Args[0]->isLValue()
7217 << Args[0]->getType()
7218 << Args[0]->getSourceRange();
7223 QualType FromType = Args[0]->getType();
7227 << Args[0]->isLValue()
7229 << Args[0]->getSourceRange();
7244 if (InitList && InitList->getNumInits() >= 1) {
7245 R =
SourceRange(InitList->getInit(0)->getLocEnd(), InitList->getLocEnd());
7247 assert(Args.size() > 1 &&
"Expected multiple initializers!");
7248 R =
SourceRange(Args.front()->getLocEnd(), Args.back()->getLocEnd());
7253 S.
Diag(Kind.
getLocation(), diag::err_builtin_func_cast_more_than_one_arg)
7275 ArgsRange =
SourceRange(Args.front()->getLocStart(),
7276 Args.back()->getLocEnd());
7279 assert(Args.size() == 1 &&
7280 "List construction from other than 1 argument.");
7282 Args =
MultiExprArg(InitList->getInits(), InitList->getNumInits());
7287 switch (FailedOverloadResult) {
7290 << DestType << ArgsRange;
7307 InheritedFrom = Inherited.getShadowDecl()->getNominatedBaseClass();
7310 << (InheritedFrom ? 2 : Constructor->isImplicit() ? 1 : 0)
7319 S.
Diag(BaseDecl->getLocation(), diag::note_previous_decl)
7323 << (InheritedFrom ? 2 : Constructor->isImplicit() ? 1 : 0)
7329 diag::note_member_declared_at);
7333 S.
Diag(Record->getDecl()->getLocation(),
7334 diag::note_previous_decl)
7341 << DestType << ArgsRange;
7351 <<
true << DestType << ArgsRange;
7352 llvm_unreachable(
"Inconsistent overload resolution?");
7362 << DestType << ArgsRange;
7365 <<
true << DestType << ArgsRange;
7372 llvm_unreachable(
"Conversion did not fail!");
7386 Constructor->isImplicit() ? 1 : 0)
7390 S.
Diag(Entity.
getDecl()->getLocation(), diag::note_previous_decl)
7400 diag::err_init_incomplete_type);
7422 assert(Ovl ==
OR_Success &&
"Inconsistent overload resolution");
7424 S.
Diag(CtorDecl->getLocation(), diag::note_constructor_declared_here);
7429 PrintInitLocationNote(S, Entity);
7436 OS <<
"Failed sequence: ";
7439 OS <<
"too many initializers for reference";
7443 OS <<
"array requires initializer list";
7447 OS <<
"address of unaddressable function was taken";
7451 OS <<
"array requires initializer list or string literal";
7455 OS <<
"array requires initializer list or wide string literal";
7459 OS <<
"narrow string into wide char array";
7463 OS <<
"wide string into char array";
7467 OS <<
"incompatible wide string into wide char array";
7471 OS <<
"array type mismatch";
7475 OS <<
"non-constant array initializer";
7479 OS <<
"address of overloaded function failed";
7483 OS <<
"overload resolution for reference initialization failed";
7487 OS <<
"non-const lvalue reference bound to temporary";
7491 OS <<
"non-const lvalue reference bound to unrelated type";
7495 OS <<
"rvalue reference bound to an lvalue";
7499 OS <<
"reference initialization drops qualifiers";
7503 OS <<
"reference initialization failed";
7507 OS <<
"conversion failed";
7511 OS <<
"conversion from property failed";
7515 OS <<
"too many initializers for scalar";
7519 OS <<
"referencing binding to initializer list";
7523 OS <<
"initializer list for non-aggregate, non-scalar type";
7527 OS <<
"overloading failed for user-defined conversion";
7531 OS <<
"constructor overloading failed";
7535 OS <<
"default initialization of a const variable";
7539 OS <<
"initialization of incomplete type";
7543 OS <<
"list initialization checker failure";
7547 OS <<
"variable length array has an initializer";
7551 OS <<
"initializer expression isn't contextually valid";
7555 OS <<
"list constructor overloading failed";
7559 OS <<
"list copy initialization chose explicit constructor";
7567 OS <<
"Dependent sequence\n";
7571 OS <<
"Normal sequence: ";
7582 OS <<
"resolve address of overloaded function";
7586 OS <<
"derived-to-base case (rvalue" << S->Type.getAsString() <<
")";
7590 OS <<
"derived-to-base case (xvalue" << S->Type.getAsString() <<
")";
7594 OS <<
"derived-to-base case (lvalue" << S->Type.getAsString() <<
")";
7598 OS <<
"bind reference to lvalue";
7602 OS <<
"bind reference to a temporary";
7606 OS <<
"extraneous C++03 copy to temporary";
7610 OS <<
"user-defined conversion via " << *S->Function.Function;
7614 OS <<
"qualification conversion (rvalue)";
7618 OS <<
"qualification conversion (xvalue)";
7622 OS <<
"qualification conversion (lvalue)";
7626 OS <<
"non-atomic-to-atomic conversion";
7630 OS <<
"load (lvalue to rvalue)";
7634 OS <<
"implicit conversion sequence (";
7640 OS <<
"implicit conversion sequence with narrowing prohibited (";
7646 OS <<
"list aggregate initialization";
7650 OS <<
"unwrap reference initializer list";
7654 OS <<
"rewrap reference initializer list";
7658 OS <<
"constructor initialization";
7662 OS <<
"list initialization via constructor";
7666 OS <<
"zero initialization";
7670 OS <<
"C assignment";
7674 OS <<
"string initialization";
7678 OS <<
"Objective-C object conversion";
7682 OS <<
"array initialization";
7686 OS <<
"parenthesized array initialization";
7690 OS <<
"pass by indirect copy and restore";
7694 OS <<
"pass by indirect restore";
7698 OS <<
"Objective-C object retension";
7702 OS <<
"std::initializer_list from initializer list";
7706 OS <<
"list initialization from std::initializer_list";
7710 OS <<
"OpenCL sampler_t from integer constant";
7714 OS <<
"OpenCL event_t from zero";
7718 OS <<
" [" << S->Type.getAsString() <<
']';
7732 const Expr *PostInit) {
7760 S.
Diag(PostInit->getLocStart(),
7762 ? diag::warn_init_list_type_narrowing
7763 : diag::ext_init_list_type_narrowing)
7764 << PostInit->getSourceRange()
7771 S.
Diag(PostInit->getLocStart(),
7773 ? diag::warn_init_list_constant_narrowing
7774 : diag::ext_init_list_constant_narrowing)
7775 << PostInit->getSourceRange()
7782 S.
Diag(PostInit->getLocStart(),
7784 ? diag::warn_init_list_variable_narrowing
7785 : diag::ext_init_list_variable_narrowing)
7786 << PostInit->getSourceRange()
7793 llvm::raw_svector_ostream OS(StaticCast);
7794 OS <<
"static_cast<";
7801 OS << *TT->getDecl();
7810 S.
Diag(PostInit->getLocStart(), diag::note_init_list_narrowing_silence)
7811 << PostInit->getSourceRange()
7827 assert(InitE &&
"No initialization expression");
7832 return !Seq.Failed();
7839 bool TopLevelOfInitList,
7840 bool AllowExplicit) {
7845 assert(InitE &&
"No initialization expression?");
7848 EqualLoc = InitE->getLocStart();
7855 ExprResult Result = Seq.Perform(*
this, Entity, Kind, InitE);
unsigned getNumElements() const
ObjCIndirectCopyRestoreExpr - Represents the passing of a function argument by indirect copy-restore ...
LValueClassification ClassifyLValue(ASTContext &Ctx) const
Reasons why an expression might not be an l-value.
llvm::iterator_range< base_class_iterator > base_class_range
Represents a single C99 designator.
Perform a derived-to-base cast, producing an lvalue.
Defines the clang::ASTContext interface.
unsigned getNumInits() const
SourceLocation getEnd() const
T getAs() const
Convert to the specified TypeLoc type, returning a null TypeLoc if this TypeLoc is not of the desired...
static bool performReferenceExtension(Expr *Init, const InitializedEntity *ExtendingEntity)
Update a glvalue expression that is used as the initializer of a reference to note that its lifetime ...
FunctionDecl - An instance of this class is created to represent a function declaration or definition...
InitListExpr * WrappingSyntacticList
When Kind = SK_RewrapInitList, the syntactic form of the wrapping list.
const internal::VariadicDynCastAllOfMatcher< Stmt, Expr > expr
Matches expressions.
static DiagnosticBuilder Diag(DiagnosticsEngine *Diags, const LangOptions &Features, FullSourceLoc TokLoc, const char *TokBegin, const char *TokRangeBegin, const char *TokRangeEnd, unsigned DiagID)
Produce a diagnostic highlighting some portion of a literal.
QualType getPromotedIntegerType(QualType PromotableType) const
Return the type that PromotableType will promote to: C99 6.3.1.1p2, assuming that PromotableType is a...
bool Diagnose(Sema &S, const InitializedEntity &Entity, const InitializationKind &Kind, ArrayRef< Expr * > Args)
Diagnose an potentially-invalid initialization sequence.
ArrayRef< NamedDecl * >::const_iterator chain_iterator
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 isConstantArrayType() const
bool isVirtual() const
Determines whether the base class is a virtual base class (or not).
DesignatorKind getKind() const
Simple class containing the result of Sema::CorrectTypo.
unsigned Index
When Kind == EK_ArrayElement, EK_VectorElement, or EK_ComplexElement, the index of the array or vecto...
bool CheckExceptionSpecCompatibility(Expr *From, QualType ToType)
step_iterator step_end() const
Expr * getArg(unsigned Arg)
getArg - Return the specified argument.
void setFromType(QualType T)
Produce an Objective-C object pointer.
A cast other than a C-style cast.
DestructionKind isDestructedType() const
Returns a nonzero value if objects of this type require non-trivial work to clean up after...
QualType getCallResultType() const
Determine the type of an expression that calls this function.
void AddOCLZeroEventStep(QualType T)
Add a step to initialize an OpenCL event_t from a NULL constant.
Initializing char array with wide string literal.
QualType getType() const
Retrieves the type of the base class.
Perform an implicit conversion sequence without narrowing.
An initialization that "converts" an Objective-C object (not a point to an object) to another Objecti...
IdentifierInfo * getIdentifier() const
getIdentifier - Get the identifier that names this declaration, if there is one.
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.
QualType getNonLValueExprType(const ASTContext &Context) const
Determine the type of a (typically non-lvalue) expression with the specified result type...
QualType getQualifiedType(SplitQualType split) const
Un-split a SplitQualType.
const LangOptions & getLangOpts() const
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.
bool allowConstDefaultInit() const
Determine whether declaring a const variable with this type is ok per core issue 253.
SmallVectorImpl< Step >::const_iterator step_iterator
QualType getRValueReferenceType(QualType T) const
Return the uniqued reference to the type for an rvalue reference to the specified type...
CanQualType getSizeType() const
Return the unique type for "size_t" (C99 7.17), defined in <stddef.h>.
Expr * getInit() const
Retrieve the initializer value.
ActionResult< Expr * > ExprResult
ExprResult BuildCXXDefaultArgExpr(SourceLocation CallLoc, FunctionDecl *FD, ParmVarDecl *Param)
BuildCXXDefaultArgExpr - Creates a CXXDefaultArgExpr, instantiating the default expr if needed...
static DesignatedInitExpr * CloneDesignatedInitExpr(Sema &SemaRef, DesignatedInitExpr *DIE)
bool isRecordType() const
UserDefinedConversionSequence UserDefined
When ConversionKind == UserDefinedConversion, provides the details of the user-defined conversion seq...
ConstructorInfo getConstructorInfo(NamedDecl *ND)
SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID)
Emit a diagnostic.
unsigned size() const
Returns the number of designators in this initializer.
uintptr_t Base
When Kind == EK_Base, the base specifier that provides the base class.
AssignConvertType
AssignConvertType - All of the 'assignment' semantic checks return this enum to indicate whether the ...
Not a narrowing conversion.
llvm::iterator_range< conversion_iterator > getVisibleConversionFunctions()
Get all conversion functions visible in current class, including conversion function templates...
bool hasFlexibleArrayMember() const
ParenExpr - This represents a parethesized expression, e.g.
bool CanPerformCopyInitialization(const InitializedEntity &Entity, ExprResult Init)
std::string getAsString() const
static InitializationKind CreateDirect(SourceLocation InitLoc, SourceLocation LParenLoc, SourceLocation RParenLoc)
Create a direct initialization.
QualType getLValueReferenceType(QualType T, bool SpelledAsLValue=true) const
Return the uniqued reference to the type for an lvalue reference to the specified type...
The base class of the type hierarchy.
SourceLocation getEqualLoc() const
Retrieve the location of the equal sign for copy initialization (if present).
static bool tryObjCWritebackConversion(Sema &S, InitializationSequence &Sequence, const InitializedEntity &Entity, Expr *Initializer)
const IncompleteArrayType * getAsIncompleteArrayType(QualType T) const
The entity being initialized is a variable.
InitListExpr * getSyntacticForm() const
Represents an array type, per C99 6.7.5.2 - Array Declarators.
const Expr * getInit() const
NamespaceDecl - 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.
Ambiguous candidates found.
A container of type source information.
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.
The entity being initialized is a base member subobject.
bool isFunctionalCast() const
Determine whether this is a functional-style cast.
List-copy-initialization chose an explicit constructor.
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.
bool HasSideEffects(const ASTContext &Ctx, bool IncludePossibleEffects=true) const
HasSideEffects - This routine returns true for all those expressions which have any effect other than...
Represents a prvalue temporary that is written into memory so that a reference can bind to it...
bool isSpelledAsLValue() const
SourceLocation getDotLoc() const
float __ovld __cnfn distance(float p0, float p1)
Returns the distance between p0 and p1.
void MarkFunctionReferenced(SourceLocation Loc, FunctionDecl *Func, bool MightBeOdrUse=true)
Mark a function referenced, and check whether it is odr-used (C++ [basic.def.odr]p2, C99 6.9p3)
const llvm::APInt & getSize() 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...
static const InitializedEntity * getEntityForTemporaryLifetimeExtension(const InitializedEntity *Entity, const InitializedEntity *FallbackDecl=nullptr)
Determine the declaration which an initialized entity ultimately refers to, for the purpose of lifeti...
Initialize an OpenCL sampler from an integer.
EntityKind getKind() const
Determine the kind of initialization.
static InitializedEntity InitializeBase(ASTContext &Context, const CXXBaseSpecifier *Base, bool IsInheritedVirtualBase, const InitializedEntity *Parent=nullptr)
Create the initialization entity for a base class subobject.
static void LookupCopyAndMoveConstructors(Sema &S, OverloadCandidateSet &CandidateSet, CXXRecordDecl *Class, Expr *CurInitExpr)
Look for copy and move constructors and constructor templates, for copying an object via direct-initi...
VarDecl - An instance of this class is created to represent a variable declaration or definition...
PartialDiagnostic PDiag(unsigned DiagID=0)
Build a partial diagnostic.
ExprResult PerformObjectArgumentInitialization(Expr *From, NestedNameSpecifier *Qualifier, NamedDecl *FoundDecl, CXXMethodDecl *Method)
PerformObjectArgumentInitialization - Perform initialization of the implicit object parameter for the...
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.
DiagnosticsEngine & Diags
const Expr * getCallee() const
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...
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())
SourceRange getParenRange() const
Retrieve the source range containing the locations of the open and closing parentheses for value and ...
SourceLocation getLBracketLoc() const
field_iterator field_begin() const
void resizeInits(const ASTContext &Context, unsigned NumInits)
Specify the number of initializers.
uint64_t getTypeSize(QualType T) const
Return the size of the specified (complete) type T, in bits.
void setInit(unsigned Init, Expr *expr)
Expr * IgnoreImplicit() LLVM_READONLY
IgnoreImplicit - Skip past any implicit AST nodes which might surround this expression.
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...
step_iterator step_begin() const
bool isCopyOrMoveConstructor(unsigned &TypeQuals) const
Determine whether this is a copy or move constructor.
SourceLocation getThrowLoc() const
Determine the location of the 'throw' keyword when initializing an exception object.
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)
bool allowsNRVO() const
Determine whether this initialization allows the named return value optimization, which also applies ...
void setElementIndex(unsigned Index)
If this is already the initializer for an array or vector element, sets the element index...
ParmVarDecl - Represents a parameter to a function.
The entity being initialized is a temporary object.
bool isObjCRetainableType() const
NullPointerConstantKind isNullPointerConstant(ASTContext &Ctx, NullPointerConstantValueDependence NPC) const
isNullPointerConstant - C99 6.3.2.3p3 - Test if this reduces down to a Null pointer constant...
Defines the clang::Expr interface and subclasses for C++ expressions.
Expr * getArrayIndex(const Designator &D) const
bool allowExplicitConversionFunctionsInRefBinding() const
Retrieve whether this initialization allows the use of explicit conversion functions when binding a r...
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.
FieldDecl * getSourceBitField()
If this expression refers to a bit-field, retrieve the declaration of that bit-field.
ExprResult PerformImplicitConversion(Expr *From, QualType ToType, AssignmentAction Action, bool AllowExplicit=false)
PerformImplicitConversion - Perform an implicit conversion of the expression From to the type ToType...
Base wrapper for a particular "section" of type source info.
Expr * IgnoreImpCasts() LLVM_READONLY
IgnoreImpCasts - Skip past any implicit casts which might surround this expression.
Expr * FixOverloadedFunctionReference(Expr *E, DeclAccessPair FoundDecl, FunctionDecl *Fn)
FixOverloadedFunctionReference - E is an expression that refers to a C++ overloaded function (possibl...
RecordDecl - Represents a struct/union/class.
Represents a C99 designated initializer expression.
Construct a std::initializer_list from an initializer list.
Trying to take the address of a function that doesn't support having its address taken.
One of these records is kept for each identifier that is lexed.
static void CheckForNullPointerDereference(Sema &S, const Expr *E)
bool isScalarType() const
Expr * getSubExpr(unsigned Idx) const
static bool isExprAnUnaddressableFunction(Sema &S, const Expr *E)
Tries to get a FunctionDecl out of E.
void RewrapReferenceInitList(QualType T, InitListExpr *Syntactic)
Add steps to unwrap a initializer list for a reference around a single element and rewrap it at the e...
bool isDirectReferenceBinding() const
Determine whether this initialization is a direct reference binding (C++ [dcl.init.ref]).
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
The results of name lookup within a DeclContext.
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...
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 isReferenceType() const
DeclaratorDecl * getDecl() const
Retrieve the variable, parameter, or field being initialized.
QualType getReturnType() const
QualType getExtVectorType(QualType VectorType, unsigned NumElts) const
Return the unique reference to an extended vector type of the specified element type and size...
FieldDecl - An instance of this class is created by Sema::ActOnField to represent a member of a struc...
FunctionDecl * getTemplatedDecl() const
Get the underlying function declaration of the template.
Represents a place-holder for an object not to be initialized by anything.
SourceLocation getReturnLoc() const
Determine the location of the 'return' keyword when initializing the result of a function call...
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 r...
static void warnOnLifetimeExtension(Sema &S, const InitializedEntity &Entity, const Expr *Init, bool IsInitializerList, const ValueDecl *ExtendingDecl)
Rewrap the single-element initializer list for a reference.
unsigned getCVRQualifiers() const
bool hasSameType(QualType T1, QualType T2) const
Determine whether the given types T1 and T2 are equivalent.
void AddOCLSamplerInitStep(QualType T)
Add a step to initialize an OpenCL sampler from an integer constant.
TypeSourceInfo * getTypeSourceInfo() const
Retrieve complete type-source information for the object being constructed, if known.
Ref_Incompatible - The two types are incompatible, so direct reference binding is not possible...
bool refersToVectorElement() const
Returns whether this expression refers to a vector element.
void AddConversionCandidate(CXXConversionDecl *Conversion, DeclAccessPair FoundDecl, CXXRecordDecl *ActingContext, Expr *From, QualType ToType, OverloadCandidateSet &CandidateSet, bool AllowObjCConversionOnExplicit)
AddConversionCandidate - Add a C++ conversion function as a candidate in the candidate set (C++ [over...
void SetOverloadFailure(FailureKind Failure, OverloadingResult Result)
Note that this initialization sequence failed due to failed overload resolution.
QualType getTypeDeclType(const TypeDecl *Decl, const TypeDecl *PrevDecl=nullptr) const
Return the unique reference to the type for the specified type declaration.
bool hasSameUnqualifiedType(QualType T1, QualType T2) const
Determine whether the given types are equivalent after cvr-qualifiers have been removed.
SourceLocation getRParenLoc() const
~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.
Perform initialization via a constructor taking a single std::initializer_list argument.
static bool shouldDestroyTemporary(const InitializedEntity &Entity)
Whether the given entity, when initialized with an object created for that initialization, requires destruction.
Describes an C or C++ initializer list.
bool CanUseDecl(NamedDecl *D, bool TreatUnavailableAsInvalid)
Determine whether the use of this declaration is valid, without emitting diagnostics.
An rvalue reference type, per C++11 [dcl.ref].
bool isCompleteType(SourceLocation Loc, QualType T)
const TargetInfo & getTargetInfo() const
SourceLocation getLocWithOffset(int Offset) const
Return a source location with the specified offset from this SourceLocation.
bool DiagnoseUseOfDecl(NamedDecl *D, SourceLocation Loc, const ObjCInterfaceDecl *UnknownObjCClass=nullptr, bool ObjCPropertyAccess=false)
Determine whether the use of this declaration is valid, and emit any corresponding diagnostics...
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...
const LangOptions & getLangOpts() const
StepKind Kind
The kind of conversion or initialization step we are taking.
SourceRange getRange() const
Retrieve the source range that covers the initialization.
Succeeded, but refers to a deleted function.
ReferenceCompareResult CompareReferenceRelationship(SourceLocation Loc, QualType T1, QualType T2, bool &DerivedToBase, bool &ObjCConversion, bool &ObjCLifetimeConversion)
CompareReferenceRelationship - Compare the two types T1 and T2 to determine whether they are referenc...
Ref_Compatible - The two types are reference-compatible and have equivalent qualifiers (cv1 == cv2)...
unsigned getMinRequiredArguments() const
getMinRequiredArguments - Returns the minimum number of arguments needed to call this function...
OverloadCandidateSet & getFailedCandidateSet()
Retrieve a reference to the candidate set when overload resolution fails.
const CXXRecordDecl * getParent() const
Returns the parent of this method declaration, which is the class in which this method is defined...
bool isDefaulted() const
Whether this function is defaulted per C++0x.
An x-value expression is a reference to an object with independent storage but which can be "moved"...
field_range fields() 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...
bool isObjCLifetimeType() const
Returns true if objects of this type have lifetime semantics under ARC.
const ArrayType * getAsArrayType(QualType T) const
Type Query functions.
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...
SourceLocation getRBraceLoc() const
bool isValueDependent() const
isValueDependent - Determines whether this expression is value-dependent (C++ [temp.dep.constexpr]).
Variable-length array must not have an initializer.
RecordDecl * getDecl() const
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.
Initialization of an incomplete type.
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.
CheckedConversionKind
The kind of conversion being performed.
bool isUnsignedIntegerType() const
Return true if this is an integer type that is unsigned, according to C99 6.2.5p6 [which returns true...
A narrowing conversion, because a constant expression got narrowed.
Unwrap the single-element initializer list for a reference.
FunctionDecl * ResolveAddressOfOverloadedFunction(Expr *AddressOfExpr, QualType TargetType, bool Complain, DeclAccessPair &Found, bool *pHadMultipleCandidates=nullptr)
ResolveAddressOfOverloadedFunction - Try to resolve the address of an overloaded function (C++ [over...
void AddParenthesizedArrayInitStep(QualType T)
Add a parenthesized array initialization step.
Expr * IgnoreParenCasts() LLVM_READONLY
IgnoreParenCasts - Ignore parentheses and casts.
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...
chain_iterator chain_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.
bool isAmbiguous() const
Determine whether this initialization failed due to an ambiguity.
CastExpr - Base class for type casts, including both implicit casts (ImplicitCastExpr) and explicit c...
bool isIncompleteType(NamedDecl **Def=nullptr) const
Types are partitioned into 3 broad categories (C99 6.2.5p1): object types, function types...
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.
NarrowingKind getNarrowingKind(ASTContext &Context, const Expr *Converted, APValue &ConstantValue, QualType &ConstantType) const
Check if this standard conversion sequence represents a narrowing conversion, according to C++11 [dcl...
ExprResult DefaultFunctionArrayLvalueConversion(Expr *E, bool Diagnose=true)
AssignConvertType CheckSingleAssignmentConstraints(QualType LHSType, ExprResult &RHS, bool Diagnose=true, bool DiagnoseCFAudited=false, bool ConvertRHS=true)
Perform initialization via a constructor.
Perform a user-defined conversion, either via a conversion function or via a constructor.
bool isExtVectorType() const
Implicit conversion failed.
detail::InMemoryDirectory::const_iterator I
The entity being initialized is a function parameter.
bool isUnnamedBitfield() const
Determines whether this is an unnamed bitfield.
static void diagnoseListInit(Sema &S, const InitializedEntity &Entity, InitListExpr *InitList)
field_iterator field_end() const
const ArrayType * getAsArrayTypeUnsafe() const
A variant of getAs<> for array types which silently discards qualifiers from the outermost type...
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
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.
void EmitRelatedResultTypeNoteForReturn(QualType destType)
Given that we had incompatible pointer types in a return statement, check whether we're in a method w...
IdentifierInfo * getFieldName() const
Reference binding drops qualifiers.
void AddObjCObjectConversionStep(QualType T)
Add an Objective-C object conversion step, which is always a no-op.
Qualifiers::ObjCLifetime getObjCLifetime() const
Returns lifetime attribute of this type.
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...
Represents a ValueDecl that came out of a declarator.
CastKind
CastKind - The kind of operation required for a conversion.
The return type of classify().
void AddStdInitializerListConstructionStep(QualType T)
Add a step to construct a std::initializer_list object from an initializer list.
static InitializedEntity InitializeMember(FieldDecl *Member, const InitializedEntity *Parent=nullptr)
Create the initialization entity for a member subobject.
static ImplicitCastExpr * Create(const ASTContext &Context, QualType T, CastKind Kind, Expr *Operand, const CXXCastPath *BasePath, ExprValueKind Cat)
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.
NamedDecl * getDecl() const
A narrowing conversion by virtue of the source and destination types.
The entity being initialized is a field of block descriptor for the copied-in c++ object...
ImplicitConversionSequence TryImplicitConversion(Expr *From, QualType ToType, bool SuppressUserConversions, bool AllowExplicit, bool InOverloadResolution, bool CStyle, bool AllowObjCWritebackConversion)
bool isObjCWritebackConversion(QualType FromType, QualType ToType, QualType &ConvertedType)
Determine whether this is an Objective-C writeback conversion, used for parameter passing when perfor...
SourceLocation getEllipsisLoc() const
virtual bool ValidateCandidate(const TypoCorrection &candidate)
Simple predicate used by the default RankCandidate to determine whether to return an edit distance of...
Initializing wide char array with incompatible wide string literal.
InheritedConstructor getInheritedConstructor() const
Get the constructor that this inheriting constructor is based on.
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...
bool isDeleted() const
Whether this function has been deleted.
SourceLocation getLocStart() const LLVM_READONLY
Implicit conversion failed.
llvm::MutableArrayRef< Designator > designators()
ValueDecl - Represent the declaration of a variable (in which case it is an lvalue) a function (in wh...
Expr - This represents one expression.
void setRBraceLoc(SourceLocation Loc)
SourceLocation getLocStart() const LLVM_READONLY
ExprValueKind
The categorization of expression values, currently following the C++11 scheme.
bool isAnyComplexType() const
StorageDuration getStorageDuration() const
Retrieve the storage duration for the materialized temporary.
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 ...
uintptr_t Parameter
When Kind == EK_Parameter, the ParmVarDecl, with the low bit indicating whether the parameter is "con...
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)
Represents a C++ functional cast expression that builds a temporary object.
SourceLocation getLBraceLoc() const
static void performLifetimeExtension(Expr *Init, const InitializedEntity *ExtendingEntity)
Update a prvalue expression that is going to be materialized as a lifetime-extended temporary...
bool isAtomicType() const
Represents a C++ destructor within a class.
Initializing a wide char array with narrow string literal.
void ClearExprs(Sema &Actions)
ClearExprs - Null out any expression references, which prevents them from being 'delete'd later...
void AddProduceObjCObjectStep(QualType T)
Add a step to "produce" an Objective-C object (by retaining it).
SmallVectorImpl< OverloadCandidate >::iterator iterator
Passing zero to a function where OpenCL event_t is expected.
ExprResult VerifyIntegerConstantExpression(Expr *E, llvm::APSInt *Result, VerifyICEDiagnoser &Diagnoser, bool AllowFold=true)
VerifyIntegerConstantExpression - Verifies that an expression is an ICE, and reports the appropriate ...
SourceLocation getLocEnd() const LLVM_READONLY
const ParmVarDecl * getParamDecl(unsigned i) const
SourceLocation getEqualOrColonLoc() const
Retrieve the location of the '=' that precedes the initializer value itself, if present.
bool isInitListConstructor(const CXXConstructorDecl *Ctor)
Determine whether Ctor is an initializer-list constructor, as defined in [dcl.init.list]p2.
Resolve the address of an overloaded function to a specific function declaration. ...
Expr * getArrayRangeStart(const Designator &D) const
Overload resolution succeeded.
void AddArrayInitStep(QualType T)
Add an array initialization step.
The entity being initialized is an exception object that is being thrown.
bool isFloatingType() const
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...
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...
Classification Classify(ASTContext &Ctx) const
Classify - Classify this expression according to the C++11 expression taxonomy.
Ref_Related - The two types are reference-related, which means that their unqualified forms (T1 and T...
bool isInSystemHeader(SourceLocation Loc) const
Returns if a SourceLocation is in a system header.
char __ovld __cnfn min(char x, char y)
Returns y if y < x, otherwise it returns x.
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++ 4.9)
Specifies that a value-dependent expression of integral or dependent type should be considered a null...
bool isExplicit() const
Determine whether this constructor was marked "explicit" or not.
ObjCMethodDecl * getMethodDecl() const
Retrieve the ObjectiveC method being initialized.
void NoteCandidates(Sema &S, OverloadCandidateDisplayKind OCD, ArrayRef< Expr * > Args, StringRef Opc="", SourceLocation Loc=SourceLocation())
PrintOverloadCandidates - When overload resolution fails, prints diagnostic messages containing the c...
bool isDependentType() const
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
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...
static void TryDefaultInitialization(Sema &S, const InitializedEntity &Entity, const InitializationKind &Kind, InitializationSequence &Sequence)
Attempt default initialization (C++ [dcl.init]p6).
void AddTemplateOverloadCandidate(FunctionTemplateDecl *FunctionTemplate, DeclAccessPair FoundDecl, TemplateArgumentListInfo *ExplicitTemplateArgs, ArrayRef< Expr * > Args, OverloadCandidateSet &CandidateSet, bool SuppressUserConversions=false, bool PartialOverloading=false)
Add a C++ function template specialization as a candidate in the candidate set, using template argume...
Initializer has a placeholder type which cannot be resolved by initialization.
UnaryOperator - This represents the unary-expression's (except sizeof and alignof), the postinc/postdec operators from postfix-expression, and various extensions.
SmallVector< ActiveTemplateInstantiation, 16 > ActiveTemplateInstantiations
List of active template instantiations.
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])
An lvalue reference type, per C++11 [dcl.ref].
DeclarationName getDeclName() const
getDeclName - Get the actual, stored name of the declaration, which may be a special name...
class LLVM_ALIGNAS(8) TemplateSpecializationType unsigned NumArgs
Represents a type template specialization; the template must be a class template, a type alias templa...
const IdentifierInfo * getField() const
FailureKind getFailureKind() const
Determine why initialization failed.
QualType getElementType() const
Represents a C++ conversion function within a class.
void AddStringInitStep(QualType T)
Add a string init step.
The result type of a method or function.
Pass an object by indirect restore.
InitKind getKind() const
Determine the initialization kind.
__UINTPTR_TYPE__ uintptr_t
An unsigned integer type with the property that any valid pointer to void can be converted to this ty...
void DefineImplicitDefaultConstructor(SourceLocation CurrentLocation, CXXConstructorDecl *Constructor)
DefineImplicitDefaultConstructor - Checks for feasibility of defining this constructor as the default...
QualType getWideCharType() const
Return the type of wide characters.
void AddZeroInitializationStep(QualType T)
Add a zero-initialization step.
bool hasUninitializedReferenceMember() const
Whether this class or any of its subobjects has any members of reference type which would make value-...
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.
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.
static InitializationKind CreateCopy(SourceLocation InitLoc, SourceLocation EqualLoc, bool AllowExplicitConvs=false)
Create a copy initialization.
InitListExpr * getUpdater() const
FailureKind
Describes why initialization failed.
A narrowing conversion, because a non-constant-expression variable might have got narrowed...
Too many initializers for scalar.
bool isArrayRangeDesignator() const
Lvalue-to-rvalue conversion (C++ 4.1)
List initialization failed at some point.
Perform a conversion adding _Atomic to a type.
void AddListInitializationStep(QualType T)
Add a list-initialization step.
SourceLocation getDotLoc() 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...
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).
Perform a qualification conversion, producing an lvalue.
Integral conversions (C++ 4.7)
void AddLValueToRValueStep(QualType Ty)
Add a new step that performs a load of the given type.
Reference binding to an lvalue.
ExprResult MaybeBindToTemporary(Expr *E)
MaybeBindToTemporary - If the passed in expression has a record type with a non-trivial destructor...
ImplicitConversionSequence - Represents an implicit conversion sequence, which may be a standard conv...
bool isIntegralOrEnumerationType() const
Determine whether this type is an integral or enumeration type.
Expr * getArrayRangeEnd(const Designator &D) const
SequenceKind
Describes the kind of initialization sequence computed.
Encodes a location in the source.
unsigned getNumParams() const
getNumParams - Return the number of parameters this function must have based on its FunctionType...
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of enums...
Reference initialization from an initializer list.
QualType getElementType() const
bool InEnclosingNamespaceSetOf(const DeclContext *NS) const
Test if this context is part of the enclosing namespace set of the context NS, as defined in C++0x [n...
static bool shouldBindAsTemporary(const InitializedEntity &Entity)
Whether we should bind a created object as a temporary when initializing the given entity...
SourceLocation getLocation() const
Retrieve the location at which initialization is occurring.
bool ConversionToObjCStringLiteralCheck(QualType DstType, Expr *&SrcExpr, bool Diagnose=true)
SourceLocation getCaptureLoc() const
Determine the location of the capture when initializing field from a captured variable in a lambda...
bool isValid() const
Return true if this is a valid SourceLocation object.
Expr * getArrayRangeStart() const
FieldDecl * getField() const
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.
static OMPLinearClause * Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc, SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef< Expr * > VL, ArrayRef< Expr * > PL, ArrayRef< Expr * > IL, Expr *Step, Expr *CalcStep, Stmt *PreInit, Expr *PostUpdate)
Creates clause with a list of variables VL and a linear step Step.
ASTContext & getASTContext() const
QualType getDependentSizedArrayType(QualType EltTy, Expr *NumElts, ArrayType::ArraySizeModifier ASM, unsigned IndexTypeQuals, SourceRange Brackets) const
Return a non-unique reference to the type for a dependently-sized array of the specified element type...
bool refersToEnclosingVariableOrCapture() const
Does this DeclRefExpr refer to an enclosing local or a captured variable?
VectorKind getVectorKind() const
llvm::APSInt EvaluateKnownConstInt(const ASTContext &Ctx, SmallVectorImpl< PartialDiagnosticAt > *Diag=nullptr) const
EvaluateKnownConstInt - Call EvaluateAsRValue and return the folded integer.
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.
QualType withConst() const
static InvalidICRKind isInvalidICRSource(ASTContext &C, Expr *e, bool isAddressOf, bool &isWeakAccess)
Determines whether this expression is an acceptable ICR source.
bool isExplicitCast() const
Determine whether this initialization is an explicit cast.
const Designator & getDesignator(unsigned Idx) const
void AddTemplateConversionCandidate(FunctionTemplateDecl *FunctionTemplate, DeclAccessPair FoundDecl, CXXRecordDecl *ActingContext, Expr *From, QualType ToType, OverloadCandidateSet &CandidateSet, bool AllowObjCConversionOnExplicit)
Adds a conversion function template specialization candidate to the overload set, using template argu...
const InitializedEntity * getParent() const
Retrieve the parent of the entity being initialized, when the initialization itself is occurring with...
Initialization of some unused destination type with an initializer list.
The entity being initialized is the result of a function call.
void InitializeFrom(Sema &S, const InitializedEntity &Entity, const InitializationKind &Kind, MultiExprArg Args, bool TopLevelOfInitList, bool TreatUnavailableAsInvalid)
SourceLocation getLBracketLoc() const
Objective-C ARC writeback conversion.
The entity being implicitly initialized back to the formal result type.
SourceLocation getRBracketLoc() const
Zero-initialize the object.
The entity being initialized is the initializer for a compound literal.
const ConstantArrayType * getAsConstantArrayType(QualType T) const
Ref_Compatible_With_Added_Qualification - The two types are reference-compatible with added qualifica...
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...
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...
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...
Describes the kind of initialization being performed, along with location information for tokens rela...
AssignConvertType CheckTransparentUnionArgumentConstraints(QualType ArgType, ExprResult &RHS)
The entity being initialized is an element of an array.
const Type * getBaseElementTypeUnsafe() const
Get the base element type of this type, potentially discarding type qualifiers.
void setAsIdentityConversion()
StandardConversionSequence - Set the standard conversion sequence to the identity conversion...
bool isCStyleOrFunctionalCast() const
Determine whether this initialization is a C-style cast.
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.
Expr ** getInits()
Retrieve the set of initializers.
Overloading for initialization by constructor failed.
QualType getToType(unsigned Idx) const
static bool ResolveOverloadedFunctionForReferenceBinding(Sema &S, Expr *Initializer, QualType &SourceType, QualType &UnqualifiedSourceType, QualType UnqualifiedTargetType, InitializationSequence &Sequence)
SourceLocation getBegin() const
Requests that all candidates be shown.
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.
An optional copy of a temporary object to another temporary object, which is permitted (but not requi...
lookup_result lookup(DeclarationName Name) const
lookup - Find the declarations (if any) with the given Name in this context.
static DesignatedInitExpr * Create(const ASTContext &C, llvm::ArrayRef< Designator > Designators, ArrayRef< Expr * > IndexExprs, SourceLocation EqualOrColonLoc, bool GNUSyntax, Expr *Init)
bool isVectorType() const
void AddAtomicConversionStep(QualType Ty)
Add a new step that performs conversion from non-atomic to atomic type.
bool isPromotableIntegerType() const
More type predicates useful for type checking/promotion.
bool HadMultipleCandidates
void AddPassByIndirectCopyRestoreStep(QualType T, bool shouldCopy)
Add a step to pass an object by indirect copy-restore.
SourceLocation getLocStart() const LLVM_READONLY
bool isVolatileQualified() const
Determine whether this type is volatile-qualified.
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 isIgnored(unsigned DiagID, SourceLocation Loc) const
Determine whether the diagnostic is known to be ignored.
bool refersToBitField() const
Returns true if this expression is a gl-value that potentially refers to a bit-field.
static void CheckStringInit(Expr *Str, QualType &DeclT, const ArrayType *AT, Sema &S)
enum SequenceKind getKind() const
Determine the kind of initialization sequence computed.
MutableArrayRef< Expr * > MultiExprArg
QualType getType() const
Return the type wrapped by this type source info.
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
CXXSpecialMember getSpecialMember(const CXXMethodDecl *MD)
getSpecialMember - get the special member enum for a method.
Pass an object by indirect copy-and-restore.
A POD class for pairing a NamedDecl* with an access specifier.
ExprResult BuildCXXMemberCallExpr(Expr *Exp, NamedDecl *FoundDecl, CXXConversionDecl *Method, bool HadMultipleCandidates)
Represents a C11 generic selection.
Rvalue reference binding to an lvalue.
void SetFailed(FailureKind Failure)
Note that this initialization sequence failed.
decl_iterator - Iterates through the declarations stored within this context.
bool isCStyleCast() const
Determine whether this is a C-style cast.
bool isStr(const char(&Str)[StrLen]) const
Return true if this is the identifier for the specified string.
void diagnoseTypo(const TypoCorrection &Correction, const PartialDiagnostic &TypoDiag, bool ErrorRecovery=true)
ExprResult PerformCopyInitialization(const InitializedEntity &Entity, SourceLocation EqualLoc, ExprResult Init, bool TopLevelOfInitList=false, bool AllowExplicit=false)
Array must be initialized with an initializer list or a string literal.
DeclContextLookupResult LookupConstructors(CXXRecordDecl *Class)
Look up the constructors for the given class.
static bool isInvalid(LocType Loc, bool *Invalid)
Non-constant array initializer.
void setIncompleteTypeFailure(QualType IncompleteType)
Note that this initialization sequence failed due to an incomplete type.
A single step in the initialization sequence.
bool isAggregateType() const
Determines whether the type is a C++ aggregate type or C aggregate or union type. ...
Array must be initialized with an initializer list or a wide string literal.
FunctionDecl * getDirectCallee()
If the callee is a FunctionDecl, return it. Otherwise return 0.
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
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.
bool isTemporaryObject(ASTContext &Ctx, const CXXRecordDecl *TempTy) const
Determine whether the result of this expression is a temporary object of the given class type...
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...
Perform a load from a glvalue, producing an rvalue.
static void checkIndirectCopyRestoreSource(Sema &S, Expr *src)
Check whether the given expression is a valid operand for an indirect copy/restore.
IndirectFieldDecl - An instance of this class is created to represent a field injected from an anonym...
void HandleFunctionTypeMismatch(PartialDiagnostic &PDiag, QualType FromType, QualType ToType)
HandleFunctionTypeMismatch - Gives diagnostic information for differeing function types...
static bool InitializedEntityOutlivesFullExpression(const InitializedEntity &Entity)
Determine whether the specified InitializedEntity definitely has a lifetime longer than the current f...
bool DiagRuntimeBehavior(SourceLocation Loc, const Stmt *Statement, const PartialDiagnostic &PD)
Conditionally issue a diagnostic based on the current evaluation context.
std::string getFixItZeroInitializerForType(QualType T, SourceLocation Loc) const
Get a string to suggest for zero-initialization of a type.
bool isAtStartOfImmediateMacroExpansion(SourceLocation Loc, SourceLocation *MacroBegin=nullptr) const
Returns true if the given MacroID location points at the beginning of the immediate macro expansion...
static FixItHint CreateRemoval(CharSourceRange RemoveRange)
Create a code modification hint that removes the given source range.
Array-to-pointer conversion (C++ 4.2)
std::pair< SourceLocation, SourceLocation > getImmediateExpansionRange(SourceLocation Loc) const
Return the start/end of the expansion information for an expansion location.
QualType getPointerType(QualType T) const
Return the uniqued reference to the type for a pointer to the specified type.
DeclarationName - The name of a declaration.
chain_iterator chain_end() const
static void TryConstructorInitialization(Sema &S, const InitializedEntity &Entity, const InitializationKind &Kind, MultiExprArg Args, QualType DestType, InitializationSequence &Sequence, bool IsListInit=false, bool IsInitListCopy=false)
Attempt initialization by constructor (C++ [dcl.init]), which enumerates the constructors of the init...
static bool IsWideCharCompatible(QualType T, ASTContext &Context)
Check whether T is compatible with a wide character type (wchar_t, char16_t or char32_t).
std::string getAsString(ASTContext &Ctx, QualType Ty) const
StringKind getKind() const
Requests that only viable candidates be shown.
detail::InMemoryDirectory::const_iterator E
bool usesGNUSyntax() const
Determines whether this designated initializer used the deprecated GNU syntax for designated initiali...
DeclaratorDecl * VariableOrMember
When Kind == EK_Variable, or EK_Member, the VarDecl or FieldDecl, respectively.
unsigned getNumArgs() const
getNumArgs - Return the number of actual arguments to this call.
CanQualType getCanonicalType(QualType T) const
Return the canonical (structural) type corresponding to the specified potentially non-canonical type ...
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 isLValueReferenceType() const
Overloading due to reference initialization failed.
Expr * getArrayIndex() const
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspnd...
unsigned getNumArgs() const
bool isParameterKind() const
void setInitializedFieldInUnion(FieldDecl *FD)
DeclClass * getCorrectionDeclAs() const
specific_decl_iterator - Iterates over a subrange of declarations stored in a DeclContext, providing only those that are of type SpecificDecl (or a class derived from it).
Expr * IgnoreParenImpCasts() LLVM_READONLY
IgnoreParenImpCasts - Ignore parentheses and implicit casts.
bool isRValueReferenceType() const
QualType getNonReferenceType() const
If Type is a reference type (e.g., const int&), returns the type that the reference refers to ("const...
static bool isRValueRef(QualType ParamType)
bool isObjCObjectType() const
const CXXBaseSpecifier * getBaseSpecifier() const
Retrieve the base specifier.
QualType getLocalUnqualifiedType() const
Return this type with all of the instance-specific qualifiers removed, but without removing any quali...
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
void setAllToTypes(QualType T)
Complex values, per C99 6.2.5p11.
static bool TryOCLZeroEventInitialization(Sema &S, InitializationSequence &Sequence, QualType DestType, Expr *Initializer)
SourceManager & getSourceManager() const
const T * getAs() const
Member-template getAs<specific type>'.
SourceLocation getLocEnd() const LLVM_READONLY
QualType getCanonicalType() const
Array must be initialized with an initializer list.
static void emitBadConversionNotes(Sema &S, const InitializedEntity &entity, Expr *op)
Emit notes associated with an initialization that failed due to a "simple" conversion failure...
bool isParameterConsumed() const
Determine whether this initialization consumes the parameter.
ObjCEncodeExpr, used for @encode in Objective-C.
bool CheckDerivedToBaseConversion(QualType Derived, QualType Base, SourceLocation Loc, SourceRange Range, CXXCastPath *BasePath=nullptr, bool IgnoreAccess=false)
SourceLocation getFieldLoc() const
Reference binding failed.
SourceLocation getLocStart() const LLVM_READONLY
bool isFunctionType() const
MaterializeTemporaryExpr * CreateMaterializeTemporaryExpr(QualType T, Expr *Temporary, bool BoundToLvalueReference)
Expr * getArg(unsigned Arg)
Return the specified argument.
bool isImplicitlyDeleted(FunctionDecl *FD)
Determine whether the given function is an implicitly-deleted special member function.
Base for LValueReferenceType and RValueReferenceType.
CXXConstructorDecl * getConstructor() const
Get the constructor that this expression will (ultimately) call.
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
AccessResult CheckMemberOperatorAccess(SourceLocation Loc, Expr *ObjectExpr, Expr *ArgExpr, DeclAccessPair FoundDecl)
Checks access to an overloaded member operator, including conversion operators.
bool isTrivial() const
Whether this function is "trivial" in some specialized C++ senses.
static FixItHint CreateInsertion(SourceLocation InsertionLoc, StringRef Code, bool BeforePreviousInsertions=false)
Create a code modification hint that inserts the given code string at a specific location.
void AddDerivedToBaseCastStep(QualType BaseType, ExprValueKind Category)
Add a new step in the initialization that performs a derived-to- base cast.
QualType getTagDeclType(const TagDecl *Decl) const
Return the unique reference to the type for the specified TagDecl (struct/union/class/enum) decl...
void setExprNeedsCleanups(bool SideEffects)
APValue - This class implements a discriminated union of [uninitialized] [APSInt] [APFloat]...
Represents a base class of a C++ class.
static bool TryOCLSamplerInitialization(Sema &S, InitializationSequence &Sequence, QualType DestType, Expr *Initializer)
QualType getType() const
Retrieve type being initialized.
static OverloadingResult ResolveConstructorOverload(Sema &S, SourceLocation DeclLoc, MultiExprArg Args, OverloadCandidateSet &CandidateSet, DeclContext::lookup_result Ctors, OverloadCandidateSet::iterator &Best, bool CopyInitializing, bool AllowExplicit, bool OnlyListConstructors, bool IsListInit)
static SourceLocation getInitializationLoc(const InitializedEntity &Entity, Expr *Initializer)
Get the location at which initialization diagnostics should appear.
bool isDefaultConstructor() const
Whether this constructor is a default constructor (C++ [class.ctor]p5), which can be used to default-...
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...
bool AllowExplicit() const
Retrieve whether this initialization allows the use of explicit constructors.
Reading or writing from this object requires a barrier call.
void AddUserConversionStep(FunctionDecl *Function, DeclAccessPair FoundDecl, QualType T, bool HadMultipleCandidates)
Add a new step invoking a conversion function, which is either a constructor or a conversion function...
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).
void dump() const
Dump a representation of the initialized entity to standard error, for debugging purposes.
Describes the sequence of initializations required to initialize a given object or reference with a s...
void AddOverloadCandidate(FunctionDecl *Function, DeclAccessPair FoundDecl, ArrayRef< Expr * > Args, OverloadCandidateSet &CandidateSet, bool SuppressUserConversions=false, bool PartialOverloading=false, bool AllowExplicit=false)
AddOverloadCandidate - Adds the given function to the set of candidate functions, using the given fun...
QualType getUnqualifiedType() const
Retrieve the unqualified variant of the given type, removing as little sugar as possible.
bool hasArrayFiller() const
Return true if this is an array initializer and its array "filler" has been set.
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.
static ExprValueKind convertQualifiersAndValueKindIfNecessary(Sema &S, InitializationSequence &Sequence, Expr *Initializer, QualType cv1T1, Qualifiers T1Quals, Qualifiers T2Quals, bool IsLValueRef)
Converts the target of reference initialization so that it has the appropriate qualifiers and value k...
bool isObjCObjectPointerType() const
Represents a C array with an unspecified size.
QualType getEncodedType() const
Optional< sema::TemplateDeductionInfo * > isSFINAEContext() const
Determines whether we are currently in a context where template argument substitution failures are no...
Expr * getArrayRangeEnd() const
The entity being initialized is the field that captures a variable in a lambda.
void setSequenceKind(enum SequenceKind SK)
Set the kind of sequence computed.
DeclContext * CurContext
CurContext - This is the current declaration context of parsing.
static void TryValueInitialization(Sema &S, const InitializedEntity &Entity, const InitializationKind &Kind, InitializationSequence &Sequence, InitListExpr *InitList=nullptr)
Attempt value initialization (C++ [dcl.init]p7).
A dependent initialization, which could not be type-checked due to the presence of dependent types or...
QualType getVectorType(QualType VectorType, unsigned NumElts, VectorType::VectorKind VecKind) const
Return the unique reference to a vector type of the specified element type and size.
This class is used for builtin types like 'int'.
bool isImplicitValueInit() const
Determine whether this initialization is an implicit value-initialization, e.g., as occurs during agg...
unsigned allocateManglingNumber() const
OverloadingResult BestViableFunction(Sema &S, SourceLocation Loc, OverloadCandidateSet::iterator &Best, bool UserDefinedConversion=false)
Find the best viable function on this overload set, if it exists.
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 OverloadingResult TryRefInitWithConversionFunction(Sema &S, const InitializedEntity &Entity, const InitializationKind &Kind, Expr *Initializer, bool AllowRValues, InitializationSequence &Sequence)
Try a reference initialization that involves calling a conversion function.
Designator * getDesignator(unsigned Idx)
Reference binding to a temporary.
DeclarationName getName() const
Retrieve the name of the entity being initialized.
static bool hasAnyTypeDependentArguments(ArrayRef< Expr * > Exprs)
hasAnyTypeDependentArguments - Determines if any of the expressions in Exprs is type-dependent.
void reserveInits(const ASTContext &C, unsigned NumInits)
Reserve space for some number of initializers.
static bool isReferenceBinding(const InitializationSequence::Step &s)
void EmitRelatedResultTypeNote(const Expr *E)
If the given expression involves a message send to a method with a related result type...
bool isIncompleteArrayType() const
void AddConstructorInitializationStep(DeclAccessPair FoundDecl, CXXConstructorDecl *Constructor, QualType T, bool HadMultipleCandidates, bool FromInitList, bool AsInitList)
Add a constructor-initialization step.
Designation - Represent a full designation, which is a sequence of designators.
static Sema::AssignmentAction getAssignmentAction(const InitializedEntity &Entity, bool Diagnose=false)
A reference to a declared variable, function, enum, etc.
ExprValueKind getValueKind() const
getValueKind - The value kind that this expression produces.
Designator - A designator in a C99 designated initializer.
QualType getConstantArrayType(QualType EltTy, const llvm::APInt &ArySize, ArrayType::ArraySizeModifier ASM, unsigned IndexTypeQuals) const
Return the unique reference to the type for a constant array of the specified element type...
CXXConstructorDecl * LookupDefaultConstructor(CXXRecordDecl *Class)
Look up the default constructor for the given class.
QualType getElementType() const
The initialization is being done by a delegating constructor.
ExprResult BuildCXXDefaultInitExpr(SourceLocation Loc, FieldDecl *Field)
void AddQualificationConversionStep(QualType Ty, ExprValueKind Category)
Add a new step that performs a qualification conversion to the given type.
bool hasQualifiers() const
Determine whether this type has any qualifiers.
SourceManager & SourceMgr
void clear()
Clear out all of the candidates.
bool hasDefaultConstructor() const
Determine whether this class has any default constructors.
ImplicitConversionKind First
First – The first conversion can be an lvalue-to-rvalue conversion, array-to-pointer conversion...
const Expr * getInit(unsigned Init) const
FieldDecl * getInitializedFieldInUnion()
If this initializes a union, specifies which field in the union to initialize.
No viable function found.
bool isConstructorInitialization() const
Determine whether this initialization is direct call to a constructor.
A failed initialization sequence.
bool isFieldDesignator() const
Array initialization (from an array rvalue).
AccessResult CheckAddressOfMemberAccess(Expr *OvlExpr, DeclAccessPair FoundDecl)
An l-value expression is a reference to an object with independent storage.
Default-initialization of a 'const' object.
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.
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 ...
TypoCorrection CorrectTypo(const DeclarationNameInfo &Typo, Sema::LookupNameKind LookupKind, Scope *S, CXXScopeSpec *SS, std::unique_ptr< CorrectionCandidateCallback > CCC, CorrectTypoKind Mode, DeclContext *MemberContext=nullptr, bool EnteringContext=false, const ObjCObjectPointerType *OPT=nullptr, bool RecordFailure=true)
Try to "correct" a typo in the source code by finding visible declarations whose names are similar to...
NamedDecl - This represents a decl with a name.
void dump() const
Dump a representation of this initialization sequence to standard error, for debugging purposes...
Represents a C array with a specified size that is not an integer-constant-expression.
unsigned getElementIndex() const
If this is an array, vector, or complex number element, get the element's index.
Automatic storage duration (most local variables).
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 isConstQualified() const
Determine whether this type is const-qualified.
static void DiagnoseNarrowingInInitList(Sema &S, const ImplicitConversionSequence &ICS, QualType PreNarrowingType, QualType EntityType, const Expr *PostInit)
bool isNull() const
Return true if this QualType doesn't point to a type yet.
Describes an entity that is being initialized.
void setToType(unsigned Idx, QualType T)
NamespaceDecl * getStdNamespace() const
unsigned getNumDesignators() const
SourceLocation getFieldLoc() const
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.
Array initialization from a parenthesized initializer list.
Represents the canonical version of C arrays with a specified constant size.
bool isArrayDesignator() const
QualType getBaseElementType(const ArrayType *VAT) const
Return the innermost element type of an array type.
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...
static bool maybeRecoverWithZeroInitialization(Sema &S, InitializationSequence &Sequence, const InitializedEntity &Entity)
Tries to add a zero initializer. Returns true if that worked.
bool hasLocalStorage() const
hasLocalStorage - Returns true if a variable with function scope is a non-static local variable...
Non-const lvalue reference binding to a temporary.
Expr * IgnoreParens() LLVM_READONLY
IgnoreParens - Ignore parentheses.
Qualifiers getQualifiers() const
Retrieve the set of qualifiers applied to this type.
bool hasInClassInitializer() const
hasInClassInitializer - Determine whether this member has a C++11 in-class initializer.
bool isPointerType() const
SourceRange getSourceRange() const LLVM_READONLY
static bool isExplicitTemporary(const InitializedEntity &Entity, const InitializationKind &Kind, unsigned NumArgs)
Returns true if the parameters describe a constructor initialization of an explicit temporary object...
StandardConversionSequence - represents a standard conversion sequence (C++ 13.3.3.1.1).