Lines Matching +full:no +full:- +full:dump +full:- +full:oops

1 //===--- SemaInit.cpp - Semantic Analysis for Initializers ----------------===//
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
11 //===----------------------------------------------------------------------===//
45 //===----------------------------------------------------------------------===//
47 //===----------------------------------------------------------------------===//
81 Init = Init->IgnoreParens(); in IsStringInit()
84 if (isa<ObjCEncodeExpr>(Init) && AT->getElementType()->isCharType()) in IsStringInit()
93 Context.getCanonicalType(AT->getElementType()).getUnqualifiedType(); in IsStringInit()
97 return BT && BT->isCharType() && BT->getKind() != BuiltinType::SChar; in IsStringInit()
100 switch (SL->getKind()) { in IsStringInit()
102 // char8_t array can be initialized with a UTF-8 string. in IsStringInit()
103 // - C++20 [dcl.init.string] (DR) in IsStringInit()
105 // by a UTF-8 string literal. in IsStringInit()
106 if (ElemTy->isChar8Type() || in IsStringInit()
114 if (ElemTy->isCharType()) in IsStringInit()
115 return (SL->getKind() == StringLiteralKind::UTF8 && in IsStringInit()
119 if (ElemTy->isChar8Type()) in IsStringInit()
132 if (ElemTy->isCharType() || ElemTy->isChar8Type()) in IsStringInit()
140 if (ElemTy->isCharType() || ElemTy->isChar8Type()) in IsStringInit()
148 if (ElemTy->isCharType() || ElemTy->isChar8Type()) in IsStringInit()
177 E->setType(Ty); in updateStringLiteralType()
178 E->setValueKind(VK_PRValue); in updateStringLiteralType()
189 E->setValueKind(VK_PRValue); in updateGNUCompoundLiteralRValue()
201 D = Parent->getDecl(); in initializingConstexprVariable()
202 Parent = Parent->getParent(); in initializingConstexprVariable()
205 if (const auto *VD = dyn_cast_if_present<VarDecl>(D); VD && VD->isConstexpr()) in initializingConstexprVariable()
218 cast<ConstantArrayType>(Str->getType()->getAsArrayTypeUnsafe()); in CheckStringInit()
219 uint64_t StrLength = ConstantArrayTy->getZExtSize(); in CheckStringInit()
222 if (const StringLiteral *SL = dyn_cast<StringLiteral>(Str->IgnoreParens())) in CheckStringInit()
231 IAT->getElementType(), ConstVal, nullptr, ArraySizeModifier::Normal, 0); in CheckStringInit()
240 // FIXME: Avoid truncation for 64-bit length strings. in CheckStringInit()
242 if (StringLiteral *SL = dyn_cast<StringLiteral>(Str->IgnoreParens())) { in CheckStringInit()
247 if (SL->isPascal()) in CheckStringInit()
248 StrLength--; in CheckStringInit()
252 if (StrLength > CAT->getZExtSize()) in CheckStringInit()
253 S.Diag(Str->getBeginLoc(), in CheckStringInit()
255 << CAT->getZExtSize() << StrLength << Str->getSourceRange(); in CheckStringInit()
258 if (StrLength - 1 > CAT->getZExtSize()) in CheckStringInit()
259 S.Diag(Str->getBeginLoc(), in CheckStringInit()
261 << Str->getSourceRange(); in CheckStringInit()
271 //===----------------------------------------------------------------------===//
273 //===----------------------------------------------------------------------===//
311 bool VerifyOnly; // No diagnostics.
415 // initializers, but ill-formed with C++20 designated initializers. in diagnoseInitOverride()
435 } else if (OldInit->getType().isDestructedType() && !FullyOverwritten) { in diagnoseInitOverride()
444 } else if (!OldInit->getSourceRange().isValid()) { in diagnoseInitOverride()
457 // non-designated initializers or a multi-level designator.) in diagnoseInitOverride()
463 << NewInitRange << FullyOverwritten << OldInit->getType(); in diagnoseInitOverride()
464 SemaRef.Diag(OldInit->getBeginLoc(), diag::note_previous_initializer) in diagnoseInitOverride()
465 << (OldInit->HasSideEffects(SemaRef.Context) && FullyOverwritten) in diagnoseInitOverride()
466 << OldInit->getSourceRange(); in diagnoseInitOverride()
519 SemaRef.Context.getAsArrayType(Entity.getParent()->getType()); in HandleEmbed()
521 ElsCount = Embed->getDataElementCount(); in HandleEmbed()
523 ElsCount = std::min(CAType->getSize().getZExtValue(), in HandleEmbed()
524 ElsCount - CurEmbedIndex); in HandleEmbed()
525 if (ElsCount == Embed->getDataElementCount()) { in HandleEmbed()
533 EmbedExpr(SemaRef.Context, Embed->getLocation(), Embed->getData(), in HandleEmbed()
536 if (CurEmbedIndex >= Embed->getDataElementCount()) { in HandleEmbed()
559 // Retrieves the fully-structured initializer list used for
575 // If there are fewer initializer-clauses in the list than there are in PerformEmptyInit()
579 Entity.getType()->getBaseElementTypeUnsafe()->isRecordType(); in PerformEmptyInit()
586 // We treat this as copy-initialization, because aggregate initialization in PerformEmptyInit()
587 // always performs copy-initialization on its elements. in PerformEmptyInit()
595 InitExpr->setType(SemaRef.Context.VoidTy); in PerformEmptyInit()
600 // shall be value-initialized. in PerformEmptyInit()
607 // std:: for stlport. This is effectively a compiler-side implementation of in PerformEmptyInit()
617 CXXConstructorDecl *CtorDecl = cast<CXXConstructorDecl>(Best->Function); in PerformEmptyInit()
618 CXXRecordDecl *R = CtorDecl->getParent(); in PerformEmptyInit()
620 if (CtorDecl->getMinRequiredArguments() == 0 && in PerformEmptyInit()
621 CtorDecl->isExplicit() && R->getDeclName() && in PerformEmptyInit()
622 SemaRef.SourceMgr.isInSystemHeader(CtorDecl->getLocation())) { in PerformEmptyInit()
624 for (NamespaceDecl *ND = dyn_cast<NamespaceDecl>(R->getDeclContext()); in PerformEmptyInit()
625 ND && !IsInStd; ND = dyn_cast<NamespaceDecl>(ND->getParent())) { in PerformEmptyInit()
626 if (SemaRef.getStdNamespace()->InEnclosingNamespaceSetOf(ND)) in PerformEmptyInit()
630 if (IsInStd && llvm::StringSwitch<bool>(R->getName()) in PerformEmptyInit()
644 SemaRef.Diag(CtorDecl->getLocation(), in PerformEmptyInit()
647 SemaRef.Diag(Entity.getDecl()->getLocation(), in PerformEmptyInit()
659 SemaRef.Diag(Entity.getDecl()->getLocation(), in PerformEmptyInit()
665 Entity.getParent()->isVariableLengthArrayNew(); in PerformEmptyInit()
681 // If we're building a fully-structured list, we'll check this at the end in CheckEmptyInitializable()
683 // that there are no designators so we can just check now. in CheckEmptyInitializable()
696 if (Init >= ILE->getNumInits() || !ILE->getInit(Init)) { in FillInEmptyInitForBase()
699 : PerformEmptyInit(ILE->getEndLoc(), BaseEntity); in FillInEmptyInitForBase()
706 assert(Init < ILE->getNumInits() && "should have been expanded"); in FillInEmptyInitForBase()
707 ILE->setInit(Init, BaseInit.getAs<Expr>()); in FillInEmptyInitForBase()
710 dyn_cast<InitListExpr>(ILE->getInit(Init))) { in FillInEmptyInitForBase()
714 dyn_cast<DesignatedInitUpdateExpr>(ILE->getInit(Init))) { in FillInEmptyInitForBase()
715 FillInEmptyInitializations(BaseEntity, InnerDIUE->getUpdater(), in FillInEmptyInitForBase()
726 SourceLocation Loc = ILE->getEndLoc(); in FillInEmptyInitForField()
727 unsigned NumInits = ILE->getNumInits(); in FillInEmptyInitForField()
731 if (Init >= NumInits || !ILE->getInit(Init)) { in FillInEmptyInitForField()
732 if (const RecordType *RType = ILE->getType()->getAs<RecordType>()) in FillInEmptyInitForField()
733 if (!RType->getDecl()->isUnion()) in FillInEmptyInitForField()
738 assert(!VerifyOnly && "should not fill with no-init in verify-only mode"); in FillInEmptyInitForField()
739 Expr *Filler = new (SemaRef.Context) NoInitExpr(Field->getType()); in FillInEmptyInitForField()
741 ILE->setInit(Init, Filler); in FillInEmptyInitForField()
743 ILE->updateInit(SemaRef.Context, Init, Filler); in FillInEmptyInitForField()
747 // If there are fewer initializer-clauses in the list than there are in FillInEmptyInitForField()
749 // shall be initialized from its brace-or-equal-initializer [...] in FillInEmptyInitForField()
750 if (Field->hasInClassInitializer()) { in FillInEmptyInitForField()
761 ILE->setInit(Init, DIE.get()); in FillInEmptyInitForField()
763 ILE->updateInit(SemaRef.Context, Init, DIE.get()); in FillInEmptyInitForField()
769 if (Field->getType()->isReferenceType()) { in FillInEmptyInitForField()
772 // If an incomplete or empty initializer-list leaves a in FillInEmptyInitForField()
774 // ill-formed. in FillInEmptyInitForField()
776 << Field->getType() in FillInEmptyInitForField()
777 << (ILE->isSyntacticForm() ? ILE : ILE->getSyntacticForm()) in FillInEmptyInitForField()
778 ->getSourceRange(); in FillInEmptyInitForField()
779 SemaRef.Diag(Field->getLocation(), diag::note_uninit_reference_member); in FillInEmptyInitForField()
794 ILE->setInit(Init, MemberInit.getAs<Expr>()); in FillInEmptyInitForField()
800 ILE->updateInit(SemaRef.Context, Init, MemberInit.getAs<Expr>()); in FillInEmptyInitForField()
804 = dyn_cast<InitListExpr>(ILE->getInit(Init))) { in FillInEmptyInitForField()
808 dyn_cast<DesignatedInitUpdateExpr>(ILE->getInit(Init))) { in FillInEmptyInitForField()
809 FillInEmptyInitializations(MemberEntity, InnerDIUE->getUpdater(), in FillInEmptyInitForField()
816 /// with expressions that perform value-initialization of the
825 assert((ILE->getType() != SemaRef.Context.VoidTy) && in FillInEmptyInitializations()
834 // (and therefore some of its properties, such as instantiation-dependence) in FillInEmptyInitializations()
845 Outer->setInit(OuterIndex, Outer->getInit(OuterIndex)); in FillInEmptyInitializations()
851 if (ILE->isTransparent()) in FillInEmptyInitializations()
854 if (const RecordType *RType = ILE->getType()->getAs<RecordType>()) { in FillInEmptyInitializations()
855 const RecordDecl *RDecl = RType->getDecl(); in FillInEmptyInitializations()
856 if (RDecl->isUnion() && ILE->getInitializedFieldInUnion()) { in FillInEmptyInitializations()
857 FillInEmptyInitForField(0, ILE->getInitializedFieldInUnion(), Entity, ILE, in FillInEmptyInitializations()
860 assert((!RDecl->isUnion() || !isa<CXXRecordDecl>(RDecl) || in FillInEmptyInitializations()
861 !cast<CXXRecordDecl>(RDecl)->hasInClassInitializer()) && in FillInEmptyInitializations()
863 // The fields beyond ILE->getNumInits() are default initialized, so in in FillInEmptyInitializations()
866 unsigned NumElems = numStructUnionElements(ILE->getType()); in FillInEmptyInitializations()
867 if (!RDecl->isUnion() && RDecl->hasFlexibleArrayMember()) in FillInEmptyInitializations()
869 if (!VerifyOnly && ILE->getNumInits() < NumElems) in FillInEmptyInitializations()
870 ILE->resizeInits(SemaRef.Context, NumElems); in FillInEmptyInitializations()
875 for (auto &Base : CXXRD->bases()) { in FillInEmptyInitializations()
885 for (auto *Field : RDecl->fields()) { in FillInEmptyInitializations()
886 if (Field->isUnnamedBitField()) in FillInEmptyInitializations()
900 if (RDecl->isUnion()) in FillInEmptyInitializations()
911 unsigned NumInits = ILE->getNumInits(); in FillInEmptyInitializations()
913 if (const ArrayType *AType = SemaRef.Context.getAsArrayType(ILE->getType())) { in FillInEmptyInitializations()
914 ElementType = AType->getElementType(); in FillInEmptyInitializations()
916 NumElements = CAType->getZExtSize(); in FillInEmptyInitializations()
923 } else if (const VectorType *VType = ILE->getType()->getAs<VectorType>()) { in FillInEmptyInitializations()
924 ElementType = VType->getElementType(); in FillInEmptyInitializations()
925 NumElements = VType->getNumElements(); in FillInEmptyInitializations()
929 ElementType = ILE->getType(); in FillInEmptyInitializations()
940 if (Init >= NumInits && (ILE->hasArrayFiller() || SkipEmptyInitChecks)) in FillInEmptyInitializations()
943 Expr *InitExpr = (Init < NumInits ? ILE->getInit(Init) : nullptr); in FillInEmptyInitializations()
944 if (!InitExpr && Init < NumInits && ILE->hasArrayFiller()) in FillInEmptyInitializations()
945 ILE->setInit(Init, ILE->getArrayFiller()); in FillInEmptyInitializations()
946 else if (!InitExpr && !ILE->hasArrayFiller()) { in FillInEmptyInitializations()
947 // In VerifyOnly mode, there's no point performing empty initialization in FillInEmptyInitializations()
958 PerformEmptyInit(ILE->getEndLoc(), ElementEntity); in FillInEmptyInitializations()
972 // For arrays, just set the expression used for value-initialization in FillInEmptyInitializations()
975 ILE->setArrayFiller(Filler); in FillInEmptyInitializations()
977 ILE->setInit(Init, Filler); in FillInEmptyInitializations()
979 // For arrays, just set the expression used for value-initialization in FillInEmptyInitializations()
982 ILE->setArrayFiller(Filler); in FillInEmptyInitializations()
991 ILE->updateInit(SemaRef.Context, Init, Filler); in FillInEmptyInitializations()
1001 FillInEmptyInitializations(ElementEntity, InnerDIUE->getUpdater(), in FillInEmptyInitializations()
1025 createInitListExpr(T, IL->getSourceRange(), IL->getNumInits()); in InitListChecker()
1030 FullyStructuredList->setSyntacticForm(IL); in InitListChecker()
1045 FullyStructuredList->markError(); in InitListChecker()
1053 maxElements = static_cast<int>(CAT->getZExtSize()); in numArrayElements()
1059 RecordDecl *structDecl = DeclType->castAs<RecordType>()->getDecl(); in numStructUnionElements()
1062 InitializableMembers += CXXRD->getNumBases(); in numStructUnionElements()
1063 for (const auto *Field : structDecl->fields()) in numStructUnionElements()
1064 if (!Field->isUnnamedBitField()) in numStructUnionElements()
1067 if (structDecl->isUnion()) in numStructUnionElements()
1069 return InitializableMembers - structDecl->hasFlexibleArrayMember(); in numStructUnionElements()
1073 if (const auto *RT = DeclType->getAs<RecordType>()) in getRecordDecl()
1074 return RT->getDecl(); in getRecordDecl()
1075 if (const auto *Inject = DeclType->getAs<InjectedClassNameType>()) in getRecordDecl()
1076 return Inject->getDecl(); in getRecordDecl()
1097 Entity.getParent()->getType()->castAs<RecordType>()->getDecl(); in isIdiomaticBraceElisionEntity()
1099 return CXXRD->getNumBases() == 1 && CXXRD->field_empty(); in isIdiomaticBraceElisionEntity()
1105 Entity.getParent()->getType()->castAs<RecordType>()->getDecl(); in isIdiomaticBraceElisionEntity()
1107 if (CXXRD->getNumBases()) { in isIdiomaticBraceElisionEntity()
1111 auto FieldIt = ParentRD->field_begin(); in isIdiomaticBraceElisionEntity()
1112 assert(FieldIt != ParentRD->field_end() && in isIdiomaticBraceElisionEntity()
1113 "no fields but have initializer for member?"); in isIdiomaticBraceElisionEntity()
1114 return ++FieldIt == ParentRD->field_end(); in isIdiomaticBraceElisionEntity()
1125 /// onwards, with the fully-braced, desugared form of the initialization.
1133 if (T->isArrayType()) in CheckImplicitInitList()
1135 else if (T->isRecordType()) in CheckImplicitInitList()
1137 else if (T->isVectorType()) in CheckImplicitInitList()
1138 maxElements = T->castAs<VectorType>()->getNumElements(); in CheckImplicitInitList()
1144 SemaRef.Diag(ParentIList->getInit(Index)->getBeginLoc(), in CheckImplicitInitList()
1154 SourceRange(ParentIList->getInit(Index)->getBeginLoc(), in CheckImplicitInitList()
1155 ParentIList->getSourceRange().getEnd())); in CheckImplicitInitList()
1166 StructuredSubobjectInitList->setType(T); in CheckImplicitInitList()
1168 unsigned EndIndex = (Index == StartIndex? StartIndex : Index - 1); in CheckImplicitInitList()
1169 // Update the structured sub-object initializer so that it's ending in CheckImplicitInitList()
1171 if (EndIndex < ParentIList->getNumInits() && in CheckImplicitInitList()
1172 ParentIList->getInit(EndIndex)) { in CheckImplicitInitList()
1174 = ParentIList->getInit(EndIndex)->getSourceRange().getEnd(); in CheckImplicitInitList()
1175 StructuredSubobjectInitList->setRBraceLoc(EndLoc); in CheckImplicitInitList()
1179 if (!VerifyOnly && (T->isArrayType() || T->isRecordType()) && in CheckImplicitInitList()
1180 !ParentIList->isIdiomaticZeroInitializer(SemaRef.getLangOpts()) && in CheckImplicitInitList()
1182 SemaRef.Diag(StructuredSubobjectInitList->getBeginLoc(), in CheckImplicitInitList()
1184 << StructuredSubobjectInitList->getSourceRange() in CheckImplicitInitList()
1186 StructuredSubobjectInitList->getBeginLoc(), "{") in CheckImplicitInitList()
1189 StructuredSubobjectInitList->getEndLoc()), in CheckImplicitInitList()
1194 auto *CXXRD = T->getAsCXXRecordDecl(); in CheckImplicitInitList()
1195 if (!VerifyOnly && CXXRD && CXXRD->hasUserDeclaredConstructor()) { in CheckImplicitInitList()
1196 SemaRef.Diag(StructuredSubobjectInitList->getBeginLoc(), in CheckImplicitInitList()
1198 << StructuredSubobjectInitList->getSourceRange() << T; in CheckImplicitInitList()
1204 /// single-element braced initializer list.
1208 // non-dependent, we warned during the initial parse; otherwise, the in warnBracedScalarInit()
1237 // No warning, might be direct-list-initialization. in warnBracedScalarInit()
1238 // FIXME: Should we warn for copy-list-initialization in these cases? in warnBracedScalarInit()
1244 // No warning, braces are part of the syntax of the underlying construct. in warnBracedScalarInit()
1248 // No warning, we already warned when initializing the result. in warnBracedScalarInit()
1263 << Entity.getType()->isSizelessBuiltinType() << Braces in warnBracedScalarInit()
1272 /// This also fills in \p StructuredList with the fully-braced, desugared
1283 if (!ExprTy->isArrayType()) in CheckExplicitInitList()
1286 IList->setType(ExprTy); in CheckExplicitInitList()
1287 StructuredList->setType(ExprTy); in CheckExplicitInitList()
1293 if (Index < IList->getNumInits() && !T->isIncompleteType()) { in CheckExplicitInitList()
1296 (SemaRef.getLangOpts().OpenCL && T->isVectorType()); in CheckExplicitInitList()
1301 IsStringInit(StructuredList->getInit(0), T, SemaRef.Context) == in CheckExplicitInitList()
1307 SemaRef.Diag(IList->getInit(Index)->getBeginLoc(), DK) in CheckExplicitInitList()
1308 << IList->getInit(Index)->getSourceRange(); in CheckExplicitInitList()
1309 } else if (T->isSizelessBuiltinType()) { in CheckExplicitInitList()
1313 SemaRef.Diag(IList->getInit(Index)->getBeginLoc(), DK) in CheckExplicitInitList()
1314 << T << IList->getInit(Index)->getSourceRange(); in CheckExplicitInitList()
1316 int initKind = T->isArrayType() ? 0 : in CheckExplicitInitList()
1317 T->isVectorType() ? 1 : in CheckExplicitInitList()
1318 T->isScalarType() ? 2 : in CheckExplicitInitList()
1319 T->isUnionType() ? 3 : in CheckExplicitInitList()
1324 SemaRef.Diag(IList->getInit(Index)->getBeginLoc(), DK) in CheckExplicitInitList()
1325 << initKind << IList->getInit(Index)->getSourceRange(); in CheckExplicitInitList()
1330 if (T->isScalarType() && IList->getNumInits() == 1 && in CheckExplicitInitList()
1331 !isa<InitListExpr>(IList->getInit(0))) in CheckExplicitInitList()
1332 warnBracedScalarInit(SemaRef, Entity, IList->getSourceRange()); in CheckExplicitInitList()
1336 auto *CXXRD = T->getAsCXXRecordDecl(); in CheckExplicitInitList()
1337 if (CXXRD && CXXRD->hasUserDeclaredConstructor()) { in CheckExplicitInitList()
1341 if (IList->getNumInits() == 0) { in CheckExplicitInitList()
1343 HasEquivCtor = CD && !CD->isDeleted(); in CheckExplicitInitList()
1347 SemaRef.Diag(IList->getBeginLoc(), in CheckExplicitInitList()
1349 << IList->getSourceRange() << T; in CheckExplicitInitList()
1363 if (DeclType->isAnyComplexType() && SubobjectIsDesignatorContext) { in CheckListElementTypes()
1368 } else if (DeclType->isScalarType()) { in CheckListElementTypes()
1371 } else if (DeclType->isVectorType()) { in CheckListElementTypes()
1378 if (DeclType->isRecordType()) { in CheckListElementTypes()
1379 assert(DeclType->isAggregateType() && in CheckListElementTypes()
1380 "non-aggregate records should be handed in CheckSubElementType"); in CheckListElementTypes()
1382 Bases = CXXRD->bases(); in CheckListElementTypes()
1384 Bases = cast<CXXRecordDecl>(RD)->bases(); in CheckListElementTypes()
1386 CheckStructUnionTypes(Entity, IList, DeclType, Bases, RD->field_begin(), in CheckListElementTypes()
1389 } else if (DeclType->isArrayType()) { in CheckListElementTypes()
1396 } else if (DeclType->isVoidType() || DeclType->isFunctionType()) { in CheckListElementTypes()
1400 SemaRef.Diag(IList->getBeginLoc(), diag::err_illegal_initializer_type) in CheckListElementTypes()
1403 } else if (DeclType->isReferenceType()) { in CheckListElementTypes()
1406 } else if (DeclType->isObjCObjectType()) { in CheckListElementTypes()
1408 SemaRef.Diag(IList->getBeginLoc(), diag::err_init_objc_class) << DeclType; in CheckListElementTypes()
1410 } else if (DeclType->isOCLIntelSubgroupAVCType() || in CheckListElementTypes()
1411 DeclType->isSizelessBuiltinType()) { in CheckListElementTypes()
1415 } else if (DeclType->isDependentType()) { in CheckListElementTypes()
1418 // dependent non-array type or an array type with a value-dependent bound in CheckListElementTypes()
1421 AggrDeductionCandidateParamTypes->push_back(DeclType); in CheckListElementTypes()
1424 SemaRef.Diag(IList->getBeginLoc(), diag::err_illegal_initializer_type) in CheckListElementTypes()
1437 Expr *expr = IList->getInit(Index); in CheckSubElementType()
1439 if (ElemType->isReferenceType()) in CheckSubElementType()
1444 if (SubInitList->getNumInits() == 1 && in CheckSubElementType()
1445 IsStringInit(SubInitList->getInit(0), ElemType, SemaRef.Context) == in CheckSubElementType()
1447 // FIXME: It would be more faithful and no less correct to include an in CheckSubElementType()
1449 expr = SubInitList->getInit(0); in CheckSubElementType()
1455 assert(SemaRef.Context.hasSameType(expr->getType(), ElemType) && in CheckSubElementType()
1464 // Each member is copy-initialized from the corresponding in CheckSubElementType()
1465 // initializer-clause. in CheckSubElementType()
1469 InitializationKind::CreateCopy(expr->getBeginLoc(), SourceLocation()); in CheckSubElementType()
1475 (ElemType->isExtVectorType() && !Entity.getType()->isExtVectorType()) in CheckSubElementType()
1479 if (TmpEntity.getType()->isDependentType()) { in CheckSubElementType()
1482 // dependent non-array type or an array type with a value-dependent in CheckSubElementType()
1486 // In the presence of a braced-init-list within the initializer, we should in CheckSubElementType()
1487 // not perform brace-elision, even if brace elision would otherwise be in CheckSubElementType()
1502 AggrDeductionCandidateParamTypes->push_back(ElemType); in CheckSubElementType()
1509 // If the assignment-expression can initialize a member, the member is in CheckSubElementType()
1513 // assignment-expression. in CheckSubElementType()
1534 AggrDeductionCandidateParamTypes->push_back(ElemType); in CheckSubElementType()
1540 } else if (ElemType->isScalarType() || ElemType->isAtomicType()) { in CheckSubElementType()
1551 // FIXME: Should we do this checking in verify-only mode? in CheckSubElementType()
1565 assert((ElemType->isRecordType() || ElemType->isVectorType() || in CheckSubElementType()
1566 ElemType->isOpenCLSpecificType()) && "Unexpected type"); in CheckSubElementType()
1597 // [...] Otherwise, if the member is itself a non-empty in CheckSubElementType()
1602 if ((!SemaRef.getLangOpts().OpenCL && ElemType->isVectorType()) || in CheckSubElementType()
1603 ElemType->isAggregateType()) { in CheckSubElementType()
1613 SemaRef.Diag(expr->getBeginLoc(), in CheckSubElementType()
1615 << expr->getSourceRange() in CheckSubElementType()
1616 << FixItHint::CreateInsertion(expr->getBeginLoc(), "{") in CheckSubElementType()
1618 SemaRef.getLocForEndOfToken(expr->getEndLoc()), "}"); in CheckSubElementType()
1631 "expected non-aggregate initialization to fail"); in CheckSubElementType()
1647 // a complex number component-wise. When an explicit initializer list for in CheckComplexType()
1653 if (IList->getNumInits() < 2) in CheckComplexType()
1660 SemaRef.Diag(IList->getBeginLoc(), diag::ext_complex_component_init) in CheckComplexType()
1661 << IList->getSourceRange(); in CheckComplexType()
1664 QualType elementType = DeclType->castAs<ComplexType>()->getElementType(); in CheckComplexType()
1680 if (Index >= IList->getNumInits()) { in CheckScalarType()
1683 if (DeclType->isSizelessBuiltinType()) in CheckScalarType()
1684 SemaRef.Diag(IList->getBeginLoc(), in CheckScalarType()
1688 << DeclType << IList->getSourceRange(); in CheckScalarType()
1690 SemaRef.Diag(IList->getBeginLoc(), in CheckScalarType()
1694 << IList->getSourceRange(); in CheckScalarType()
1704 Expr *expr = IList->getInit(Index); in CheckScalarType()
1709 SemaRef.Diag(SubIList->getBeginLoc(), diag::ext_many_braces_around_init) in CheckScalarType()
1710 << DeclType->isSizelessBuiltinType() << SubIList->getSourceRange(); in CheckScalarType()
1717 SemaRef.Diag(expr->getBeginLoc(), in CheckScalarType()
1719 << DeclType->isSizelessBuiltinType() << DeclType in CheckScalarType()
1720 << expr->getSourceRange(); in CheckScalarType()
1737 SemaRef.PerformCopyInitialization(Entity, expr->getBeginLoc(), expr, in CheckScalarType()
1751 IList->setInit(Index, ResultExpr); in CheckScalarType()
1759 AggrDeductionCandidateParamTypes->push_back(DeclType); in CheckScalarType()
1767 if (Index >= IList->getNumInits()) { in CheckReferenceType()
1773 SemaRef.Diag(IList->getBeginLoc(), in CheckReferenceType()
1775 << DeclType << IList->getSourceRange(); in CheckReferenceType()
1782 Expr *expr = IList->getInit(Index); in CheckReferenceType()
1785 SemaRef.Diag(IList->getBeginLoc(), diag::err_init_non_aggr_init_list) in CheckReferenceType()
1786 << DeclType << IList->getSourceRange(); in CheckReferenceType()
1801 SemaRef.PerformCopyInitialization(Entity, expr->getBeginLoc(), expr, in CheckReferenceType()
1811 IList->setInit(Index, expr); in CheckReferenceType()
1816 AggrDeductionCandidateParamTypes->push_back(DeclType); in CheckReferenceType()
1824 const VectorType *VT = DeclType->castAs<VectorType>(); in CheckVectorType()
1825 unsigned maxElements = VT->getNumElements(); in CheckVectorType()
1827 QualType elementType = VT->getElementType(); in CheckVectorType()
1829 if (Index >= IList->getNumInits()) { in CheckVectorType()
1830 // Make sure the element type can be value-initialized. in CheckVectorType()
1833 IList->getEndLoc()); in CheckVectorType()
1838 // If the initializing element is a vector, try to copy-initialize in CheckVectorType()
1840 Expr *Init = IList->getInit(Index); in CheckVectorType()
1841 if (!isa<InitListExpr>(Init) && Init->getType()->isVectorType()) { in CheckVectorType()
1850 SemaRef.PerformCopyInitialization(Entity, Init->getBeginLoc(), Init, in CheckVectorType()
1863 IList->setInit(Index, ResultExpr); in CheckVectorType()
1869 AggrDeductionCandidateParamTypes->push_back(elementType); in CheckVectorType()
1878 if (Index >= IList->getNumInits()) { in CheckVectorType()
1879 CheckEmptyInitializable(ElementEntity, IList->getEndLoc()); in CheckVectorType()
1892 const VectorType *T = Entity.getType()->castAs<VectorType>(); in CheckVectorType()
1893 if (isBigEndian && (T->getVectorKind() == VectorKind::Neon || in CheckVectorType()
1894 T->getVectorKind() == VectorKind::NeonPoly)) { in CheckVectorType()
1903 // Because of this, explicitly call out that it is non-portable. in CheckVectorType()
1905 SemaRef.Diag(IList->getBeginLoc(), in CheckVectorType()
1911 if (elementType->isFloatingType()) in CheckVectorType()
1913 else if (elementType->isSignedIntegerType()) in CheckVectorType()
1915 else if (elementType->isUnsignedIntegerType()) in CheckVectorType()
1920 SemaRef.Diag(IList->getBeginLoc(), in CheckVectorType()
1936 if (Index >= IList->getNumInits()) in CheckVectorType()
1941 QualType IType = IList->getInit(Index)->getType(); in CheckVectorType()
1942 if (!IType->isVectorType()) { in CheckVectorType()
1948 const VectorType *IVT = IType->castAs<VectorType>(); in CheckVectorType()
1949 unsigned numIElts = IVT->getNumElements(); in CheckVectorType()
1951 if (IType->isExtVectorType()) in CheckVectorType()
1955 IVT->getVectorKind()); in CheckVectorType()
1965 SemaRef.Diag(IList->getBeginLoc(), in CheckVectorType()
1984 auto *CXXRD = ElementType->getAsCXXRecordDecl(); in checkDestructorReference()
2004 InitType = Parent->getType(); in canInitializeArrayWithEmbedDataString()
2005 Parent = Parent->getParent(); in canInitializeArrayWithEmbedDataString()
2011 ? dyn_cast_if_present<EmbedExpr>(ExprList[0]->IgnoreParens()) in canInitializeArrayWithEmbedDataString()
2016 if (InitType->isArrayType()) { in canInitializeArrayWithEmbedDataString()
2017 const ArrayType *InitArrayType = InitType->getAsArrayTypeUnsafe(); in canInitializeArrayWithEmbedDataString()
2018 QualType InitElementTy = InitArrayType->getElementType(); in canInitializeArrayWithEmbedDataString()
2019 QualType EmbedExprElementTy = EE->getDataStringLiteral()->getType(); in canInitializeArrayWithEmbedDataString()
2022 (InitElementTy->isCharType() && EmbedExprElementTy->isCharType()); in canInitializeArrayWithEmbedDataString()
2039 if (checkDestructorReference(arrayType->getElementType(), in CheckArrayType()
2040 IList->getEndLoc(), SemaRef)) { in CheckArrayType()
2046 if (canInitializeArrayWithEmbedDataString(IList->inits(), Entity, in CheckArrayType()
2048 EmbedExpr *Embed = cast<EmbedExpr>(IList->inits()[0]); in CheckArrayType()
2049 IList->setInit(0, Embed->getDataStringLiteral()); in CheckArrayType()
2052 // Check for the special-case of initializing an array with a string. in CheckArrayType()
2053 if (Index < IList->getNumInits()) { in CheckArrayType()
2054 if (IsStringInit(IList->getInit(Index), arrayType, SemaRef.Context) == in CheckArrayType()
2061 // FIXME: Should we do these checks in verify-only mode too? in CheckArrayType()
2063 CheckStringInit(IList->getInit(Index), DeclType, arrayType, SemaRef, in CheckArrayType()
2068 IList->getInit(Index)); in CheckArrayType()
2069 StructuredList->resizeInits(SemaRef.Context, StructuredIndex); in CheckArrayType()
2073 AggrDeductionCandidateParamTypes->push_back(DeclType); in CheckArrayType()
2081 bool HasErr = IList->getNumInits() != 0 || SemaRef.getLangOpts().CPlusPlus; in CheckArrayType()
2090 // init a VLA in C++ in all cases (such as with non-trivial constructors). in CheckArrayType()
2094 SemaRef.Diag(VAT->getSizeExpr()->getBeginLoc(), in CheckArrayType()
2096 << VAT->getSizeExpr()->getSourceRange(); in CheckArrayType()
2109 maxElements = CAT->getSize(); in CheckArrayType()
2115 QualType elementType = arrayType->getElementType(); in CheckArrayType()
2116 while (Index < IList->getNumInits()) { in CheckArrayType()
2117 Expr *Init = IList->getInit(Index); in CheckArrayType()
2162 if ((CurEmbed || isa<EmbedExpr>(Init)) && elementType->isScalarType()) { in CheckArrayType()
2165 elementIndex + CurEmbedIndex - EmbedElementIndexBeforeInit - 1; in CheckArrayType()
2168 elementIndex = elementIndex + Embed->getDataElementCount() - in CheckArrayType()
2169 EmbedElementIndexBeforeInit - 1; in CheckArrayType()
2178 if (!hadError && DeclType->isIncompleteArrayType() && !VerifyOnly) { in CheckArrayType()
2185 SemaRef.Diag(IList->getBeginLoc(), diag::ext_typecheck_zero_array_size); in CheckArrayType()
2192 // If there are any members of the array that get value-initialized, check in CheckArrayType()
2200 IList->getEndLoc()); in CheckArrayType()
2211 cast<InitListExpr>(InitExpr)->getNumInits() == 0) { in CheckFlexibleArrayInit()
2215 // Disallow flexible array init on non-top-level object in CheckFlexibleArrayInit()
2220 } else if (cast<VarDecl>(Entity.getDecl())->hasLocalStorage()) { in CheckFlexibleArrayInit()
2229 SemaRef.Diag(InitExpr->getBeginLoc(), FlexArrayDiag) in CheckFlexibleArrayInit()
2230 << InitExpr->getBeginLoc(); in CheckFlexibleArrayInit()
2231 SemaRef.Diag(Field->getLocation(), diag::note_flexible_array_member) in CheckFlexibleArrayInit()
2248 if (RD->isInvalidDecl()) { in CheckStructUnionTypes()
2255 if (RD->isUnion() && IList->getNumInits() == 0) { in CheckStructUnionTypes()
2257 for (FieldDecl *FD : RD->fields()) { in CheckStructUnionTypes()
2258 QualType ET = SemaRef.Context.getBaseElementType(FD->getType()); in CheckStructUnionTypes()
2259 if (checkDestructorReference(ET, IList->getEndLoc(), SemaRef)) { in CheckStructUnionTypes()
2267 cast<CXXRecordDecl>(RD)->hasInClassInitializer()) { in CheckStructUnionTypes()
2270 for (RecordDecl::field_iterator FieldEnd = RD->field_end(); in CheckStructUnionTypes()
2272 if (Field->hasInClassInitializer() || in CheckStructUnionTypes()
2273 (Field->isAnonymousStructOrUnion() && in CheckStructUnionTypes()
2274 Field->getType()->getAsCXXRecordDecl()->hasInClassInitializer())) { in CheckStructUnionTypes()
2275 StructuredList->setInitializedFieldInUnion(*Field); in CheckStructUnionTypes()
2280 llvm_unreachable("Couldn't find in-class initializer"); in CheckStructUnionTypes()
2283 // Value-initialize the first member of the union that isn't an unnamed in CheckStructUnionTypes()
2285 for (RecordDecl::field_iterator FieldEnd = RD->field_end(); in CheckStructUnionTypes()
2287 if (!Field->isUnnamedBitField()) { in CheckStructUnionTypes()
2290 IList->getEndLoc()); in CheckStructUnionTypes()
2292 StructuredList->setInitializedFieldInUnion(*Field); in CheckStructUnionTypes()
2304 Expr *Init = Index < IList->getNumInits() ? IList->getInit(Index) : nullptr; in CheckStructUnionTypes()
2307 // remaining base classes have no explicit initializer. in CheckStructUnionTypes()
2312 // each non-trailing aggregate element that is a pack expansion is assumed in CheckStructUnionTypes()
2313 // to correspond to no elements of the initializer list, and (1.7) a in CheckStructUnionTypes()
2320 // position corresponding to each non-trailing aggregate element of in CheckStructUnionTypes()
2326 AggrDeductionCandidateParamTypes->push_back( in CheckStructUnionTypes()
2330 if (I + 1 == E && RD->field_empty()) { in CheckStructUnionTypes()
2331 if (Index < IList->getNumInits()) in CheckStructUnionTypes()
2332 Index = IList->getNumInits(); in CheckStructUnionTypes()
2339 SourceLocation InitLoc = Init ? Init->getBeginLoc() : IList->getEndLoc(); in CheckStructUnionTypes()
2361 RecordDecl::field_iterator FieldEnd = RD->field_end(); in CheckStructUnionTypes()
2362 size_t NumRecordDecls = llvm::count_if(RD->decls(), [&](const Decl *D) { in CheckStructUnionTypes()
2369 while (Index < IList->getNumInits()) { in CheckStructUnionTypes()
2370 Expr *Init = IList->getInit(Index); in CheckStructUnionTypes()
2371 SourceLocation InitLoc = Init->getBeginLoc(); in CheckStructUnionTypes()
2391 DesignatedInitExpr::Designator *D = DIE->getDesignator(0); in CheckStructUnionTypes()
2392 if (!VerifyOnly && D->isFieldDesignator()) { in CheckStructUnionTypes()
2393 FieldDecl *F = D->getFieldDecl(); in CheckStructUnionTypes()
2396 QualType ET = SemaRef.Context.getBaseElementType(F->getType()); in CheckStructUnionTypes()
2420 if (IList->getNumInits() == 1) { in CheckStructUnionTypes()
2424 return IL->getValue().isZero(); in CheckStructUnionTypes()
2429 // Don't allow non-designated initializers on randomized structures. in CheckStructUnionTypes()
2430 if (RD->isRandomized() && !IsZeroInitializer(Init)) { in CheckStructUnionTypes()
2443 if (InitializedSomething && RD->isUnion()) in CheckStructUnionTypes()
2447 if (Field->getType()->isIncompleteArrayType()) in CheckStructUnionTypes()
2450 if (Field->isUnnamedBitField()) { in CheckStructUnionTypes()
2462 *Field, IList->getInit(Index)->getBeginLoc()); in CheckStructUnionTypes()
2471 QualType ET = SemaRef.Context.getBaseElementType(Field->getType()); in CheckStructUnionTypes()
2480 CheckSubElementType(MemberEntity, IList, Field->getType(), Index, in CheckStructUnionTypes()
2485 if (RD->isUnion() && StructuredList) { in CheckStructUnionTypes()
2487 StructuredList->setInitializedFieldInUnion(*Field); in CheckStructUnionTypes()
2498 if (!VerifyOnly && InitializedSomething && !RD->isUnion() && in CheckStructUnionTypes()
2499 !IList->isIdiomaticZeroInitializer(SemaRef.getLangOpts()) && in CheckStructUnionTypes()
2503 for (RecordDecl::field_iterator it = HasDesignatedInit ? RD->field_begin() in CheckStructUnionTypes()
2505 end = RD->field_end(); in CheckStructUnionTypes()
2510 if (!it->isUnnamedBitField() && !it->hasInClassInitializer() && in CheckStructUnionTypes()
2511 !it->getType()->isIncompleteArrayType()) { in CheckStructUnionTypes()
2515 SemaRef.Diag(IList->getSourceRange().getEnd(), Diag) << *it; in CheckStructUnionTypes()
2521 // Check that any remaining fields can be value-initialized if we're not in CheckStructUnionTypes()
2523 if (!StructuredList && Field != FieldEnd && !RD->isUnion() && in CheckStructUnionTypes()
2524 !Field->getType()->isIncompleteArrayType()) { in CheckStructUnionTypes()
2526 if (!Field->isUnnamedBitField() && !Field->hasInClassInitializer()) in CheckStructUnionTypes()
2529 IList->getEndLoc()); in CheckStructUnionTypes()
2537 RecordDecl::field_iterator I = HasDesignatedInit ? RD->field_begin() in CheckStructUnionTypes()
2539 for (RecordDecl::field_iterator E = RD->field_end(); I != E; ++I) { in CheckStructUnionTypes()
2540 QualType ET = SemaRef.Context.getBaseElementType(I->getType()); in CheckStructUnionTypes()
2541 if (checkDestructorReference(ET, IList->getEndLoc(), SemaRef)) { in CheckStructUnionTypes()
2548 if (Field == FieldEnd || !Field->getType()->isIncompleteArrayType() || in CheckStructUnionTypes()
2549 Index >= IList->getNumInits()) in CheckStructUnionTypes()
2552 if (CheckFlexibleArrayInit(Entity, IList->getInit(Index), *Field, in CheckStructUnionTypes()
2562 if (isa<InitListExpr>(IList->getInit(Index)) || in CheckStructUnionTypes()
2564 CheckSubElementType(MemberEntity, IList, Field->getType(), Index, in CheckStructUnionTypes()
2567 CheckImplicitInitList(MemberEntity, IList, Field->getType(), Index, in CheckStructUnionTypes()
2570 if (RD->isUnion() && StructuredList) { in CheckStructUnionTypes()
2572 StructuredList->setInitializedFieldInUnion(*Field); in CheckStructUnionTypes()
2588 for (IndirectFieldDecl::chain_iterator PI = IndirectField->chain_begin(), in ExpandAnonymousFieldDesignator()
2589 PE = IndirectField->chain_end(); PI != PE; ++PI) { in ExpandAnonymousFieldDesignator()
2592 (IdentifierInfo *)nullptr, DIE->getDesignator(DesigIdx)->getDotLoc(), in ExpandAnonymousFieldDesignator()
2593 DIE->getDesignator(DesigIdx)->getFieldLoc())); in ExpandAnonymousFieldDesignator()
2604 DIE->ExpandDesignator(SemaRef.Context, DesigIdx, &Replacements[0], in ExpandAnonymousFieldDesignator()
2610 unsigned NumIndexExprs = DIE->getNumSubExprs() - 1; in CloneDesignatedInitExpr()
2613 IndexExprs[I] = DIE->getSubExpr(I + 1); in CloneDesignatedInitExpr()
2614 return DesignatedInitExpr::Create(SemaRef.Context, DIE->designators(), in CloneDesignatedInitExpr()
2616 DIE->getEqualOrColonLoc(), in CloneDesignatedInitExpr()
2617 DIE->usesGNUSyntax(), DIE->getInit()); in CloneDesignatedInitExpr()
2631 return FD && FD->getDeclContext()->getRedeclContext()->Equals(Record); in ValidateCandidate()
2644 /// Check the well-formedness of a C99 designated initializer.
2648 /// IList, is well-formed for a current object of type @p DeclType
2663 /// @param NextField If non-NULL and the first designator in @p DIE is
2669 /// @param NextElementIndex If non-NULL and the first designator in @p
2670 /// DIE is an array designator or GNU array-range designator, this
2694 if (DesigIdx == DIE->size()) { in CheckDesignatedInitializer()
2695 // C++20 designated initialization can result in direct-list-initialization in CheckDesignatedInitializer()
2699 if (DIE->isDirectInit()) { in CheckDesignatedInitializer()
2700 Expr *Init = DIE->getInit(); in CheckDesignatedInitializer()
2702 "designator result in direct non-list initialization?"); in CheckDesignatedInitializer()
2704 DIE->getBeginLoc(), Init->getBeginLoc(), Init->getEndLoc()); in CheckDesignatedInitializer()
2716 AggrDeductionCandidateParamTypes->push_back(CurrentObjectType); in CheckDesignatedInitializer()
2725 // to re-process the designator. in CheckDesignatedInitializer()
2727 IList->setInit(OldIndex, DIE->getInit()); in CheckDesignatedInitializer()
2734 if (IList->getInit(OldIndex) != DIE->getInit()) in CheckDesignatedInitializer()
2735 DIE->setInit(IList->getInit(OldIndex)); in CheckDesignatedInitializer()
2736 IList->setInit(OldIndex, DIE); in CheckDesignatedInitializer()
2741 DesignatedInitExpr::Designator *D = DIE->getDesignator(DesigIdx); in CheckDesignatedInitializer()
2749 Expr *ExistingInit = StructuredIndex < StructuredList->getNumInits() ? in CheckDesignatedInitializer()
2750 StructuredList->getInit(StructuredIndex) : nullptr; in CheckDesignatedInitializer()
2751 if (!ExistingInit && StructuredList->hasArrayFiller()) in CheckDesignatedInitializer()
2752 ExistingInit = StructuredList->getArrayFiller(); in CheckDesignatedInitializer()
2757 SourceRange(D->getBeginLoc(), DIE->getEndLoc())); in CheckDesignatedInitializer()
2770 // designated initializer re-initializes only its current object in CheckDesignatedInitializer()
2773 SourceRange(D->getBeginLoc(), DIE->getEndLoc()), in CheckDesignatedInitializer()
2780 StructuredList = E->getUpdater(); in CheckDesignatedInitializer()
2783 DesignatedInitUpdateExpr(SemaRef.Context, D->getBeginLoc(), in CheckDesignatedInitializer()
2784 ExistingInit, DIE->getEndLoc()); in CheckDesignatedInitializer()
2785 StructuredList->updateInit(SemaRef.Context, StructuredIndex, DIUE); in CheckDesignatedInitializer()
2786 StructuredList = DIUE->getUpdater(); in CheckDesignatedInitializer()
2790 // designated init update of an already-fully-initialized object in in CheckDesignatedInitializer()
2791 // verify-only mode. The only reason we would need the structure is in CheckDesignatedInitializer()
2800 if (D->isFieldDesignator()) { in CheckDesignatedInitializer()
2812 SourceLocation Loc = D->getDotLoc(); in CheckDesignatedInitializer()
2814 Loc = D->getFieldLoc(); in CheckDesignatedInitializer()
2822 FieldDecl *KnownField = D->getFieldDecl(); in CheckDesignatedInitializer()
2824 const IdentifierInfo *FieldName = D->getFieldName(); in CheckDesignatedInitializer()
2833 D = DIE->getDesignator(DesigIdx); in CheckDesignatedInitializer()
2834 KnownField = cast<FieldDecl>(*IFD->chain_begin()); in CheckDesignatedInitializer()
2839 return true; // No typo correction when just trying this out. in CheckDesignatedInitializer()
2843 if (SemaRef.DiagRedefinedPlaceholderFieldDecl(DIE->getBeginLoc(), RD, in CheckDesignatedInitializer()
2849 if (DeclContextLookupResult Lookup = RD->lookup(FieldName); in CheckDesignatedInitializer()
2851 SemaRef.Diag(D->getFieldLoc(), diag::err_field_designator_nonfield) in CheckDesignatedInitializer()
2853 SemaRef.Diag(Lookup.front()->getLocation(), in CheckDesignatedInitializer()
2863 DeclarationNameInfo(FieldName, D->getFieldLoc()), in CheckDesignatedInitializer()
2874 SourceLocation Loc = D->getFieldLoc(); in CheckDesignatedInitializer()
2879 Loc = IList->getBeginLoc(); in CheckDesignatedInitializer()
2882 << FieldName << CurrentObjectType << DIE->getSourceRange(); in CheckDesignatedInitializer()
2891 NumBases = CXXRD->getNumBases(); in CheckDesignatedInitializer()
2895 for (auto *FI : RD->fields()) { in CheckDesignatedInitializer()
2896 if (FI->isUnnamedBitField()) in CheckDesignatedInitializer()
2910 if (RD->isUnion()) { in CheckDesignatedInitializer()
2913 FieldDecl *CurrentField = StructuredList->getInitializedFieldInUnion(); in CheckDesignatedInitializer()
2915 assert(StructuredList->getNumInits() == 1 in CheckDesignatedInitializer()
2918 Expr *ExistingInit = StructuredList->getInit(0); in CheckDesignatedInitializer()
2922 ExistingInit, SourceRange(D->getBeginLoc(), DIE->getEndLoc()), in CheckDesignatedInitializer()
2929 StructuredList->resizeInits(SemaRef.Context, 0); in CheckDesignatedInitializer()
2930 StructuredList->setInitializedFieldInUnion(nullptr); in CheckDesignatedInitializer()
2933 StructuredList->setInitializedFieldInUnion(*Field); in CheckDesignatedInitializer()
2942 InvalidUse = SemaRef.DiagnoseUseOfDecl(*Field, D->getFieldLoc()); in CheckDesignatedInitializer()
2949 // The ordered identifiers in the designators of the designated- in CheckDesignatedInitializer()
2950 // initializer-list shall form a subsequence of the ordered identifiers in CheckDesignatedInitializer()
2951 // in the direct non-static data members of T. in CheckDesignatedInitializer()
2958 // catches cases where we have a top-level field designator that jumps in CheckDesignatedInitializer()
2960 // otherwise-valid C++20 program, so is the only case that's required for in CheckDesignatedInitializer()
2965 (*NextField == RD->field_end() || in CheckDesignatedInitializer()
2966 (*NextField)->getFieldIndex() > Field->getFieldIndex() + 1)) { in CheckDesignatedInitializer()
2969 for (auto FI = RD->field_begin(); FI != RD->field_end(); ++FI) { in CheckDesignatedInitializer()
2970 if (FI->isUnnamedBitField()) in CheckDesignatedInitializer()
2972 if (*NextField != RD->field_end() && in CheckDesignatedInitializer()
2979 PrevField->getFieldIndex() > KnownField->getFieldIndex()) { in CheckDesignatedInitializer()
2980 SemaRef.Diag(DIE->getInit()->getBeginLoc(), in CheckDesignatedInitializer()
2982 << KnownField << PrevField << DIE->getSourceRange(); in CheckDesignatedInitializer()
2984 unsigned OldIndex = StructuredIndex - 1; in CheckDesignatedInitializer()
2985 if (StructuredList && OldIndex <= StructuredList->getNumInits()) { in CheckDesignatedInitializer()
2986 if (Expr *PrevInit = StructuredList->getInit(OldIndex)) { in CheckDesignatedInitializer()
2987 SemaRef.Diag(PrevInit->getBeginLoc(), in CheckDesignatedInitializer()
2989 << PrevField << PrevInit->getSourceRange(); in CheckDesignatedInitializer()
2998 D->setFieldDecl(*Field); in CheckDesignatedInitializer()
3000 // Make sure that our non-designated initializer list has space in CheckDesignatedInitializer()
3002 if (StructuredList && FieldIndex >= StructuredList->getNumInits()) in CheckDesignatedInitializer()
3003 StructuredList->resizeInits(SemaRef.Context, FieldIndex + 1); in CheckDesignatedInitializer()
3006 if (Field->getType()->isIncompleteArrayType()) { in CheckDesignatedInitializer()
3008 if ((DesigIdx + 1) != DIE->size()) { in CheckDesignatedInitializer()
3013 = DIE->getDesignator(DesigIdx + 1); in CheckDesignatedInitializer()
3014 SemaRef.Diag(NextD->getBeginLoc(), in CheckDesignatedInitializer()
3016 << SourceRange(NextD->getBeginLoc(), DIE->getEndLoc()); in CheckDesignatedInitializer()
3017 SemaRef.Diag(Field->getLocation(), diag::note_flexible_array_member) in CheckDesignatedInitializer()
3023 if (!hadError && !isa<InitListExpr>(DIE->getInit()) && in CheckDesignatedInitializer()
3024 !isa<StringLiteral>(DIE->getInit())) { in CheckDesignatedInitializer()
3027 SemaRef.Diag(DIE->getInit()->getBeginLoc(), in CheckDesignatedInitializer()
3029 << DIE->getInit()->getSourceRange(); in CheckDesignatedInitializer()
3030 SemaRef.Diag(Field->getLocation(), diag::note_flexible_array_member) in CheckDesignatedInitializer()
3037 if (!Invalid && CheckFlexibleArrayInit(Entity, DIE->getInit(), *Field, in CheckDesignatedInitializer()
3050 IList->setInit(Index, DIE->getInit()); in CheckDesignatedInitializer()
3054 CheckSubElementType(MemberEntity, IList, Field->getType(), Index, in CheckDesignatedInitializer()
3057 IList->setInit(OldIndex, DIE); in CheckDesignatedInitializer()
3068 QualType FieldType = Field->getType(); in CheckDesignatedInitializer()
3088 if (Field != RD->field_end() && Field->isUnnamedBitField()) in CheckDesignatedInitializer()
3102 if (RD->isUnion()) in CheckDesignatedInitializer()
3120 // [ constant-expression ] in CheckDesignatedInitializer()
3130 // [ constant-expression ... constant-expression ] in CheckDesignatedInitializer()
3134 SemaRef.Diag(D->getLBracketLoc(), diag::err_array_designator_non_array) in CheckDesignatedInitializer()
3142 if (D->isArrayDesignator()) { in CheckDesignatedInitializer()
3143 IndexExpr = DIE->getArrayIndex(*D); in CheckDesignatedInitializer()
3144 DesignatedStartIndex = IndexExpr->EvaluateKnownConstInt(SemaRef.Context); in CheckDesignatedInitializer()
3147 assert(D->isArrayRangeDesignator() && "Need array-range designator"); in CheckDesignatedInitializer()
3150 DIE->getArrayRangeStart(*D)->EvaluateKnownConstInt(SemaRef.Context); in CheckDesignatedInitializer()
3152 DIE->getArrayRangeEnd(*D)->EvaluateKnownConstInt(SemaRef.Context); in CheckDesignatedInitializer()
3153 IndexExpr = DIE->getArrayRangeEnd(*D); in CheckDesignatedInitializer()
3161 DIE->getInit()->HasSideEffects(SemaRef.Context) && !VerifyOnly) in CheckDesignatedInitializer()
3162 FullyStructuredList->sawArrayRangeDesignator(); in CheckDesignatedInitializer()
3166 llvm::APSInt MaxElements(cast<ConstantArrayType>(AT)->getSize(), false); in CheckDesignatedInitializer()
3175 SemaRef.Diag(IndexExpr->getBeginLoc(), in CheckDesignatedInitializer()
3178 << IndexExpr->getSourceRange(); in CheckDesignatedInitializer()
3194 StructuredList && StructuredList->isStringLiteralInit(); in CheckDesignatedInitializer()
3203 Expr *SubExpr = StructuredList->getInit(0)->IgnoreParenImpCasts(); in CheckDesignatedInitializer()
3206 QualType CharTy = AT->getElementType(); in CheckDesignatedInitializer()
3216 uint64_t StrLen = SL->getLength(); in CheckDesignatedInitializer()
3217 if (cast<ConstantArrayType>(AT)->getSize().ult(StrLen)) in CheckDesignatedInitializer()
3218 StrLen = cast<ConstantArrayType>(AT)->getZExtSize(); in CheckDesignatedInitializer()
3219 StructuredList->resizeInits(Context, StrLen); in CheckDesignatedInitializer()
3224 llvm::APInt CodeUnit(PromotedCharTyWidth, SL->getCodeUnit(i)); in CheckDesignatedInitializer()
3226 Context, CodeUnit, PromotedCharTy, SubExpr->getExprLoc()); in CheckDesignatedInitializer()
3231 StructuredList->updateInit(Context, i, Init); in CheckDesignatedInitializer()
3236 Context.getObjCEncodingForType(E->getEncodedType(), Str); in CheckDesignatedInitializer()
3240 if (cast<ConstantArrayType>(AT)->getSize().ult(StrLen)) in CheckDesignatedInitializer()
3241 StrLen = cast<ConstantArrayType>(AT)->getZExtSize(); in CheckDesignatedInitializer()
3242 StructuredList->resizeInits(Context, StrLen); in CheckDesignatedInitializer()
3249 Context, CodeUnit, PromotedCharTy, SubExpr->getExprLoc()); in CheckDesignatedInitializer()
3254 StructuredList->updateInit(Context, i, Init); in CheckDesignatedInitializer()
3259 // Make sure that our non-designated initializer list has space in CheckDesignatedInitializer()
3262 DesignatedEndIndex.getZExtValue() >= StructuredList->getNumInits()) in CheckDesignatedInitializer()
3263 StructuredList->resizeInits(SemaRef.Context, in CheckDesignatedInitializer()
3278 QualType ElementType = AT->getElementType(); in CheckDesignatedInitializer()
3327 if (StructuredIndex < StructuredList->getNumInits()) in getStructuredSubobjectInit()
3328 ExistingInit = StructuredList->getInit(StructuredIndex); in getStructuredSubobjectInit()
3366 if (Index < IList->getNumInits()) { in getStructuredSubobjectInit()
3367 if (auto *Init = dyn_cast_or_null<InitListExpr>(IList->getInit(Index))) in getStructuredSubobjectInit()
3368 ExpectedNumInits = Init->getNumInits(); in getStructuredSubobjectInit()
3370 ExpectedNumInits = IList->getNumInits() - Index; in getStructuredSubobjectInit()
3378 StructuredList->updateInit(SemaRef.Context, StructuredIndex, Result); in getStructuredSubobjectInit()
3390 if (!ResultType->isArrayType()) in createInitListExpr()
3392 Result->setType(ResultType); in createInitListExpr()
3394 // Pre-allocate storage for the structured initializer list. in createInitListExpr()
3400 NumElements = CAType->getZExtSize(); in createInitListExpr()
3406 } else if (const VectorType *VType = CurrentObjectType->getAs<VectorType>()) { in createInitListExpr()
3407 NumElements = VType->getNumElements(); in createInitListExpr()
3408 } else if (CurrentObjectType->isRecordType()) { in createInitListExpr()
3410 } else if (CurrentObjectType->isDependentType()) { in createInitListExpr()
3414 Result->reserveInits(SemaRef.Context, NumElements); in createInitListExpr()
3424 // No structured initializer list to update in UpdateStructuredListElement()
3428 if (Expr *PrevInit = StructuredList->updateInit(SemaRef.Context, in UpdateStructuredListElement()
3431 // No need to diagnose when `expr` is nullptr because a more relevant in UpdateStructuredListElement()
3435 diagnoseInitOverride(PrevInit, expr->getSourceRange()); in UpdateStructuredListElement()
3459 SourceLocation Loc = Index->getBeginLoc(); in CheckArrayDesignatorExpr()
3469 << toString(Value, 10) << Index->getSourceRange(); in CheckArrayDesignatorExpr()
3495 if (!Index->isTypeDependent() && !Index->isValueDependent()) in ActOnDesignatedInitializer()
3509 bool StartDependent = StartIndex->isTypeDependent() || in ActOnDesignatedInitializer()
3510 StartIndex->isValueDependent(); in ActOnDesignatedInitializer()
3511 bool EndDependent = EndIndex->isTypeDependent() || in ActOnDesignatedInitializer()
3512 EndIndex->isValueDependent(); in ActOnDesignatedInitializer()
3533 << StartIndex->getSourceRange() << EndIndex->getSourceRange(); in ActOnDesignatedInitializer()
3554 //===----------------------------------------------------------------------===//
3556 //===----------------------------------------------------------------------===//
3564 Type = AT->getElementType(); in InitializedEntity()
3565 } else if (const VectorType *VT = Parent.getType()->getAs<VectorType>()) { in InitializedEntity()
3567 Type = VT->getElementType(); in InitializedEntity()
3569 const ComplexType *CT = Parent.getType()->getAs<ComplexType>(); in InitializedEntity()
3572 Type = CT->getElementType(); in InitializedEntity()
3585 Result.Type = Base->getType(); in InitializeBase()
3594 return (D ? D->getDeclName() : DeclarationName()); in getName()
3602 return Variable.VariableOrMember->getDeclName(); in getName()
3695 unsigned Depth = getParent() ? getParent()->dumpImpl(OS) : 0; in dumpImpl()
3697 OS << "`-"; in dumpImpl()
3734 D->printQualifiedName(OS); in dumpImpl()
3742 LLVM_DUMP_METHOD void InitializedEntity::dump() const { in dump() function in InitializedEntity
3746 //===----------------------------------------------------------------------===//
3748 //===----------------------------------------------------------------------===//
3872 S.Type = Function->getType(); in AddAddressOverloadResolutionStep()
4093 assert(Syntactic->getNumInits() == 1 && in RewrapReferenceInitList()
4097 S.Type = Syntactic->getInit(0)->getType(); in RewrapReferenceInitList()
4109 this->Failure = Failure; in SetOverloadFailure()
4110 this->FailedOverloadResult = Result; in SetOverloadFailure()
4113 //===----------------------------------------------------------------------===//
4115 //===----------------------------------------------------------------------===//
4125 if (VD->getInit() || VD->getEndLoc().isMacroID()) in maybeRecoverWithZeroInitialization()
4128 QualType VariableTy = VD->getType().getCanonicalType(); in maybeRecoverWithZeroInitialization()
4129 SourceLocation Loc = S.getLocForEndOfToken(VD->getEndLoc()); in maybeRecoverWithZeroInitialization()
4150 assert(Entity.getType()->isObjCRetainableType() && in MaybeProduceObjCObject()
4160 if (!Entity.getType()->isObjCRetainableType()) in MaybeProduceObjCObject()
4188 if (!S.isCompleteType(List->getExprLoc(), E)) { in TryInitializerListConstruction()
4197 List->getNumInits()), in TryInitializerListConstruction()
4202 List->getExprLoc(), List->getBeginLoc(), List->getEndLoc()); in TryInitializerListConstruction()
4213 /// cv-qualified) T.
4216 if (Info.Constructor->getNumParams() == 0) in hasCopyOrMoveCtorParam()
4220 Info.Constructor->getParamDecl(0)->getType().getNonReferenceType(); in hasCopyOrMoveCtorParam()
4222 Ctx.getRecordType(cast<CXXRecordDecl>(Info.FoundDecl->getDeclContext())); in hasCopyOrMoveCtorParam()
4239 if (!Info.Constructor || Info.Constructor->isInvalidDecl()) in ResolveConstructorOverload()
4246 // ... and the constructor or user-defined conversion function is a in ResolveConstructorOverload()
4248 // - 13.3.1.3, when the argument is the temporary in the second step in ResolveConstructorOverload()
4249 // of a class copy-initialization, or in ResolveConstructorOverload()
4250 // - 13.3.1.4, 13.3.1.5, or 13.3.1.6 (in all cases), [not handled here] in ResolveConstructorOverload()
4251 // - the second phase of 13.3.1.7 when the initializer list has exactly in ResolveConstructorOverload()
4254 // is to X or reference to (possibly cv-qualified X), in ResolveConstructorOverload()
4255 // user-defined conversion sequences are not considered. in ResolveConstructorOverload()
4268 // - When initializing a temporary to be bound to the first parameter in ResolveConstructorOverload()
4270 // cv-qualified T as its first argument, called with a single in ResolveConstructorOverload()
4271 // argument in the context of direct-initialization, explicit in ResolveConstructorOverload()
4287 // ([over.match.ctor]) or by list-initialization ([over.match.list]) in ResolveConstructorOverload()
4289 // U that convert to the non-reference type cv T are candidates. in ResolveConstructorOverload()
4291 // direct-initialization. in ResolveConstructorOverload()
4298 auto *SourceRD = Initializer->getType()->getAsCXXRecordDecl(); in ResolveConstructorOverload()
4299 if (SourceRD && S.isCompleteType(DeclLoc, Initializer->getType())) { in ResolveConstructorOverload()
4300 const auto &Conversions = SourceRD->getVisibleConversionFunctions(); in ResolveConstructorOverload()
4303 CXXRecordDecl *ActingDC = cast<CXXRecordDecl>(D->getDeclContext()); in ResolveConstructorOverload()
4304 D = D->getUnderlyingDecl(); in ResolveConstructorOverload()
4309 Conv = cast<CXXConversionDecl>(ConvTemplate->getTemplatedDecl()); in ResolveConstructorOverload()
4337 /// \param IsListInit Is this list-initialization?
4338 /// \param IsInitListCopy Is this non-list-initialization resulting from a
4339 /// list-initialization from {x} where x is the same
4356 ILE ? MultiExprArg(ILE->getInits(), ILE->getNumInits()) : Args; in TryConstructorInitialization()
4371 // - If the initializer expression is a prvalue and the cv-unqualified in TryConstructorInitialization()
4375 // Per DR (no number yet), this does not apply when initializing a base in TryConstructorInitialization()
4376 // class or delegating to another constructor from a mem-initializer. in TryConstructorInitialization()
4380 UnwrappedArgs.size() == 1 && UnwrappedArgs[0]->isPRValue() && in TryConstructorInitialization()
4381 S.Context.hasSameUnqualifiedType(UnwrappedArgs[0]->getType(), DestType)) { in TryConstructorInitialization()
4389 const RecordType *DestRecordType = DestType->getAs<RecordType>(); in TryConstructorInitialization()
4392 = cast<CXXRecordDecl>(DestRecordType->getDecl()); in TryConstructorInitialization()
4403 // - Otherwise, if T is a class type, constructors are considered. The in TryConstructorInitialization()
4413 // When objects of non-aggregate type T are list-initialized, such that in TryConstructorInitialization()
4418 // - Initially, the candidate functions are the initializer-list in TryConstructorInitialization()
4424 // If the initializer list has no elements and T has a default constructor, in TryConstructorInitialization()
4434 // - If no viable initializer-list constructor is found, overload resolution in TryConstructorInitialization()
4459 if (auto *CD = dyn_cast<CXXConversionDecl>(Best->Function)) { in TryConstructorInitialization()
4460 // Add the user-defined conversion step that calls the conversion function. in TryConstructorInitialization()
4461 QualType ConvType = CD->getConversionType(); in TryConstructorInitialization()
4464 Sequence.AddUserConversionStep(CD, Best->FoundDecl, ConvType, in TryConstructorInitialization()
4473 CXXConstructorDecl *CtorDecl = cast<CXXConstructorDecl>(Best->Function); in TryConstructorInitialization()
4477 // of a const-qualified type T, T shall be a class type with a in TryConstructorInitialization()
4478 // user-provided default constructor. in TryConstructorInitialization()
4480 // If the implicit default constructor initializes all subobjects, no in TryConstructorInitialization()
4486 if (!CtorDecl->getParent()->allowConstDefaultInit()) { in TryConstructorInitialization()
4494 // In copy-list-initialization, if an explicit constructor is chosen, the in TryConstructorInitialization()
4495 // initializer is ill-formed. in TryConstructorInitialization()
4496 if (IsListInit && !Kind.AllowExplicit() && CtorDecl->isExplicit()) { in TryConstructorInitialization()
4503 // In some copy-initialization contexts, a two-stage overload resolution in TryConstructorInitialization()
4508 // For deleted functions in other contexts, there is no need to get the in TryConstructorInitialization()
4513 // Add the constructor initialization step. Any cv-qualification conversion is in TryConstructorInitialization()
4516 Best->FoundDecl, CtorDecl, DestArrayType, HadMultipleCandidates, in TryConstructorInitialization()
4538 SourceType = Fn->getType(); in ResolveOverloadedFunctionForReferenceBinding()
4540 } else if (!UnqualifiedTargetType->isRecordType()) { in ResolveOverloadedFunctionForReferenceBinding()
4584 QualType cv1T1 = DestType->castAs<ReferenceType>()->getPointeeType(); in TryReferenceListInitialization()
4590 // reference-related to the referenced type, bind directly to that element in TryReferenceListInitialization()
4594 if (InitList->getNumInits() == 1) { in TryReferenceListInitialization()
4595 Expr *Initializer = InitList->getInit(0); in TryReferenceListInitialization()
4605 SourceLocation DeclLoc = Initializer->getBeginLoc(); in TryReferenceListInitialization()
4626 (void)S.Context.getUnqualifiedArrayType(InitList->getType(), T2Quals); in TryReferenceListInitialization()
4637 // Not reference-related. Create a temporary and bind to that. in TryReferenceListInitialization()
4644 if (DestType->isRValueReferenceType() || in TryReferenceListInitialization()
4647 isa<IncompleteArrayType>(T1->getUnqualifiedDesugaredType()) && in TryReferenceListInitialization()
4648 DestType->isRValueReferenceType()) { in TryReferenceListInitialization()
4650 // List-initialization of an object or reference of type T is defined as in TryReferenceListInitialization()
4661 cv1T1, DestType->isRValueReferenceType() ? VK_XValue : VK_LValue); in TryReferenceListInitialization()
4679 if (S.getLangOpts().CPlusPlus && DestType->isScalarType() && in TryListInitialization()
4680 !DestType->isAnyComplexType() && InitList->getNumInits() > 1) { in TryListInitialization()
4684 if (DestType->isReferenceType()) { in TryListInitialization()
4690 if (DestType->isRecordType() && in TryListInitialization()
4691 !S.isCompleteType(InitList->getBeginLoc(), DestType)) { in TryListInitialization()
4697 // - If the braced-init-list contains a designated-initializer-list, T shall in TryListInitialization()
4705 bool IsDesignatedInit = InitList->hasDesignatedInit(); in TryListInitialization()
4706 if (!DestType->isAggregateType() && IsDesignatedInit) { in TryListInitialization()
4713 // - If T is a class type and the initializer list has a single element of in TryListInitialization()
4715 // initialized from that element (by copy-initialization for in TryListInitialization()
4716 // copy-list-initialization, or by direct-initialization for in TryListInitialization()
4717 // direct-list-initialization). in TryListInitialization()
4718 // - Otherwise, if T is a character array and the initializer list has a in TryListInitialization()
4719 // single element that is an appropriately-typed string literal in TryListInitialization()
4722 // - Otherwise, if T is an aggregate, [...] (continue below). in TryListInitialization()
4723 if (S.getLangOpts().CPlusPlus11 && InitList->getNumInits() == 1 && in TryListInitialization()
4725 if (DestType->isRecordType()) { in TryListInitialization()
4726 QualType InitType = InitList->getInit(0)->getType(); in TryListInitialization()
4728 S.IsDerivedFrom(InitList->getBeginLoc(), InitType, DestType)) { in TryListInitialization()
4738 Expr *SubInit[1] = {InitList->getInit(0)}; in TryListInitialization()
4744 InitList->getLBraceLoc(), in TryListInitialization()
4745 InitList->getRBraceLoc()) in TryListInitialization()
4752 // the element is not an appropriately-typed string literal, in which in TryListInitialization()
4763 // - If T is an aggregate, aggregate initialization is performed. in TryListInitialization()
4764 if ((DestType->isRecordType() && !DestType->isAggregateType()) || in TryListInitialization()
4768 // - Otherwise, if the initializer list has no elements and T is a in TryListInitialization()
4770 // value-initialized. in TryListInitialization()
4771 if (InitList->getNumInits() == 0) { in TryListInitialization()
4772 CXXRecordDecl *RD = DestType->getAsCXXRecordDecl(); in TryListInitialization()
4779 // - Otherwise, if T is a specialization of std::initializer_list<E>, in TryListInitialization()
4785 // - Otherwise, if T is a class type, constructors are considered. in TryListInitialization()
4794 if (S.getLangOpts().CPlusPlus && !DestType->isAggregateType() && in TryListInitialization()
4795 InitList->getNumInits() == 1) { in TryListInitialization()
4796 Expr *E = InitList->getInit(0); in TryListInitialization()
4798 // - Otherwise, if T is an enumeration with a fixed underlying type, in TryListInitialization()
4799 // the initializer-list has a single element v, and the initialization in TryListInitialization()
4800 // is direct-list-initialization, the object is initialized with the in TryListInitialization()
4802 // the underlying type of T, the program is ill-formed. in TryListInitialization()
4803 auto *ET = DestType->getAs<EnumType>(); in TryListInitialization()
4806 ET && ET->getDecl()->isFixed() && in TryListInitialization()
4807 !S.Context.hasSameUnqualifiedType(E->getType(), DestType) && in TryListInitialization()
4808 (E->getType()->isIntegralOrUnscopedEnumerationType() || in TryListInitialization()
4809 E->getType()->isFloatingType())) { in TryListInitialization()
4813 // Otherwise, if v is of integral, unscoped enumeration, or floating-point in TryListInitialization()
4815 // There is no overlap possible between these two cases (except when the in TryListInitialization()
4817 // case is handled by the general case for single-element lists below. in TryListInitialization()
4821 if (!E->isPRValue()) in TryListInitialization()
4823 // If E is of a floating-point type, then the conversion is ill-formed in TryListInitialization()
4826 ICS.Standard.Second = E->getType()->isFloatingType() in TryListInitialization()
4829 ICS.Standard.setFromType(E->getType()); in TryListInitialization()
4830 ICS.Standard.setToType(0, E->getType()); in TryListInitialization()
4839 // - Otherwise, if the initializer list has a single element of type E in TryListInitialization()
4841 // initialized from that element (by copy-initialization for in TryListInitialization()
4842 // copy-list-initialization, or by direct-initialization for in TryListInitialization()
4843 // direct-list-initialization); if a narrowing conversion is required in TryListInitialization()
4844 // to convert the element to T, the program is ill-formed. in TryListInitialization()
4846 // Per core-24034, this is direct-initialization if we were performing in TryListInitialization()
4847 // direct-list-initialization and copy-initialization otherwise. in TryListInitialization()
4849 // copy-initialization. This only matters if we might use an 'explicit' in TryListInitialization()
4854 Expr *Init = InitList->getInit(0); in TryListInitialization()
4855 if (Init->getType()->isRecordType() || in TryListInitialization()
4856 (Init->getType()->isNullPtrType() && DestType->isBooleanType())) { in TryListInitialization()
4860 InitList->getLBraceLoc(), in TryListInitialization()
4861 InitList->getRBraceLoc()) in TryListInitialization()
4891 QualType cv1T1 = DestType->castAs<ReferenceType>()->getPointeeType(); in TryRefInitWithConversionFunction()
4893 QualType cv2T2 = Initializer->getType(); in TryRefInitWithConversionFunction()
4896 assert(!S.CompareReferenceRelationship(Initializer->getBeginLoc(), T1, T2) && in TryRefInitWithConversionFunction()
4907 // initializing a reference, not even for direct-initialization. in TryRefInitWithConversionFunction()
4912 if (AllowRValues && (T1RecordType = T1->getAs<RecordType>()) && in TryRefInitWithConversionFunction()
4916 CXXRecordDecl *T1RecordDecl = cast<CXXRecordDecl>(T1RecordType->getDecl()); in TryRefInitWithConversionFunction()
4923 if (!Info.Constructor->isInvalidDecl() && in TryRefInitWithConversionFunction()
4924 Info.Constructor->isConvertingConstructor(/*AllowExplicit*/true)) { in TryRefInitWithConversionFunction()
4939 if (T1RecordType && T1RecordType->getDecl()->isInvalidDecl()) in TryRefInitWithConversionFunction()
4943 if ((T2RecordType = T2->getAs<RecordType>()) && in TryRefInitWithConversionFunction()
4947 CXXRecordDecl *T2RecordDecl = cast<CXXRecordDecl>(T2RecordType->getDecl()); in TryRefInitWithConversionFunction()
4949 const auto &Conversions = T2RecordDecl->getVisibleConversionFunctions(); in TryRefInitWithConversionFunction()
4952 CXXRecordDecl *ActingDC = cast<CXXRecordDecl>(D->getDeclContext()); in TryRefInitWithConversionFunction()
4954 D = cast<UsingShadowDecl>(D)->getTargetDecl(); in TryRefInitWithConversionFunction()
4959 Conv = cast<CXXConversionDecl>(ConvTemplate->getTemplatedDecl()); in TryRefInitWithConversionFunction()
4967 // candidates with reference-compatible results? That might be needed to in TryRefInitWithConversionFunction()
4970 Conv->getConversionType()->isLValueReferenceType())) { in TryRefInitWithConversionFunction()
4983 if (T2RecordType && T2RecordType->getDecl()->isInvalidDecl()) in TryRefInitWithConversionFunction()
4986 SourceLocation DeclLoc = Initializer->getBeginLoc(); in TryRefInitWithConversionFunction()
4994 FunctionDecl *Function = Best->Function; in TryRefInitWithConversionFunction()
4997 Function->setReferenced(); in TryRefInitWithConversionFunction()
5002 cv3T3 = Function->getReturnType(); in TryRefInitWithConversionFunction()
5007 if (cv3T3->isLValueReferenceType()) in TryRefInitWithConversionFunction()
5009 else if (const auto *RRef = cv3T3->getAs<RValueReferenceType>()) in TryRefInitWithConversionFunction()
5010 VK = RRef->getPointeeType()->isFunctionType() ? VK_LValue : VK_XValue; in TryRefInitWithConversionFunction()
5013 // Add the user-defined conversion step. in TryRefInitWithConversionFunction()
5015 Sequence.AddUserConversionStep(Function, Best->FoundDecl, cv3T3, in TryRefInitWithConversionFunction()
5018 // Determine whether we'll need to perform derived-to-base adjustments or in TryRefInitWithConversionFunction()
5031 ICS.Standard = Best->FinalConversion; in TryRefInitWithConversionFunction()
5035 // derived-to-base conversion, which we handle below. in TryRefInitWithConversionFunction()
5043 // We adjust the cv-qualifications to match the reference regardless of in TryRefInitWithConversionFunction()
5077 QualType cv1T1 = DestType->castAs<ReferenceType>()->getPointeeType(); in TryReferenceInitialization()
5097 /// Determine whether an expression is a non-referenceable glvalue (one to
5101 return E->refersToBitField() || E->refersToVectorElement() || in isNonReferenceableGLValue()
5102 E->refersToMatrixElement(); in isNonReferenceableGLValue()
5120 SourceLocation DeclLoc = Initializer->getBeginLoc(); in TryReferenceInitializationCore()
5123 bool isLValueRef = DestType->isLValueReferenceType(); in TryReferenceInitializationCore()
5125 Expr::Classification InitCategory = Initializer->Classify(S.Context); in TryReferenceInitializationCore()
5135 // - If the reference is an lvalue reference and the initializer in TryReferenceInitializationCore()
5138 // there are no function rvalues in C++, rvalue refs to functions are treated in TryReferenceInitializationCore()
5141 bool T1Function = T1->isFunctionType(); in TryReferenceInitializationCore()
5147 // - is an lvalue (but is not a bit-field), and "cv1 T1" is in TryReferenceInitializationCore()
5148 // reference-compatible with "cv2 T2," or in TryReferenceInitializationCore()
5152 // these qualifiers must all be top-level, so just convert to "cv1 T2". in TryReferenceInitializationCore()
5156 Initializer->getValueKind()); in TryReferenceInitializationCore()
5162 // Perform a (possibly multi-level) qualification conversion. in TryReferenceInitializationCore()
5164 Initializer->getValueKind()); in TryReferenceInitializationCore()
5170 // bit-field or vector element. Those cases are't supposed to be in TryReferenceInitializationCore()
5176 // - has a class type (i.e., T2 is a class type), where T1 is not in TryReferenceInitializationCore()
5177 // reference-related to T2, and can be implicitly converted to an in TryReferenceInitializationCore()
5178 // lvalue of type "cv3 T3," where "cv1 T1" is reference-compatible in TryReferenceInitializationCore()
5184 if (RefRelationship == Sema::Ref_Incompatible && T2->isRecordType() && in TryReferenceInitializationCore()
5203 // - Otherwise, the reference shall be an lvalue reference to a in TryReferenceInitializationCore()
5204 // non-volatile const type (i.e., cv1 shall be const), or the reference in TryReferenceInitializationCore()
5226 if (Initializer->refersToBitField()) in TryReferenceInitializationCore()
5229 else if (Initializer->refersToVectorElement()) in TryReferenceInitializationCore()
5232 else if (Initializer->refersToMatrixElement()) in TryReferenceInitializationCore()
5251 // - If the initializer expression in TryReferenceInitializationCore()
5252 // - is an in TryReferenceInitializationCore()
5253 // [<=14] xvalue (but not a bit-field), class prvalue, array prvalue, or in TryReferenceInitializationCore()
5254 // [1z] rvalue (but not a bit-field) or in TryReferenceInitializationCore()
5255 // function lvalue and "cv1 T1" is reference-compatible with "cv2 T2" in TryReferenceInitializationCore()
5264 (S.getLangOpts().CPlusPlus17 || T2->isRecordType() || in TryReferenceInitializationCore()
5265 T2->isArrayType())))) { in TryReferenceInitializationCore()
5267 if (InitCategory.isPRValue() && T2->isRecordType()) { in TryReferenceInitializationCore()
5322 // - has a class type (i.e., T2 is a class type), where T1 is not in TryReferenceInitializationCore()
5323 // reference-related to T2, and can be implicitly converted to an in TryReferenceInitializationCore()
5325 // where "cv1 T1" is reference-compatible with "cv3 T3", in TryReferenceInitializationCore()
5328 if (T2->isRecordType()) { in TryReferenceInitializationCore()
5352 // - Otherwise, a temporary of type "cv1 T1" is created and initialized in TryReferenceInitializationCore()
5353 // from the initializer expression using the rules for a non-reference in TryReferenceInitializationCore()
5354 // copy-initialization (8.5). The reference is then bound to the in TryReferenceInitializationCore()
5368 // copy-initialization? in TryReferenceInitializationCore()
5396 // [...] If T1 is reference-related to T2, cv1 must be the in TryReferenceInitializationCore()
5397 // same cv-qualification as, or greater cv-qualification in TryReferenceInitializationCore()
5398 // than, cv2; otherwise, the program is ill-formed. in TryReferenceInitializationCore()
5408 // [...] If T1 is reference-related to T2 and the reference is an rvalue in TryReferenceInitializationCore()
5447 assert((!InitList || InitList->getNumInits() == 0) && in TryValueInitialization()
5448 "Shouldn't use value-init for non-empty init lists"); in TryValueInitialization()
5452 // To value-initialize an object of type T means: in TryValueInitialization()
5455 // -- if T is an array type, then each element is value-initialized; in TryValueInitialization()
5458 if (const RecordType *RT = T->getAs<RecordType>()) { in TryValueInitialization()
5459 if (CXXRecordDecl *ClassDecl = dyn_cast<CXXRecordDecl>(RT->getDecl())) { in TryValueInitialization()
5462 // -- if T is a class type (clause 9) with a user-declared constructor in TryValueInitialization()
5464 // initialization is ill-formed if T has no accessible default in TryValueInitialization()
5467 // -- if T is a class type (clause 9) with either no default constructor in TryValueInitialization()
5468 // (12.1 [class.ctor]) or a default constructor that is user-provided in TryValueInitialization()
5469 // or deleted, then the object is default-initialized; in TryValueInitialization()
5471 // Note that the C++11 rule is the same as the C++98 rule if there are no in TryValueInitialization()
5474 if (!CD || !CD->getCanonicalDecl()->isDefaulted() || CD->isDeleted()) in TryValueInitialization()
5477 // -- if T is a (possibly cv-qualified) non-union class type without a in TryValueInitialization()
5478 // user-provided or deleted default constructor, then the object is in TryValueInitialization()
5479 // zero-initialized and, if T has a non-trivial default constructor, in TryValueInitialization()
5480 // default-initialized; in TryValueInitialization()
5481 // The 'non-union' here was removed by DR1502. The 'non-trivial default in TryValueInitialization()
5487 // -- if T is a non-union class type without a user-declared constructor, in TryValueInitialization()
5488 // then every non-static data member and base class component of T is in TryValueInitialization()
5489 // value-initialized; in TryValueInitialization()
5490 // [...] A program that calls for [...] value-initialization of an in TryValueInitialization()
5491 // entity of reference type is ill-formed. in TryValueInitialization()
5493 // C++11 doesn't need this handling, because value-initialization does not in TryValueInitialization()
5497 ClassDecl->hasUninitializedReferenceMember()) { in TryValueInitialization()
5502 // If this is list-value-initialization, pass the empty init list on when in TryValueInitialization()
5510 // wrap a class-typed CXXConstructExpr in an ArrayInitLoopExpr. in TryValueInitialization()
5527 // To default-initialize an object of type T means: in TryDefaultInitialization()
5528 // - if T is an array type, each element is default-initialized; in TryDefaultInitialization()
5531 // - if T is a (possibly cv-qualified) class type (Clause 9), the default in TryDefaultInitialization()
5532 // constructor for T is called (and the initialization is ill-formed if in TryDefaultInitialization()
5533 // T has no accessible default constructor); in TryDefaultInitialization()
5534 if (DestType->isRecordType() && S.getLangOpts().CPlusPlus) { in TryDefaultInitialization()
5540 // - otherwise, no initialization is performed. in TryDefaultInitialization()
5543 // a const-qualified type T, T shall be a class type with a user-provided in TryDefaultInitialization()
5551 // If the destination type has a lifetime property, zero-initialize it. in TryDefaultInitialization()
5606 // follows. Let x1, . . . , xk be the elements of the expression-list. If in TryOrBuildParenListInitialization()
5611 ArrayLength = CAT->getZExtSize(); in TryOrBuildParenListInitialization()
5615 // Braced-initialization of variable array types is not allowed, even if in TryOrBuildParenListInitialization()
5619 const Expr *SE = VAT->getSizeExpr(); in TryOrBuildParenListInitialization()
5620 S.Diag(SE->getBeginLoc(), diag::err_variable_object_no_init) in TryOrBuildParenListInitialization()
5621 << SE->getSourceRange(); in TryOrBuildParenListInitialization()
5624 assert(Entity.getType()->isIncompleteArrayType()); in TryOrBuildParenListInitialization()
5629 // ...the ith array element is copy-initialized with xi for each in TryOrBuildParenListInitialization()
5635 E->getExprLoc(), /*isDirectInit=*/false, E); in TryOrBuildParenListInitialization()
5639 // ...and value-initialized for each k < i <= n; in TryOrBuildParenListInitialization()
5651 AT->getElementType(), llvm::APInt(/*numBits=*/32, ArrayLength), in TryOrBuildParenListInitialization()
5654 } else if (auto *RT = Entity.getType()->getAs<RecordType>()) { in TryOrBuildParenListInitialization()
5655 bool IsUnion = RT->isUnionType(); in TryOrBuildParenListInitialization()
5656 const CXXRecordDecl *RD = cast<CXXRecordDecl>(RT->getDecl()); in TryOrBuildParenListInitialization()
5657 if (RD->isInvalidDecl()) { in TryOrBuildParenListInitialization()
5667 for (const CXXBaseSpecifier &Base : RD->bases()) { in TryOrBuildParenListInitialization()
5674 // the elements of the expression-list...The element ei is in TryOrBuildParenListInitialization()
5675 // copy-initialized with xi for 1 <= i <= k. in TryOrBuildParenListInitialization()
5678 E->getExprLoc(), /*isDirectInit=*/false, E); in TryOrBuildParenListInitialization()
5696 for (FieldDecl *FD : RD->fields()) { in TryOrBuildParenListInitialization()
5699 if (FD->isUnnamedBitField()) in TryOrBuildParenListInitialization()
5706 // ...The element ei is copy-initialized with xi for 1 <= i <= k. in TryOrBuildParenListInitialization()
5712 if (FD->getType()->isIncompleteArrayType()) { in TryOrBuildParenListInitialization()
5714 S.Diag(E->getBeginLoc(), diag::err_flexible_array_init) in TryOrBuildParenListInitialization()
5715 << SourceRange(E->getBeginLoc(), E->getEndLoc()); in TryOrBuildParenListInitialization()
5716 S.Diag(FD->getLocation(), diag::note_flexible_array_member) << FD; in TryOrBuildParenListInitialization()
5724 E->getExprLoc(), /*isDirectInit=*/false, E); in TryOrBuildParenListInitialization()
5740 if (FD->hasInClassInitializer()) { in TryOrBuildParenListInitialization()
5755 if (FD->getType()->isReferenceType()) { in TryOrBuildParenListInitialization()
5761 << FD->getType() << SR; in TryOrBuildParenListInitialization()
5762 S.Diag(FD->getLocation(), diag::note_uninit_reference_member); in TryOrBuildParenListInitialization()
5783 int InitKind = T->isArrayType() ? 0 : T->isUnionType() ? 3 : 4; in TryOrBuildParenListInitialization()
5784 SourceRange ExcessInitSR(Args[EntityIndexToProcess]->getBeginLoc(), in TryOrBuildParenListInitialization()
5785 Args.back()->getEndLoc()); in TryOrBuildParenListInitialization()
5801 CPLIE->setArrayFiller(ArrayFiller); in TryOrBuildParenListInitialization()
5803 CPLIE->setInitializedFieldInUnion(InitializedFieldInUnion); in TryOrBuildParenListInitialization()
5811 /// Attempt a user-defined conversion between two types (C++ [dcl.init]),
5820 assert(!DestType->isReferenceType() && "References are handled elsewhere"); in TryUserDefinedConversion()
5821 QualType SourceType = Initializer->getType(); in TryUserDefinedConversion()
5822 assert((DestType->isRecordType() || SourceType->isRecordType()) && in TryUserDefinedConversion()
5823 "Must have a class type to perform a user-defined conversion"); in TryUserDefinedConversion()
5835 if (const RecordType *DestRecordType = DestType->getAs<RecordType>()) { in TryUserDefinedConversion()
5839 = cast<CXXRecordDecl>(DestRecordType->getDecl()); in TryUserDefinedConversion()
5848 if (!Info.Constructor->isInvalidDecl() && in TryUserDefinedConversion()
5849 Info.Constructor->isConvertingConstructor(/*AllowExplicit*/true)) { in TryUserDefinedConversion()
5866 SourceLocation DeclLoc = Initializer->getBeginLoc(); in TryUserDefinedConversion()
5868 if (const RecordType *SourceRecordType = SourceType->getAs<RecordType>()) { in TryUserDefinedConversion()
5876 = cast<CXXRecordDecl>(SourceRecordType->getDecl()); in TryUserDefinedConversion()
5879 SourceRecordDecl->getVisibleConversionFunctions(); in TryUserDefinedConversion()
5882 CXXRecordDecl *ActingDC = cast<CXXRecordDecl>(D->getDeclContext()); in TryUserDefinedConversion()
5884 D = cast<UsingShadowDecl>(D)->getTargetDecl(); in TryUserDefinedConversion()
5889 Conv = cast<CXXConversionDecl>(ConvTemplate->getTemplatedDecl()); in TryUserDefinedConversion()
5913 // In some copy-initialization contexts, a two-stage overload resolution in TryUserDefinedConversion()
5923 FunctionDecl *Function = Best->Function; in TryUserDefinedConversion()
5924 Function->setReferenced(); in TryUserDefinedConversion()
5928 // Add the user-defined conversion step. Any cv-qualification conversion is in TryUserDefinedConversion()
5930 // cv-unqualified type of the destination. in TryUserDefinedConversion()
5931 Sequence.AddUserConversionStep(Function, Best->FoundDecl, in TryUserDefinedConversion()
5936 // - if the function is a constructor, the call initializes a temporary in TryUserDefinedConversion()
5937 // of the cv-unqualified version of the destination type. The [...] in TryUserDefinedConversion()
5938 // temporary [...] is then used to direct-initialize, according to the in TryUserDefinedConversion()
5940 // copy-initialization. in TryUserDefinedConversion()
5944 // - if the function is a constructor, the call is a prvalue of the in TryUserDefinedConversion()
5945 // cv-unqualified version of the destination type whose return object in TryUserDefinedConversion()
5947 // direct-initialize, according to the rules above, the object that in TryUserDefinedConversion()
5948 // is the destination of the copy-initialization. in TryUserDefinedConversion()
5959 // Add the user-defined conversion step that calls the conversion function. in TryUserDefinedConversion()
5960 QualType ConvType = Function->getCallResultType(); in TryUserDefinedConversion()
5961 Sequence.AddUserConversionStep(Function, Best->FoundDecl, ConvType, in TryUserDefinedConversion()
5964 if (ConvType->getAs<RecordType>()) { in TryUserDefinedConversion()
5965 // The call is used to direct-initialize [...] the object that is the in TryUserDefinedConversion()
5966 // destination of the copy-initialization. in TryUserDefinedConversion()
5969 // - If the initializer expression is a prvalue and the cv-unqualified in TryUserDefinedConversion()
5975 Function->getReturnType()->isReferenceType() || in TryUserDefinedConversion()
5985 if (Best->FinalConversion.First || Best->FinalConversion.Second || in TryUserDefinedConversion()
5986 Best->FinalConversion.Third) { in TryUserDefinedConversion()
5989 ICS.Standard = Best->FinalConversion; in TryUserDefinedConversion()
5994 /// An egregious hack for compatibility with libstdc++-4.2: in <tr1/hashtable>,
5999 /// Work around this by treating 'return false;' as zero-initializing the result
6000 /// if it's used in a pointer-returning function in a system header.
6006 Entity.getType()->isPointerType() && in isLibstdcxxPointerReturnFalseHack()
6008 !cast<CXXBoolLiteralExpr>(Init)->getValue() && in isLibstdcxxPointerReturnFalseHack()
6009 S.getSourceManager().isInSystemHeader(Init->getExprLoc()); in isLibstdcxxPointerReturnFalseHack()
6012 /// The non-zero enum values here are indexes into diagnostic alternatives.
6019 e = e->IgnoreParens(); in isInvalidICRSource()
6021 // Skip address-of nodes. in isInvalidICRSource()
6023 if (op->getOpcode() == UO_AddrOf) in isInvalidICRSource()
6024 return isInvalidICRSource(C, op->getSubExpr(), /*addressof*/ true, in isInvalidICRSource()
6029 switch (ce->getCastKind()) { in isInvalidICRSource()
6034 return isInvalidICRSource(C, ce->getSubExpr(), isAddressOf, isWeakAccess); in isInvalidICRSource()
6050 if (e->getType().getObjCLifetime() == Qualifiers::OCL_Weak) in isInvalidICRSource()
6055 VarDecl *var = dyn_cast<VarDecl>(cast<DeclRefExpr>(e)->getDecl()); in isInvalidICRSource()
6058 return (var->hasLocalStorage() ? IIK_okay : IIK_nonlocal); in isInvalidICRSource()
6062 if (InvalidICRKind iik = isInvalidICRSource(C, cond->getLHS(), isAddressOf, in isInvalidICRSource()
6066 return isInvalidICRSource(C, cond->getRHS(), isAddressOf, isWeakAccess); in isInvalidICRSource()
6074 return (e->isNullPointerConstant(C, Expr::NPC_ValueDependentIsNull) in isInvalidICRSource()
6084 assert(src->isPRValue()); in checkIndirectCopyRestoreSource()
6094 S.Diag(src->getExprLoc(), diag::err_arc_nonlocal_writeback) in checkIndirectCopyRestoreSource()
6095 << ((unsigned) iik - 1) // shift index into diagnostic explanations in checkIndirectCopyRestoreSource()
6096 << src->getSourceRange(); in checkIndirectCopyRestoreSource()
6100 /// purposes of GNU by-copy array initialization.
6109 if (!Context.hasSameType(Dest->getElementType(), Source->getElementType())) in hasCompatibleArrayTypes()
6114 return Source->isConstantArrayType() && Dest->isIncompleteArrayType(); in hasCompatibleArrayTypes()
6122 QualType ArgType = Initializer->getType(); in tryObjCWritebackConversion()
6126 ArgPointee = ArgArrayType->getElementType(); in tryObjCWritebackConversion()
6130 // Handle write-back conversion. in tryObjCWritebackConversion()
6140 ShouldCopy = (param->getObjCDeclQualifier() != ParmVarDecl::OBJC_TQ_Out); in tryObjCWritebackConversion()
6143 if (ArrayDecay || Initializer->isGLValue()) { in tryObjCWritebackConversion()
6154 ResultType = Initializer->getType().getNonLValueExprType(S.Context); in tryObjCWritebackConversion()
6168 if (!S.getLangOpts().OpenCL || !DestType->isSamplerT() || in TryOCLSamplerInitialization()
6169 (!Initializer->isIntegerConstantExpr(S.Context) && in TryOCLSamplerInitialization()
6170 !Initializer->getType()->isSamplerT())) in TryOCLSamplerInitialization()
6178 return Initializer->isIntegerConstantExpr(S.getASTContext()) && in IsZeroInitializer()
6179 (Initializer->EvaluateKnownConstInt(S.getASTContext()) == 0); in IsZeroInitializer()
6197 if (DestType->isEventT() || DestType->isQueueT()) { in TryOCLZeroOpaqueTypeInitialization()
6210 DestType->isOCLIntelSubgroupAVCType()) { in TryOCLZeroOpaqueTypeInitialization()
6211 if (DestType->isOCLIntelSubgroupAVCMcePayloadType() || in TryOCLZeroOpaqueTypeInitialization()
6212 DestType->isOCLIntelSubgroupAVCMceResultType()) in TryOCLZeroOpaqueTypeInitialization()
6237 if (!DRE || !isa<FunctionDecl>(DRE->getDecl())) in isExprAnUnaddressableFunction()
6241 cast<FunctionDecl>(DRE->getDecl())); in isExprAnUnaddressableFunction()
6250 // For array members, the array elements are direct-initialized in in canPerformArrayCopy()
6256 // [...] each element is copy-initialized or direct-initialized from the in canPerformArrayCopy()
6257 // corresponding element of the assignment-expression [...] in canPerformArrayCopy()
6262 // - if the member is an array, each element is direct-initialized with in canPerformArrayCopy()
6288 // Eliminate non-overload placeholder types in the arguments. We in InitializeFrom()
6290 // because lowering a pseudo-object expression might well give us in InitializeFrom()
6293 if (Args[I]->getType()->isNonOverloadPlaceholderType()) { in InitializeFrom()
6307 // defined when the initializer is a braced-init-list or when it is a in InitializeFrom()
6311 if (DestType->isDependentType() || in InitializeFrom()
6326 Initializer->getBeginLoc(), DestType, Initializer->getType(), in InitializeFrom()
6332 SourceType = Initializer->getType(); in InitializeFrom()
6335 // - If the initializer is a (non-parenthesized) braced-init-list, the in InitializeFrom()
6336 // object is list-initialized (8.5.4). in InitializeFrom()
6345 // - If the destination type is a reference type, see 8.5.3. in InitializeFrom()
6346 if (DestType->isReferenceType()) { in InitializeFrom()
6366 // - If the initializer is (), the object is value-initialized. in InitializeFrom()
6379 // - If the destination type is an array of characters, an array of in InitializeFrom()
6382 // - Otherwise, if the destination type is an array, the program is in InitializeFrom()
6383 // ill-formed. in InitializeFrom()
6384 // - Except in HLSL, where non-decaying array parameters behave like in InitializeFrom()
6385 // non-array types for initialization. in InitializeFrom()
6386 if (DestType->isArrayType() && !DestType->isArrayParameterType()) { in InitializeFrom()
6421 S.Context.hasSameUnqualifiedType(Initializer->getType(), in InitializeFrom()
6425 if (Initializer->isPRValue()) { in InitializeFrom()
6430 // Emit element-at-a-time copy loop. in InitializeFrom()
6434 Context.getAsArrayType(Initializer->getType())->getElementType(); in InitializeFrom()
6435 OpaqueValueExpr OVE(Initializer->getExprLoc(), InitEltT, in InitializeFrom()
6436 Initializer->getValueKind(), in InitializeFrom()
6437 Initializer->getObjectKind()); in InitializeFrom()
6448 // type, so long as the initializer has no side effects. in InitializeFrom()
6450 isa<CompoundLiteralExpr>(Initializer->IgnoreParens()) && in InitializeFrom()
6451 Initializer->getType()->isArrayType()) { in InitializeFrom()
6453 = Context.getAsArrayType(Initializer->getType()); in InitializeFrom()
6456 else if (Initializer->HasSideEffects(S.Context)) in InitializeFrom()
6462 // Note: as a GNU C++ extension, we allow list-initialization of a in InitializeFrom()
6474 else if (DestAT->getElementType()->isCharType()) in InitializeFrom()
6476 else if (IsWideCharCompatible(DestAT->getElementType(), Context)) in InitializeFrom()
6485 // Objective-C ARC. in InitializeFrom()
6492 // We're at the end of the line for C: it's either a write-back conversion in InitializeFrom()
6493 // or it's a C assignment. There's no need to check anything else. in InitializeFrom()
6495 assert(Initializer && "Initializer must be non-null"); in InitializeFrom()
6496 // If allowed, check whether this is an Objective-C writeback conversion. in InitializeFrom()
6513 // - If the destination type is a (possibly cv-qualified) class type: in InitializeFrom()
6514 if (DestType->isRecordType()) { in InitializeFrom()
6515 // - If the initialization is direct-initialization, or if it is in InitializeFrom()
6516 // copy-initialization where the cv-unqualified version of the in InitializeFrom()
6522 (Initializer && S.IsDerivedFrom(Initializer->getBeginLoc(), in InitializeFrom()
6527 // We fall back to the "no matching constructor" path if the in InitializeFrom()
6531 dyn_cast<CXXRecordDecl>(DestType->getAs<RecordType>()->getDecl()); in InitializeFrom()
6535 S.getLangOpts().CPlusPlus20 && RD && RD->hasDefinition() && in InitializeFrom()
6536 RD->isAggregate() && Failed() && in InitializeFrom()
6542 // a non-trivial copy or move constructor and we call one of those two in InitializeFrom()
6552 // - Otherwise, if no constructor is viable, the destination type is in InitializeFrom()
6555 // expression-list. in InitializeFrom()
6561 // - Otherwise (i.e., for the remaining copy-initialization cases), in InitializeFrom()
6562 // user-defined conversion sequences that can convert from the in InitializeFrom()
6567 assert(Initializer && "Initializer must be non-null"); in InitializeFrom()
6574 assert(Args.size() >= 1 && "Zero-argument case handled above"); in InitializeFrom()
6579 if (S.getLangOpts().HLSL && Args.size() > 1 && DestType->isExtVectorType() && in InitializeFrom()
6585 if (Arg->getType()->isExtVectorType()) { in InitializeFrom()
6586 const auto *VTy = Arg->getType()->castAs<ExtVectorType>(); in InitializeFrom()
6587 unsigned Elm = VTy->getNumElements(); in InitializeFrom()
6594 VTy->getElementType(), Arg->getValueKind(), Arg->getObjectKind(), in InitializeFrom()
6616 // - Otherwise, if the source type is a (possibly cv-qualified) class in InitializeFrom()
6618 if (!SourceType.isNull() && SourceType->isRecordType()) { in InitializeFrom()
6619 assert(Initializer && "Initializer must be non-null"); in InitializeFrom()
6623 if (const AtomicType *Atomic = DestType->getAs<AtomicType>()) { in InitializeFrom()
6624 if (Context.hasSameUnqualifiedType(SourceType, Atomic->getValueType()) || in InitializeFrom()
6625 S.IsDerivedFrom(Initializer->getBeginLoc(), SourceType, in InitializeFrom()
6626 Atomic->getValueType())) { in InitializeFrom()
6627 DestType = Atomic->getValueType(); in InitializeFrom()
6640 // - Otherwise, if the initialization is direct-initialization, the source in InitializeFrom()
6643 if (!SourceType.isNull() && SourceType->isNullPtrType() && in InitializeFrom()
6644 DestType->isBooleanType() && in InitializeFrom()
6648 Initializer->isGLValue()), in InitializeFrom()
6653 // - Otherwise, the initial value of the object being initialized is the in InitializeFrom()
6656 // initializer expression to the cv-unqualified version of the in InitializeFrom()
6657 // destination type; no user-defined conversions are considered. in InitializeFrom()
6669 // Objective-C ARC writeback conversion. in InitializeFrom()
6675 ShouldCopy = (Param->getObjCDeclQualifier() != ParmVarDecl::OBJC_TQ_Out); in InitializeFrom()
6693 Initializer->getType() == Context.OverloadTy && in InitializeFrom()
6697 else if (Initializer->getType()->isFunctionType() && in InitializeFrom()
6714 //===----------------------------------------------------------------------===//
6716 //===----------------------------------------------------------------------===//
6729 isa<ObjCMethodDecl>(Entity.getDecl()->getDeclContext())) in getAssignmentAction()
6736 isa<ObjCMethodDecl>(Entity.getDecl()->getDeclContext())) in getAssignmentAction()
6852 return Entity.getDecl()->getLocation(); in getInitializationLoc()
6873 return Initializer->getBeginLoc(); in getInitializationLoc()
6882 /// \param S The Sema object used for type-checking.
6908 if (const RecordType *Record = T->getAs<RecordType>()) in CopyObject()
6909 Class = cast<CXXRecordDecl>(Record->getDecl()); in CopyObject()
6921 // is direct-initialization. in CopyObject()
6941 << (int)Entity.getKind() << CurInitExpr->getType() in CopyObject()
6942 << CurInitExpr->getSourceRange()), in CopyObject()
6952 << CurInitExpr->getType() in CopyObject()
6953 << CurInitExpr->getSourceRange()), in CopyObject()
6959 << (int)Entity.getKind() << CurInitExpr->getType() in CopyObject()
6960 << CurInitExpr->getSourceRange(); in CopyObject()
6961 S.NoteDeletedFunction(Best->Function); in CopyObject()
6967 CXXConstructorDecl *Constructor = cast<CXXConstructorDecl>(Best->Function); in CopyObject()
6971 S.CheckConstructorAccess(Loc, Constructor, Best->FoundDecl, Entity, in CopyObject()
6985 for (unsigned I = 1, N = Constructor->getNumParams(); I != N; ++I) { in CopyObject()
6986 ParmVarDecl *Parm = Constructor->getParamDecl(I); in CopyObject()
6987 if (S.RequireCompleteType(Loc, Parm->getType(), in CopyObject()
7001 // constructor call (we might have derived-to-base conversions, or in CopyObject()
7012 // - when a temporary class object that has not been bound to a in CopyObject()
7014 // with the same cv-unqualified type, the copy/move operation in CopyObject()
7021 // is handled by the run-time. in CopyObject()
7027 CurInitExpr->isTemporaryObject(S.Context, Class) && in CopyObject()
7029 Best->Function->getParamDecl(0)->getType().getNonReferenceType(), in CopyObject()
7030 CurInitExpr->getType()); in CopyObject()
7034 Loc, T, Best->FoundDecl, Constructor, Elidable, ConstructorArgs, in CopyObject()
7048 /// -Wc++98-compat.
7054 const RecordType *Record = CurInitExpr->getType()->getAs<RecordType>(); in CheckCXX98CompatAccessibleCopy()
7065 S.LookupConstructors(cast<CXXRecordDecl>(Record->getDecl())); in CheckCXX98CompatAccessibleCopy()
7070 S, Loc, CurInitExpr, CandidateSet, CurInitExpr->getType(), Ctors, Best, in CheckCXX98CompatAccessibleCopy()
7077 << OR << (int)Entity.getKind() << CurInitExpr->getType() in CheckCXX98CompatAccessibleCopy()
7078 << CurInitExpr->getSourceRange(); in CheckCXX98CompatAccessibleCopy()
7082 S.CheckConstructorAccess(Loc, cast<CXXConstructorDecl>(Best->Function), in CheckCXX98CompatAccessibleCopy()
7083 Best->FoundDecl, Entity, Diag); in CheckCXX98CompatAccessibleCopy()
7099 S.NoteDeletedFunction(Best->Function); in CheckCXX98CompatAccessibleCopy()
7107 if (Entity.getDecl()->getLocation().isInvalid()) in PrintInitLocationNote()
7110 if (Entity.getDecl()->getDeclName()) in PrintInitLocationNote()
7111 S.Diag(Entity.getDecl()->getLocation(), diag::note_parameter_named_here) in PrintInitLocationNote()
7112 << Entity.getDecl()->getDeclName(); in PrintInitLocationNote()
7114 S.Diag(Entity.getDecl()->getLocation(), diag::note_parameter_here); in PrintInitLocationNote()
7118 S.Diag(Entity.getMethodDecl()->getLocation(), in PrintInitLocationNote()
7120 << Entity.getMethodDecl()->getDeclName(); in PrintInitLocationNote()
7175 assert(Constructor->getParent() && "No parent class for constructor."); in PerformConstructorInitialization()
7176 if (Constructor->isDefaulted() && Constructor->isDefaultConstructor() && in PerformConstructorInitialization()
7177 Constructor->isTrivial() && !Constructor->isUsed(false)) { in PerformConstructorInitialization()
7187 // - When initializing a temporary to be bound to the first parameter in PerformConstructorInitialization()
7188 // of a constructor that takes a reference to possibly cv-qualified in PerformConstructorInitialization()
7190 // context of direct-initialization, explicit conversion functions in PerformConstructorInitialization()
7200 Entity.getType(), Args.front()->getType(), Kind.getLocation()); in PerformConstructorInitialization()
7210 // An explicitly-constructed temporary, e.g., X(1, 2). in PerformConstructorInitialization()
7241 ConstructKind = Entity.getBaseSpecifier()->isVirtual() in PerformConstructorInitialization()
7322 QualType DestType = InitExpr->getType(); in CheckMoveOnConstruction()
7323 if (!DestType->isRecordType()) in CheckMoveOnConstruction()
7329 dyn_cast<CXXConstructExpr>(InitExpr->IgnoreParens()); in CheckMoveOnConstruction()
7330 if (!CCE || CCE->getNumArgs() != 1) in CheckMoveOnConstruction()
7333 if (!CCE->getConstructor()->isCopyOrMoveConstructor()) in CheckMoveOnConstruction()
7336 InitExpr = CCE->getArg(0)->IgnoreImpCasts(); in CheckMoveOnConstruction()
7340 const CallExpr *CE = dyn_cast<CallExpr>(InitExpr->IgnoreParens()); in CheckMoveOnConstruction()
7341 if (!CE || !CE->isCallToStdMove()) in CheckMoveOnConstruction()
7344 const Expr *Arg = CE->getArg(0)->IgnoreImplicit(); in CheckMoveOnConstruction()
7347 const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Arg->IgnoreParenImpCasts()); in CheckMoveOnConstruction()
7348 if (!DRE || DRE->refersToEnclosingVariableOrCapture()) in CheckMoveOnConstruction()
7351 const VarDecl *VD = dyn_cast<VarDecl>(DRE->getDecl()); in CheckMoveOnConstruction()
7352 if (!VD || !VD->hasLocalStorage()) in CheckMoveOnConstruction()
7356 if (VD->hasAttr<BlocksAttr>()) in CheckMoveOnConstruction()
7359 QualType SourceType = VD->getType(); in CheckMoveOnConstruction()
7360 if (!SourceType->isRecordType()) in CheckMoveOnConstruction()
7375 const Expr *ArgStripped = Arg->IgnoreImplicit()->IgnoreParens(); in CheckMoveOnConstruction()
7376 if (!ArgStripped->isPRValue() || !ArgStripped->getType()->isRecordType()) in CheckMoveOnConstruction()
7380 S.Diag(CE->getBeginLoc(), DiagID); in CheckMoveOnConstruction()
7382 // Get all the locations for a fix-it. Don't emit the fix-it if any location in CheckMoveOnConstruction()
7384 SourceLocation CallBegin = CE->getCallee()->getBeginLoc(); in CheckMoveOnConstruction()
7387 SourceLocation RParen = CE->getRParenLoc(); in CheckMoveOnConstruction()
7391 SourceLocation ArgLoc = Arg->getBeginLoc(); in CheckMoveOnConstruction()
7393 // Special testing for the argument location. Since the fix-it needs the in CheckMoveOnConstruction()
7404 LParen = ArgLoc.getLocWithOffset(-1); in CheckMoveOnConstruction()
7406 S.Diag(CE->getBeginLoc(), diag::note_remove_move) in CheckMoveOnConstruction()
7415 if (const UnaryOperator *UO = dyn_cast<UnaryOperator>(E->IgnoreParenCasts())) in CheckForNullPointerDereference()
7416 if (UO->getOpcode() == UO_Deref && in CheckForNullPointerDereference()
7417 UO->getSubExpr()->IgnoreParenCasts()-> in CheckForNullPointerDereference()
7419 S.DiagRuntimeBehavior(UO->getOperatorLoc(), UO, in CheckForNullPointerDereference()
7421 << UO->getSubExpr()->getSourceRange()); in CheckForNullPointerDereference()
7450 if (!E->isPRValue() || !getLangOpts().CPlusPlus11) in TemporaryMaterializationConversion()
7455 // If so, we should check for a non-abstract class type here too. in TemporaryMaterializationConversion()
7456 QualType T = E->getType(); in TemporaryMaterializationConversion()
7457 if (RequireCompleteType(E->getExprLoc(), T, diag::err_incomplete_type)) in TemporaryMaterializationConversion()
7460 return CreateMaterializeTemporaryExpr(E->getType(), E, false); in TemporaryMaterializationConversion()
7470 auto PointeeTy = Ty->getPointeeType(); in PerformQualificationConversion()
7471 auto ExprPointeeTy = E->getType()->getPointeeType(); in PerformQualificationConversion()
7475 } else if (Ty.getAddressSpace() != E->getType().getAddressSpace()) { in PerformQualificationConversion()
7499 if (!DestType->isRecordType() && VD && VD->isConstexpr()) { in Perform()
7507 if (S.getLangOpts().MSVCCompat && D && D->hasAttr<SelectAnyAttr>()) in Perform()
7511 << DestType << (bool)DestType->getAs<RecordType>() in Perform()
7518 // If the declaration is a non-dependent, incomplete array type in Perform()
7521 if (ResultType && !Entity.getType()->isDependentType() && in Perform()
7528 // performing full type-checking of the initializer list in Perform()
7531 // type a dependently-sized array type with no specified in Perform()
7538 if (TypeSourceInfo *TInfo = DD->getTypeSourceInfo()) { in Perform()
7539 TypeLoc TL = TInfo->getTypeLoc(); in Perform()
7547 = S.Context.getDependentSizedArrayType(ArrayT->getElementType(), in Perform()
7549 ArrayT->getSizeModifier(), in Perform()
7550 ArrayT->getIndexTypeCVRQualifiers(), in Perform()
7569 // No steps means no initialization. in Perform()
7573 if (S.getLangOpts().CPlusPlus11 && Entity.getType()->isReferenceType() && in Perform()
7580 S.Diag(Init->getBeginLoc(), diag::warn_cxx98_compat_reference_list_init) in Perform()
7581 << Init->getSourceRange(); in Perform()
7585 isa<PredefinedExpr>(Args[0]) && Entity.getType()->isArrayType()) { in Perform()
7590 S.Diag(Init->getBeginLoc(), diag::ext_init_from_predefined) << Init; in Perform()
7599 ETy->isAtomicType() && !HasGlobalAS && in Perform()
7601 S.Diag(Args[0]->getBeginLoc(), diag::err_opencl_atomic_init) in Perform()
7603 << SourceRange(Entity.getDecl()->getBeginLoc(), Args[0]->getEndLoc()); in Perform()
7609 // the same as Entity.getDecl()->getType() in cases involving type merging, in Perform()
7612 *ResultType = Entity.getDecl() ? Entity.getDecl()->getType() : in Perform()
7619 // use the syntax of a C++-like constructor. in Perform()
7620 bool IsHLSLVectorInit = S.getLangOpts().HLSL && DestType->isExtVectorType() && in Perform()
7676 // C++11 list-initialization; we need to instantiate entities usable in in Perform()
7683 // no objects of an abstract class can be created except as subobjects in Perform()
7685 auto checkAbstractType = [&](QualType T) -> bool { in Perform()
7701 QualType SourceType = CurInit.get() ? CurInit.get()->getType() : QualType(); in Perform()
7703 switch (Step->Kind) { in Perform()
7707 S.CheckAddressOfMemberAccess(CurInit.get(), Step->Function.FoundDecl); in Perform()
7708 if (S.DiagnoseUseOfDecl(Step->Function.FoundDecl, Kind.getLocation())) in Perform()
7711 Step->Function.FoundDecl, in Perform()
7712 Step->Function.Function); in Perform()
7722 // We have a derived-to-base cast that produces either an rvalue or an in Perform()
7727 // Casts to inaccessible base classes are allowed with C-style casts. in Perform()
7730 SourceType, Step->Type, CurInit.get()->getBeginLoc(), in Perform()
7731 CurInit.get()->getSourceRange(), &BasePath, IgnoreBaseAccess)) in Perform()
7735 Step->Kind == SK_CastDerivedToBaseLValue in Perform()
7737 : (Step->Kind == SK_CastDerivedToBaseXValue ? VK_XValue in Perform()
7739 CurInit = ImplicitCastExpr::Create(S.Context, Step->Type, in Perform()
7755 if (CurInit.get()->getType()->isFunctionProtoType()) { in Perform()
7756 if (auto *DRE = dyn_cast<DeclRefExpr>(CurInit.get()->IgnoreParens())) { in Perform()
7757 if (auto *FD = dyn_cast<FunctionDecl>(DRE->getDecl())) { in Perform()
7759 DRE->getBeginLoc())) in Perform()
7770 assert(CurInit.get()->isPRValue() && "not a temporary"); in Perform()
7776 QualType MTETy = Step->Type; in Perform()
7781 if (MTETy->isIncompleteArrayType() && in Perform()
7782 !CurInit.get()->getType()->isIncompleteArrayType() && in Perform()
7784 MTETy->getPointeeOrArrayElementType(), in Perform()
7785 CurInit.get()->getType()->getPointeeOrArrayElementType())) in Perform()
7786 MTETy = CurInit.get()->getType(); in Perform()
7790 MTETy, CurInit.get(), Entity.getType()->isLValueReferenceType()); in Perform()
7793 // If we're extending this temporary to automatic storage duration -- we in Perform()
7794 // need to register its cleanup during the full-expression's cleanups. in Perform()
7795 if (MTE->getStorageDuration() == SD_Automatic && in Perform()
7796 MTE->getType().isDestructedType()) in Perform()
7802 if (checkAbstractType(Step->Type)) in Perform()
7807 // ultimately initializing a non-temporary), our argument needs to be in Perform()
7812 CurInit = CopyObject(S, Step->Type, Entity, CurInit, in Perform()
7817 CurInit = CopyObject(S, Step->Type, Entity, CurInit, in Perform()
7822 // We have a user-defined conversion that invokes either a constructor in Perform()
7825 FunctionDecl *Fn = Step->Function.Function; in Perform()
7826 DeclAccessPair FoundFn = Step->Function.FoundDecl; in Perform()
7827 bool HadMultipleCandidates = Step->Function.HadMultipleCandidates; in Perform()
7832 SourceLocation Loc = CurInit.get()->getBeginLoc(); in Perform()
7837 if (S.CompleteConstructorCall(Constructor, Step->Type, in Perform()
7844 Loc, Step->Type, FoundFn, Constructor, ConstructorArgs, in Perform()
7873 CreatedObject = Conversion->getReturnType()->isRecordType(); in Perform()
7876 if (CreatedObject && checkAbstractType(CurInit.get()->getType())) in Perform()
7880 S.Context, CurInit.get()->getType(), CastKind, CurInit.get(), nullptr, in Perform()
7881 CurInit.get()->getValueKind(), S.CurFPFeatureOverrides()); in Perform()
7885 // destroyed at the end of its full-expression. in Perform()
7888 // The object outlasts the full-expression, but we need to prepare for in Perform()
7890 // FIXME: It makes no sense to do this here. This should happen in Perform()
7892 QualType T = CurInit.get()->getType(); in Perform()
7893 if (const RecordType *Record = T->getAs<RecordType>()) { in Perform()
7895 = S.LookupDestructor(cast<CXXRecordDecl>(Record->getDecl())); in Perform()
7896 S.CheckDestructorAccess(CurInit.get()->getBeginLoc(), Destructor, in Perform()
7898 S.MarkFunctionReferenced(CurInit.get()->getBeginLoc(), Destructor); in Perform()
7899 if (S.DiagnoseUseOfDecl(Destructor, CurInit.get()->getBeginLoc())) in Perform()
7911 Step->Kind == SK_QualificationConversionLValue in Perform()
7913 : (Step->Kind == SK_QualificationConversionXValue ? VK_XValue in Perform()
7915 CurInit = S.PerformQualificationConversion(CurInit.get(), Step->Type, VK); in Perform()
7920 assert(CurInit.get()->isLValue() && in Perform()
7923 S.ImpCastExprToType(CurInit.get(), Step->Type, CK_NoOp, VK_LValue); in Perform()
7927 assert(CurInit.get()->isPRValue() && "cannot convert glvalue to atomic"); in Perform()
7928 CurInit = S.ImpCastExprToType(CurInit.get(), Step->Type, in Perform()
7936 CurInit.get()->getType()->getAs<PointerType>()) { in Perform()
7937 if (const auto *ToPtrType = Step->Type->getAs<PointerType>()) { in Perform()
7938 if (FromPtrType->getPointeeType()->hasAttr(attr::NoDeref) && in Perform()
7939 !ToPtrType->getPointeeType()->hasAttr(attr::NoDeref)) { in Perform()
7943 S.Diag(CurInit.get()->getExprLoc(), in Perform()
7945 << CurInit.get()->getSourceRange(); in Perform()
7957 Init, Step->Type, *Step->ICS, getAssignmentAction(Entity), CCK); in Perform()
7961 S.DiscardMisalignedMemberAddress(Step->Type.getTypePtr(), Init); in Perform()
7965 if (Step->Kind == SK_ConversionSequenceNoNarrowing && in Perform()
7967 DiagnoseNarrowingInInitList(S, *Step->ICS, SourceType, Entity.getType(), in Perform()
7974 if (checkAbstractType(Step->Type)) in Perform()
7978 // If we're not initializing the top-level entity, we need to create an in Perform()
7980 QualType Ty = Step->Type; in Perform()
7994 ResultType->getNonReferenceType()->isIncompleteArrayType()) { in Perform()
7995 if ((*ResultType)->isRValueReferenceType()) in Perform()
7997 else if ((*ResultType)->isLValueReferenceType()) in Perform()
7999 (*ResultType)->castAs<LValueReferenceType>()->isSpelledAsLValue()); in Perform()
8013 if (checkAbstractType(Step->Type)) in Perform()
8024 bool UseTemporary = Entity.getType()->isReferenceType(); in Perform()
8027 S.Diag(InitList->getExprLoc(), diag::warn_cxx98_compat_ctor_list_init) in Perform()
8028 << InitList->getSourceRange(); in Perform()
8029 MultiExprArg Arg(InitList->getInits(), InitList->getNumInits()); in Perform()
8036 InitList->getLBraceLoc(), in Perform()
8037 InitList->getRBraceLoc()); in Perform()
8042 CurInit = cast<InitListExpr>(CurInit.get())->getInit(0); in Perform()
8047 InitListExpr *Syntactic = Step->WrappingSyntacticList; in Perform()
8049 Syntactic->getLBraceLoc(), E, Syntactic->getRBraceLoc()); in Perform()
8050 ILE->setSyntacticForm(Syntactic); in Perform()
8051 ILE->setType(E->getType()); in Perform()
8052 ILE->setValueKind(E->getValueKind()); in Perform()
8059 if (checkAbstractType(Step->Type)) in Perform()
8070 bool UseTemporary = Entity.getType()->isReferenceType(); in Perform()
8072 Step->Kind == SK_StdInitializerListConstructorCall; in Perform()
8092 (NextStep->Kind == SK_ConstructorInitialization || in Perform()
8093 NextStep->Kind == SK_ConstructorInitializationFromList)) { in Perform()
8094 // The need for zero-initialization is recorded directly into in Perform()
8102 TSInfo = S.Context.getTrivialTypeSourceInfo(Step->Type, in Perform()
8109 CurInit = new (S.Context) ImplicitValueInitExpr(Step->Type); in Perform()
8115 QualType SourceType = CurInit.get()->getType(); in Perform()
8122 S.CheckSingleAssignmentConstraints(Step->Type, Result, true, in Perform()
8132 S.CheckTransparentUnionArgumentConstraints(Step->Type, CurInitExprRes) in Perform()
8143 // C23 6.7.1p6: If an object or subobject declared with storage-class in Perform()
8149 if (Entity.getType()->getAs<PointerType>() && in Perform()
8150 CurInit.get()->EvaluateAsRValue(ER, S.Context) && in Perform()
8158 Step->Type, SourceType, in Perform()
8170 QualType Ty = Step->Type; in Perform()
8171 bool UpdateType = ResultType && Entity.getType()->isIncompleteArrayType(); in Perform()
8180 CurInit = S.ImpCastExprToType(CurInit.get(), Step->Type, in Perform()
8182 CurInit.get()->getValueKind()); in Perform()
8188 OpaqueValueExpr(Cur->getExprLoc(), Cur->getType(), in Perform()
8189 Cur->getValueKind(), Cur->getObjectKind(), Cur); in Perform()
8202 CurInit = new (S.Context) ArrayInitLoopExpr(Step->Type, Common, in Perform()
8211 << Step->Type << CurInit.get()->getType() in Perform()
8212 << CurInit.get()->getSourceRange(); in Perform()
8220 = S.Context.getAsIncompleteArrayType(Step->Type)) { in Perform()
8222 = S.Context.getAsConstantArrayType(CurInit.get()->getType())) { in Perform()
8224 IncompleteDest->getElementType(), ConstantSource->getSize(), in Perform()
8225 ConstantSource->getSizeExpr(), ArraySizeModifier::Normal, 0); in Perform()
8235 << CurInit.get()->getSourceRange(); in Perform()
8242 CurInit.get(), Step->Type, in Perform()
8243 Step->Kind == SK_PassByIndirectCopyRestore); in Perform()
8248 S.Context, Step->Type, CK_ARCProduceObject, CurInit.get(), nullptr, in Perform()
8253 S.Diag(CurInit.get()->getExprLoc(), in Perform()
8255 << CurInit.get()->getSourceRange(); in Perform()
8259 CurInit.get()->getType(), CurInit.get(), in Perform()
8263 CurInit = new (S.Context) CXXStdInitializerListExpr(Step->Type, MTE); in Perform()
8265 if (!Step->Type->isDependentType()) { in Perform()
8268 S.isStdInitializerList(Step->Type, &ElementType); in Perform()
8270 "StdInitializerList step to non-std::initializer_list"); in Perform()
8272 Step->Type->getAsCXXRecordDecl()->getDefinition(); in Perform()
8273 assert(Record && Record->isCompleteDefinition() && in Perform()
8278 S.Diag(Record->getLocation(), in Perform()
8280 << Step->Type.getUnqualifiedType(); in Perform()
8284 if (Record->isUnion() || Record->getNumBases() != 0 || in Perform()
8285 Record->isPolymorphic()) in Perform()
8288 RecordDecl::field_iterator Field = Record->field_begin(); in Perform()
8289 if (Field == Record->field_end()) in Perform()
8293 if (!Field->getType()->isPointerType() || in Perform()
8294 !S.Context.hasSameType(Field->getType()->getPointeeType(), in Perform()
8298 if (++Field == Record->field_end()) in Perform()
8302 if (const auto *PT = Field->getType()->getAs<PointerType>()) { in Perform()
8303 if (!S.Context.hasSameType(PT->getPointeeType(), in Perform()
8307 if (Field->isBitField() || in Perform()
8308 !S.Context.hasSameType(Field->getType(), S.Context.getSizeType())) in Perform()
8312 if (++Field != Record->field_end()) in Perform()
8317 // non-trivial destructor. in Perform()
8326 // 1a. argument is a file-scope variable in Perform()
8327 // 1b. argument is a function-scope variable in Perform()
8330 // 2a. initializing a file-scope variable in Perform()
8331 // 2b. initializing a function-scope variable in Perform()
8333 // For file-scope variables, since they cannot be initialized by function in Perform()
8339 assert(Step->Type->isSamplerT() && in Perform()
8340 "Sampler initialization on non-sampler type."); in Perform()
8341 Expr *Init = CurInit.get()->IgnoreParens(); in Perform()
8342 QualType SourceType = Init->getType(); in Perform()
8345 if (!SourceType->isSamplerT() && !SourceType->isIntegerType()) { in Perform()
8350 auto Var = cast<VarDecl>(DRE->getDecl()); in Perform()
8352 // No cast from integer to sampler is needed. in Perform()
8353 if (!Var->hasGlobalStorage()) { in Perform()
8355 S.Context, Step->Type, CK_LValueToRValue, Init, in Perform()
8360 // For function call with a file-scope sampler variable as argument, in Perform()
8362 // Do not diagnose if the file-scope variable does not have initializer in Perform()
8365 if (!Var->getInit() || !isa<ImplicitCastExpr>(Var->getInit())) in Perform()
8368 Var->getInit()))->getSubExpr(); in Perform()
8369 SourceType = Init->getType(); in Perform()
8376 if (!Init->isConstantInitializer(S.Context, false)) in Perform()
8379 if (!SourceType->isIntegerType() || in Perform()
8387 Init->EvaluateAsInt(EVResult, S.Context); in Perform()
8390 // 32-bit value of sampler's initializer is interpreted as in Perform()
8391 // bit-field with the following structure: in Perform()
8395 // defined in SPIR spec v1.2 and also opencl-c.h in Perform()
8417 assert((Step->Type->isEventT() || Step->Type->isQueueT() || in Perform()
8418 Step->Type->isOCLIntelSubgroupAVCType()) && in Perform()
8421 CurInit = S.ImpCastExprToType(CurInit.get(), Step->Type, in Perform()
8423 CurInit.get()->getValueKind()); in Perform()
8431 *ResultType = CurInit.get()->getType(); in Perform()
8444 // entity, and if not, either lifetime-extend or warn as appropriate. in Perform()
8447 // Diagnose non-fatal problems with the completed initialization. in Perform()
8451 cast<FieldDecl>(Entity.getDecl())->isBitField()) in Perform()
8466 if (T->isReferenceType()) { in DiagnoseUninitializedReference()
8472 CXXRecordDecl *RD = T->getBaseElementTypeUnsafe()->getAsCXXRecordDecl(); in DiagnoseUninitializedReference()
8473 if (!RD || !RD->hasUninitializedReferenceMember()) in DiagnoseUninitializedReference()
8476 for (const auto *FI : RD->fields()) { in DiagnoseUninitializedReference()
8477 if (FI->isUnnamedBitField()) in DiagnoseUninitializedReference()
8480 if (DiagnoseUninitializedReference(S, FI->getLocation(), FI->getType())) { in DiagnoseUninitializedReference()
8486 for (const auto &BI : RD->bases()) { in DiagnoseUninitializedReference()
8497 //===----------------------------------------------------------------------===//
8499 //===----------------------------------------------------------------------===//
8506 if (destType.getNonReferenceType()->isObjCObjectPointerType() && in emitBadConversionNotes()
8507 op->getType()->isObjCObjectPointerType()) { in emitBadConversionNotes()
8518 QualType fromType = op->getType(); in emitBadConversionNotes()
8519 QualType fromPointeeType = fromType.getCanonicalType()->getPointeeType(); in emitBadConversionNotes()
8520 QualType destPointeeType = destType.getCanonicalType()->getPointeeType(); in emitBadConversionNotes()
8521 auto *fromDecl = fromType->getPointeeCXXRecordDecl(); in emitBadConversionNotes()
8522 auto *destDecl = destType->getPointeeCXXRecordDecl(); in emitBadConversionNotes()
8523 if (fromDecl && destDecl && fromDecl->getDeclKind() == Decl::CXXRecord && in emitBadConversionNotes()
8524 destDecl->getDeclKind() == Decl::CXXRecord && in emitBadConversionNotes()
8525 !fromDecl->isInvalidDecl() && !destDecl->isInvalidDecl() && in emitBadConversionNotes()
8526 !fromDecl->hasDefinition() && in emitBadConversionNotes()
8529 S.Diag(fromDecl->getLocation(), diag::note_forward_class_conversion) in emitBadConversionNotes()
8543 InitList->getNumInits()), in diagnoseListInit()
8550 if (DestType->isReferenceType()) { in diagnoseListInit()
8551 // A list-initialization failure for a reference means that we tried to in diagnoseListInit()
8554 QualType T = DestType->castAs<ReferenceType>()->getPointeeType(); in diagnoseListInit()
8556 SourceLocation Loc = InitList->getBeginLoc(); in diagnoseListInit()
8558 Loc = D->getLocation(); in diagnoseListInit()
8579 // When we want to diagnose only one element of a braced-init-list, in Diagnose()
8584 if (List && List->getNumInits() == 1) in Diagnose()
8585 OnlyArg = List->getInit(0); in Diagnose()
8589 if (OnlyArg->getType() == S.Context.OverloadTy) { in Diagnose()
8608 // If this is value-initialization, this could be nested some way within in Diagnose()
8611 DestType->isReferenceType()); in Diagnose()
8618 << SourceRange(Args.front()->getBeginLoc(), Args.back()->getEndLoc()); in Diagnose()
8622 << 1 << Entity.getType() << Args[0]->getSourceRange(); in Diagnose()
8647 S.Diag(Args.front()->getBeginLoc(), in Diagnose()
8649 << FixItHint::CreateInsertion(Args.front()->getBeginLoc(), "u8"); in Diagnose()
8653 << DestType->isSignedIntegerType() << S.getLangOpts().CPlusPlus20; in Diagnose()
8662 << OnlyArg->getType() in Diagnose()
8663 << Args[0]->getSourceRange(); in Diagnose()
8668 << Args[0]->getSourceRange(); in Diagnose()
8681 auto *FD = cast<FunctionDecl>(cast<DeclRefExpr>(OnlyArg)->getDecl()); in Diagnose()
8683 OnlyArg->getBeginLoc()); in Diagnose()
8697 << OnlyArg->getType() << DestType in Diagnose()
8698 << Args[0]->getSourceRange()) in Diagnose()
8700 << DestType << OnlyArg->getType() in Diagnose()
8701 << Args[0]->getSourceRange())), in Diagnose()
8710 OnlyArg->getType(), Args[0]->getSourceRange())) in Diagnose()
8713 << OnlyArg->getType() << Args[0]->getSourceRange() in Diagnose()
8724 StringLiteral *Msg = Best->Function->getDeletedMessage(); in Diagnose()
8726 << OnlyArg->getType() << DestType.getNonReferenceType() in Diagnose()
8727 << (Msg != nullptr) << (Msg ? Msg->getString() : StringRef()) in Diagnose()
8728 << Args[0]->getSourceRange(); in Diagnose()
8730 S.NoteDeletedFunction(Best->Function); in Diagnose()
8748 << Args[0]->getSourceRange(); in Diagnose()
8760 << OnlyArg->getType() in Diagnose()
8761 << Args[0]->getSourceRange(); in Diagnose()
8765 // We don't necessarily have an unambiguous source bit-field. in Diagnose()
8766 FieldDecl *BitField = Args[0]->getSourceBitField(); in Diagnose()
8769 << (BitField ? BitField->getDeclName() : DeclarationName()) in Diagnose()
8771 << Args[0]->getSourceRange(); in Diagnose()
8773 S.Diag(BitField->getLocation(), diag::note_bitfield_decl); in Diagnose()
8780 << Args[0]->getSourceRange(); in Diagnose()
8785 << DestType.isVolatileQualified() << Args[0]->getSourceRange(); in Diagnose()
8790 << DestType.getNonReferenceType() << OnlyArg->getType() in Diagnose()
8791 << Args[0]->getSourceRange(); in Diagnose()
8796 << DestType << Args[0]->getSourceRange(); in Diagnose()
8800 QualType SourceType = OnlyArg->getType(); in Diagnose()
8803 SourceType.getQualifiers() - NonRefType.getQualifiers(); in Diagnose()
8809 << Args[0]->getSourceRange(); in Diagnose()
8814 << DroppedQualifiers.getCVRQualifiers() << Args[0]->getSourceRange(); in Diagnose()
8820 << Args[0]->getSourceRange(); in Diagnose()
8827 << DestType.getNonReferenceType()->isIncompleteType() in Diagnose()
8828 << OnlyArg->isLValue() in Diagnose()
8829 << OnlyArg->getType() in Diagnose()
8830 << Args[0]->getSourceRange(); in Diagnose()
8835 QualType FromType = OnlyArg->getType(); in Diagnose()
8839 << OnlyArg->isLValue() in Diagnose()
8841 << Args[0]->getSourceRange(); in Diagnose()
8849 // No-op. This error has already been reported. in Diagnose()
8856 if (InitList && InitList->getNumInits() >= 1) { in Diagnose()
8857 R = SourceRange(InitList->getInit(0)->getEndLoc(), InitList->getEndLoc()); in Diagnose()
8860 R = SourceRange(Args.front()->getEndLoc(), Args.back()->getEndLoc()); in Diagnose()
8875 << 0 << Entity.getType() << Args[0]->getSourceRange(); in Diagnose()
8880 << DestType.getNonReferenceType() << Args[0]->getSourceRange(); in Diagnose()
8885 << (DestType->isRecordType()) << DestType << Args[0]->getSourceRange(); in Diagnose()
8893 SourceRange(Args.front()->getBeginLoc(), Args.back()->getEndLoc()); in Diagnose()
8899 Args = MultiExprArg(InitList->getInits(), InitList->getNumInits()); in Diagnose()
8920 // base within a constructor. If no viable function was in Diagnose()
8926 if (auto Inherited = Constructor->getInheritedConstructor()) in Diagnose()
8927 InheritedFrom = Inherited.getShadowDecl()->getNominatedBaseClass(); in Diagnose()
8930 << (InheritedFrom ? 2 : Constructor->isImplicit() ? 1 : 0) in Diagnose()
8931 << S.Context.getTypeDeclType(Constructor->getParent()) in Diagnose()
8937 = Entity.getBaseSpecifier()->getType()->castAs<RecordType>() in Diagnose()
8938 ->getDecl(); in Diagnose()
8939 S.Diag(BaseDecl->getLocation(), diag::note_previous_decl) in Diagnose()
8943 << (InheritedFrom ? 2 : Constructor->isImplicit() ? 1 : 0) in Diagnose()
8944 << S.Context.getTypeDeclType(Constructor->getParent()) in Diagnose()
8948 S.Diag(Entity.getDecl()->getLocation(), in Diagnose()
8952 = Entity.getType()->getAs<RecordType>()) in Diagnose()
8953 S.Diag(Record->getDecl()->getLocation(), in Diagnose()
8955 << S.Context.getTagDeclType(Record->getDecl()); in Diagnose()
8979 // If this is a defaulted or implicitly-declared function, then in Diagnose()
8982 if (S.isImplicitlyDeleted(Best->Function)) in Diagnose()
8985 S.getSpecialMember(cast<CXXMethodDecl>(Best->Function))) in Diagnose()
8988 StringLiteral *Msg = Best->Function->getDeletedMessage(); in Diagnose()
8991 << (Msg ? Msg->getString() : StringRef()) << ArgsRange; in Diagnose()
8994 S.NoteDeletedFunction(Best->Function); in Diagnose()
9007 // This is implicit default-initialization of a const member in in Diagnose()
9012 << (Constructor->getInheritedConstructor() ? 2 : in Diagnose()
9013 Constructor->isImplicit() ? 1 : 0) in Diagnose()
9014 << S.Context.getTypeDeclType(Constructor->getParent()) in Diagnose()
9017 S.Diag(Entity.getDecl()->getLocation(), diag::note_previous_decl) in Diagnose()
9020 VD && VD->isConstexpr()) { in Diagnose()
9025 << DestType << (bool)DestType->getAs<RecordType>(); in Diagnose()
9048 << Args[0]->getSourceRange(); in Diagnose()
9054 CXXConstructorDecl *CtorDecl = cast<CXXConstructorDecl>(Best->Function); in Diagnose()
9055 S.Diag(CtorDecl->getLocation(), in Diagnose()
9068 << Entity.getType() << InitList->getSourceRange(); in Diagnose()
9076 void InitializationSequence::dump(raw_ostream &OS) const { in dump() function in InitializationSequence
9130 OS << "non-constant array initializer"; in dump()
9142 OS << "non-const lvalue reference bound to temporary"; in dump()
9146 OS << "non-const lvalue reference bound to bit-field"; in dump()
9150 OS << "non-const lvalue reference bound to vector element"; in dump()
9154 OS << "non-const lvalue reference bound to matrix element"; in dump()
9158 OS << "non-const lvalue reference bound to unrelated type"; in dump()
9198 OS << "initializer list for non-aggregate, non-scalar type"; in dump()
9202 OS << "overloading failed for user-defined conversion"; in dump()
9242 OS << "designated initializer for non-aggregate type"; in dump()
9260 OS << " -> "; in dump()
9263 switch (S->Kind) { in dump()
9269 OS << "derived-to-base (prvalue)"; in dump()
9273 OS << "derived-to-base (xvalue)"; in dump()
9277 OS << "derived-to-base (lvalue)"; in dump()
9289 OS << "final copy in class direct-initialization"; in dump()
9297 OS << "user-defined conversion via " << *S->Function.Function; in dump()
9317 OS << "non-atomic-to-atomic conversion"; in dump()
9322 S->ICS->dump(); // FIXME: use OS in dump()
9328 S->ICS->dump(); // FIXME: use OS in dump()
9365 OS << "Objective-C object conversion"; in dump()
9397 OS << "Objective-C object retension"; in dump()
9420 OS << " [" << S->Type << ']'; in dump()
9426 void InitializationSequence::dump() const { in dump() function in InitializationSequence
9427 dump(llvm::errs()); in dump()
9459 return S.Diag(PostInit->getBeginLoc(), DiagID) in DiagnoseNarrowingInInitList()
9460 << PostInit->getSourceRange(); in DiagnoseNarrowingInInitList()
9466 switch (SCS->getNarrowingKind(S.Context, PostInit, ConstantValue, in DiagnoseNarrowingInInitList()
9470 // No narrowing occurred. in DiagnoseNarrowingInInitList()
9474 // This was a floating-to-integer conversion, which is always considered a in DiagnoseNarrowingInInitList()
9512 if (const TypedefType *TT = EntityType->getAs<TypedefType>()) { in DiagnoseNarrowingInInitList()
9517 // getQualifiedNameAsString() includes non-machine-parsable components. in DiagnoseNarrowingInInitList()
9518 OS << *TT->getDecl(); in DiagnoseNarrowingInInitList()
9519 } else if (const BuiltinType *BT = EntityType->getAs<BuiltinType>()) in DiagnoseNarrowingInInitList()
9520 OS << BT->getName(S.getLangOpts()); in DiagnoseNarrowingInInitList()
9522 // Oops, we didn't find the actual type of the variable. Don't emit a fixit in DiagnoseNarrowingInInitList()
9527 S.Diag(PostInit->getBeginLoc(), diag::note_init_list_narrowing_silence) in DiagnoseNarrowingInInitList()
9528 << PostInit->getSourceRange() in DiagnoseNarrowingInInitList()
9529 << FixItHint::CreateInsertion(PostInit->getBeginLoc(), OS.str()) in DiagnoseNarrowingInInitList()
9531 S.getLocForEndOfToken(PostInit->getEndLoc()), ")"); in DiagnoseNarrowingInInitList()
9538 Init->IgnoreParenImpCasts(), ToType, /*SuppressUserConversions*/ false, in CheckC23ConstexprInitConversion()
9555 S.Diag(Init->getBeginLoc(), diag::err_c23_constexpr_init_not_representable) in CheckC23ConstexprInitConversion()
9561 S.Diag(Init->getBeginLoc(), diag::err_c23_constexpr_init_type_mismatch) in CheckC23ConstexprInitConversion()
9578 // character that string literal contains fits into TT - target type. in CheckC23ConstexprInitStringLiteral()
9580 QualType CharType = AT->getElementType(); in CheckC23ConstexprInitStringLiteral()
9582 bool isUnsigned = CharType->isUnsignedIntegerType(); in CheckC23ConstexprInitStringLiteral()
9584 for (unsigned I = 0, N = SE->getLength(); I != N; ++I) { in CheckC23ConstexprInitStringLiteral()
9585 int64_t C = SE->getCodeUnitS(I, SemaRef.Context.getCharWidth()); in CheckC23ConstexprInitStringLiteral()
9597 //===----------------------------------------------------------------------===//
9599 //===----------------------------------------------------------------------===//
9607 assert(InitE && "No initialization expression"); in CanPerformCopyInitialization()
9610 InitializationKind::CreateCopy(InitE->getBeginLoc(), SourceLocation()); in CanPerformCopyInitialization()
9625 assert(InitE && "No initialization expression?"); in PerformCopyInitialization()
9628 EqualLoc = InitE->getBeginLoc(); in PerformCopyInitialization()
9631 InitE->getBeginLoc(), EqualLoc, AllowExplicit); in PerformCopyInitialization()
9634 // Prevent infinite recursion when performing parameter copy-initialization. in PerformCopyInitialization()
9645 const auto LastStep = Seq.step_end() - 1; in PerformCopyInitialization()
9646 assert(LastStep->Kind == in PerformCopyInitialization()
9648 const FunctionDecl *Function = LastStep->Function.Function; in PerformCopyInitialization()
9651 [Function](const OverloadCandidate &Candidate) -> bool { in PerformCopyInitialization()
9657 Function->getNumParams() > 0) { in PerformCopyInitialization()
9658 Candidate->Viable = false; in PerformCopyInitialization()
9659 Candidate->FailureKind = ovl_fail_bad_conversion; in PerformCopyInitialization()
9660 Candidate->Conversions[0].setBad(BadConversionSequence::no_conversion, in PerformCopyInitialization()
9662 Function->getParamDecl(0)->getType()); in PerformCopyInitialization()
9681 return !CTSD || !declaresSameEntity(CTSD->getSpecializedTemplate(), CTD); in isOrIsDerivedFromSpecializationOf()
9683 return !(NotSpecialization(RD) && RD->forallBases(NotSpecialization)); in isOrIsDerivedFromSpecializationOf()
9690 TSInfo->getType()->getContainedDeducedType()); in DeduceTemplateSpecializationFromInitializer()
9693 auto TemplateName = DeducedTST->getTemplateName(); in DeduceTemplateSpecializationFromInitializer()
9695 return SubstAutoTypeDependent(TSInfo->getType()); in DeduceTemplateSpecializationFromInitializer()
9707 auto UnderlyingType = AliasTemplate->getTemplatedDecl() in DeduceTemplateSpecializationFromInitializer()
9708 ->getUnderlyingType() in DeduceTemplateSpecializationFromInitializer()
9710 // C++ [over.match.class.deduct#3]: ..., the defining-type-id of A must be in DeduceTemplateSpecializationFromInitializer()
9712 // [typename] [nested-name-specifier] [template] simple-template-id in DeduceTemplateSpecializationFromInitializer()
9714 UnderlyingType->getAs<TemplateSpecializationType>()) { in DeduceTemplateSpecializationFromInitializer()
9716 TST->getTemplateName().getAsTemplateDecl()); in DeduceTemplateSpecializationFromInitializer()
9717 } else if (const auto *RT = UnderlyingType->getAs<RecordType>()) { in DeduceTemplateSpecializationFromInitializer()
9722 RT->getAsCXXRecordDecl())) in DeduceTemplateSpecializationFromInitializer()
9723 Template = CTSD->getSpecializedTemplate(); in DeduceTemplateSpecializationFromInitializer()
9738 Diag(TSInfo->getTypeLoc().getBeginLoc(), in DeduceTemplateSpecializationFromInitializer()
9740 << TSInfo->getTypeLoc().getSourceRange() << 0; in DeduceTemplateSpecializationFromInitializer()
9741 return SubstAutoTypeDependent(TSInfo->getType()); in DeduceTemplateSpecializationFromInitializer()
9745 // Or implement this via an implied 'T(T) -> T' deduction guide? in DeduceTemplateSpecializationFromInitializer()
9751 // - For each constructor of the class template designated by the in DeduceTemplateSpecializationFromInitializer()
9752 // template-name, a function template [...] in DeduceTemplateSpecializationFromInitializer()
9753 // - For each deduction-guide, a function or function template [...] in DeduceTemplateSpecializationFromInitializer()
9756 TSInfo->getTypeLoc().getEndLoc()); in DeduceTemplateSpecializationFromInitializer()
9758 LookupQualifiedName(Guides, LookupTemplateDecl->getDeclContext()); in DeduceTemplateSpecializationFromInitializer()
9764 // Figure out if this is list-initialization. in DeduceTemplateSpecializationFromInitializer()
9791 // C++ [over.match.ctor]p1: (non-list copy-initialization from non-class) in DeduceTemplateSpecializationFromInitializer()
9792 // For copy-initialization, the candidate functions are all the in DeduceTemplateSpecializationFromInitializer()
9794 // C++ [over.match.copy]p1: (non-list copy-initialization from class) in DeduceTemplateSpecializationFromInitializer()
9803 if (GD->getMinRequiredArguments() > 1 || in DeduceTemplateSpecializationFromInitializer()
9804 (GD->getNumParams() == 0 && !GD->isVariadic())) in DeduceTemplateSpecializationFromInitializer()
9809 // Initially, the candidate functions are the initializer-list in DeduceTemplateSpecializationFromInitializer()
9815 GD->getDeductionCandidateKind() == DeductionCandidate::Aggregate) in DeduceTemplateSpecializationFromInitializer()
9826 // - [over.match.copy] (in all cases) in DeduceTemplateSpecializationFromInitializer()
9831 TmpInits.push_back(DI->getInit()); in DeduceTemplateSpecializationFromInitializer()
9849 [&](bool OnlyListConstructors) -> OverloadingResult { in DeduceTemplateSpecializationFromInitializer()
9855 while (Pattern->getInstantiatedFromMemberTemplate()) { in DeduceTemplateSpecializationFromInitializer()
9856 if (Pattern->isMemberSpecialization()) in DeduceTemplateSpecializationFromInitializer()
9858 Pattern = Pattern->getInstantiatedFromMemberTemplate(); in DeduceTemplateSpecializationFromInitializer()
9861 auto *RD = cast<CXXRecordDecl>(Pattern->getTemplatedDecl()); in DeduceTemplateSpecializationFromInitializer()
9862 if (!(RD->getDefinition() && RD->isAggregate())) in DeduceTemplateSpecializationFromInitializer()
9870 // if e_i is of array type and x_i is a braced-init-list, T_i is an in DeduceTemplateSpecializationFromInitializer()
9873 // if e_i is of array type and x_i is a string-literal, T_i is an in DeduceTemplateSpecializationFromInitializer()
9874 // lvalue reference to the const-qualified declared type of e_i and in DeduceTemplateSpecializationFromInitializer()
9877 for (int I = 0, E = ListInit->getNumInits(); in DeduceTemplateSpecializationFromInitializer()
9879 if (ElementTypes[I]->isArrayType()) { in DeduceTemplateSpecializationFromInitializer()
9880 if (isa<InitListExpr, DesignatedInitExpr>(ListInit->getInit(I))) in DeduceTemplateSpecializationFromInitializer()
9883 ListInit->getInit(I)->IgnoreParenImpCasts())) in DeduceTemplateSpecializationFromInitializer()
9891 TSInfo->getTypeLoc().getEndLoc())) { in DeduceTemplateSpecializationFromInitializer()
9892 auto *GD = cast<CXXDeductionGuideDecl>(TD->getTemplatedDecl()); in DeduceTemplateSpecializationFromInitializer()
9902 NamedDecl *D = (*I)->getUnderlyingDecl(); in DeduceTemplateSpecializationFromInitializer()
9903 if (D->isInvalidDecl()) in DeduceTemplateSpecializationFromInitializer()
9908 TD ? TD->getTemplatedDecl() : dyn_cast<FunctionDecl>(D)); in DeduceTemplateSpecializationFromInitializer()
9912 if (!GD->isImplicit()) in DeduceTemplateSpecializationFromInitializer()
9922 // dependent base class has no virtual functions and no virtual base in DeduceTemplateSpecializationFromInitializer()
9923 // classes, and the initializer is a non-empty braced-init-list or in DeduceTemplateSpecializationFromInitializer()
9924 // parenthesized expression-list, and there are no deduction-guides for in DeduceTemplateSpecializationFromInitializer()
9928 if (ListInit && ListInit->getNumInits()) { in DeduceTemplateSpecializationFromInitializer()
9930 } else if (Inits.size()) { // parenthesized expression-list in DeduceTemplateSpecializationFromInitializer()
9934 InitListExpr TempListInit(getASTContext(), Inits.front()->getBeginLoc(), in DeduceTemplateSpecializationFromInitializer()
9935 Inits, Inits.back()->getEndLoc()); in DeduceTemplateSpecializationFromInitializer()
9947 // C++11 [over.match.list]p1, per DR1467: for list-initialization, first in DeduceTemplateSpecializationFromInitializer()
9948 // try initializer-list constructors. in DeduceTemplateSpecializationFromInitializer()
9954 if (!ListInit->getNumInits()) { in DeduceTemplateSpecializationFromInitializer()
9956 auto *FD = dyn_cast<FunctionDecl>(D->getUnderlyingDecl()); in DeduceTemplateSpecializationFromInitializer()
9957 if (FD && FD->getMinRequiredArguments() == 0) { in DeduceTemplateSpecializationFromInitializer()
9962 } else if (ListInit->getNumInits() == 1) { in DeduceTemplateSpecializationFromInitializer()
9965 // initializer-list constructors) is omitted if the initializer list in DeduceTemplateSpecializationFromInitializer()
9968 Expr *E = ListInit->getInit(0); in DeduceTemplateSpecializationFromInitializer()
9969 auto *RD = E->getType()->getAsCXXRecordDecl(); in DeduceTemplateSpecializationFromInitializer()
9971 isCompleteType(Kind.getLocation(), E->getType()) && in DeduceTemplateSpecializationFromInitializer()
9980 Inits = MultiExprArg(ListInit->getInits(), ListInit->getNumInits()); in DeduceTemplateSpecializationFromInitializer()
9983 // If list-initialization fails, or if we're doing any other kind of in DeduceTemplateSpecializationFromInitializer()
9990 // FIXME: For list-initialization candidates, it'd usually be better to in DeduceTemplateSpecializationFromInitializer()
10003 cast<ClassTemplateDecl>(Template)->getTemplatedDecl(); in DeduceTemplateSpecializationFromInitializer()
10017 // FIXME: There are no tests for this diagnostic, and it doesn't seem in DeduceTemplateSpecializationFromInitializer()
10022 NoteDeletedFunction(Best->Function); in DeduceTemplateSpecializationFromInitializer()
10028 // In copy-list-initialization, if an explicit constructor is chosen, the in DeduceTemplateSpecializationFromInitializer()
10029 // initialization is ill-formed. in DeduceTemplateSpecializationFromInitializer()
10031 cast<CXXDeductionGuideDecl>(Best->Function)->isExplicit()) { in DeduceTemplateSpecializationFromInitializer()
10032 bool IsDeductionGuide = !Best->Function->isImplicit(); in DeduceTemplateSpecializationFromInitializer()
10035 Diag(Best->Function->getLocation(), in DeduceTemplateSpecializationFromInitializer()
10043 DiagnoseUseOfDecl(Best->FoundDecl, Kind.getLocation()); in DeduceTemplateSpecializationFromInitializer()
10044 MarkFunctionReferenced(Kind.getLocation(), Best->Function); in DeduceTemplateSpecializationFromInitializer()
10052 SubstAutoType(TSInfo->getType(), Best->Function->getReturnType()); in DeduceTemplateSpecializationFromInitializer()
10053 Diag(TSInfo->getTypeLoc().getBeginLoc(), in DeduceTemplateSpecializationFromInitializer()
10055 << TSInfo->getTypeLoc().getSourceRange() << 1 << DeducedType; in DeduceTemplateSpecializationFromInitializer()
10057 // Warn if CTAD was used on a type that does not have any user-defined in DeduceTemplateSpecializationFromInitializer()
10060 Diag(TSInfo->getTypeLoc().getBeginLoc(), in DeduceTemplateSpecializationFromInitializer()
10063 Diag(Template->getLocation(), diag::note_suppress_ctad_maybe_unsupported); in DeduceTemplateSpecializationFromInitializer()