41 #include "llvm/ADT/APInt.h"
42 #include "llvm/ADT/STLExtras.h"
43 #include "llvm/Support/ErrorHandling.h"
44 #include "llvm/Support/TypeSize.h"
45 using namespace clang;
77 llvm_unreachable(
"Nested name specifier is not a type for inheriting ctor");
82 return CreateParsedType(
Type,
89 bool EnteringContext) {
92 "not a constructor name");
102 if (SS.
isNotEmpty() && RequireCompleteDeclContext(SS, CurClass))
113 auto *RD = dyn_cast<CXXRecordDecl>(ND);
114 if (RD && RD->isInjectedClassName()) {
115 InjectedClassName = RD;
119 if (!InjectedClassName) {
124 diag::err_incomplete_nested_name_spec) << CurClass << SS.
getRange();
130 DiagnoseUseOfDecl(InjectedClassName, NameLoc);
131 MarkAnyDeclReferenced(NameLoc, InjectedClassName,
false);
141 bool EnteringContext) {
184 ObjectTypePtr ? GetTypeFromParser(ObjectTypePtr) :
QualType();
187 auto IsAcceptableResult = [&](
NamedDecl *D) ->
bool {
188 auto *
Type = dyn_cast<TypeDecl>(D->getUnderlyingDecl());
199 unsigned NumAcceptableResults = 0;
201 if (IsAcceptableResult(D))
202 ++NumAcceptableResults;
207 if (
auto *RD = dyn_cast<CXXRecordDecl>(D))
208 if (RD->isInjectedClassName())
209 D = cast<NamedDecl>(RD->getParent());
211 if (FoundDeclSet.insert(D).second)
212 FoundDecls.push_back(D);
220 if (Found.isAmbiguous() && NumAcceptableResults == 1) {
221 Diag(NameLoc, diag::ext_dtor_name_ambiguous);
231 if (!IsAcceptableResult(D))
237 if (Found.isAmbiguous())
241 if (IsAcceptableResult(
Type)) {
243 MarkAnyDeclReferenced(
Type->getLocation(),
Type,
false);
244 return CreateParsedType(T,
252 bool IsDependent =
false;
254 auto LookupInObjectType = [&]() ->
ParsedType {
255 if (Failed || SearchType.
isNull())
260 LookupResult Found(*
this, &II, NameLoc, LookupDestructorName);
261 DeclContext *LookupCtx = computeDeclContext(SearchType);
264 LookupQualifiedName(Found, LookupCtx);
265 return CheckLookupResult(Found);
272 IsDependent |= isDependentScopeSpecifier(LookupSS);
273 DeclContext *LookupCtx = computeDeclContext(LookupSS, EnteringContext);
277 LookupResult Found(*
this, &II, NameLoc, LookupDestructorName);
278 if (RequireCompleteDeclContext(LookupSS, LookupCtx)) {
282 LookupQualifiedName(Found, LookupCtx);
283 return CheckLookupResult(Found);
290 LookupResult Found(*
this, &II, NameLoc, LookupDestructorName);
291 LookupName(Found, S);
292 return CheckLookupResult(Found);
339 if (
ParsedType T = LookupInNestedNameSpec(PrefixSS))
369 unsigned NumNonExtensionDecls = FoundDecls.size();
377 if (
ParsedType T = LookupInNestedNameSpec(SS)) {
393 Diag(SS.
getEndLoc(), diag::ext_qualified_dtor_named_in_lexical_scope)
395 Diag(FoundDecls.back()->getLocation(), diag::note_destructor_type_here)
396 << GetTypeFromParser(T);
406 FoundDecls.resize(NumNonExtensionDecls);
409 std::stable_sort(FoundDecls.begin(), FoundDecls.end(),
411 return isa<TypeDecl>(A->getUnderlyingDecl()) >
412 isa<TypeDecl>(B->getUnderlyingDecl());
416 auto MakeFixItHint = [&]{
422 Destroyed = dyn_cast_or_null<CXXRecordDecl>(S->getEntity());
429 if (FoundDecls.empty()) {
431 Diag(NameLoc, diag::err_undeclared_destructor_name)
432 << &II << MakeFixItHint();
433 }
else if (!SearchType.
isNull() && FoundDecls.size() == 1) {
434 if (
auto *TD = dyn_cast<TypeDecl>(FoundDecls[0]->getUnderlyingDecl())) {
435 assert(!SearchType.
isNull() &&
436 "should only reject a type result if we have a search type");
438 Diag(NameLoc, diag::err_destructor_expr_type_mismatch)
439 << T << SearchType << MakeFixItHint();
441 Diag(NameLoc, diag::err_destructor_expr_nontype)
442 << &II << MakeFixItHint();
445 Diag(NameLoc, SearchType.
isNull() ? diag::err_destructor_name_nontype
446 : diag::err_destructor_expr_mismatch)
447 << &II << SearchType << MakeFixItHint();
451 if (
auto *TD = dyn_cast<TypeDecl>(FoundD->getUnderlyingDecl()))
452 Diag(FoundD->getLocation(), diag::note_destructor_type_here)
455 Diag(FoundD->getLocation(), diag::note_destructor_nontype_here)
473 "unexpected type in getDestructorType");
478 QualType SearchType = GetTypeFromParser(ObjectType);
501 !PP.getSourceManager().isInSystemHeader(Loc)) {
502 Diag(Loc, diag::warn_reserved_extern_symbol)
503 << II << static_cast<int>(Status)
505 Name.getSourceRange(),
506 (StringRef(
"operator\"\"") + II->
getName()).str());
521 Diag(Name.getBeginLoc(), diag::err_literal_operator_id_outside_namespace)
532 llvm_unreachable(
"unknown nested name specifier kind");
550 RequireCompleteType(TypeidLoc, T, diag::err_incomplete_typeid))
554 return ExprError(
Diag(TypeidLoc, diag::err_variably_modified_typeid) << T);
556 if (CheckQualifiedFunctionForTypeId(T, TypeidLoc))
568 bool WasEvaluated =
false;
578 CXXRecordDecl *RecordD = cast<CXXRecordDecl>(RecordT->getDecl());
582 if (RequireCompleteType(TypeidLoc, T, diag::err_incomplete_typeid))
590 if (isUnevaluatedContext()) {
593 ExprResult Result = TransformToPotentiallyEvaluated(E);
594 if (Result.isInvalid())
600 MarkVTableUsed(TypeidLoc, RecordD);
605 ExprResult Result = CheckUnevaluatedOperand(E);
606 if (Result.isInvalid())
619 E = ImpCastExprToType(E, UnqualT, CK_NoOp, E->
getValueKind()).get();
624 return ExprError(
Diag(TypeidLoc, diag::err_variably_modified_typeid)
626 else if (!inTemplateInstantiation() &&
631 ? diag::warn_side_effects_typeid
632 : diag::warn_side_effects_unevaluated_context);
644 if (getLangOpts().OpenCLCPlusPlus) {
645 return ExprError(
Diag(OpLoc, diag::err_openclcxx_not_supported)
650 if (!getStdNamespace())
651 return ExprError(
Diag(OpLoc, diag::err_need_header_before_typeid));
653 if (!CXXTypeInfoDecl) {
654 IdentifierInfo *TypeInfoII = &PP.getIdentifierTable().get(
"type_info");
656 LookupQualifiedName(R, getStdNamespace());
660 if (!CXXTypeInfoDecl && LangOpts.MSVCCompat) {
664 if (!CXXTypeInfoDecl)
665 return ExprError(
Diag(OpLoc, diag::err_need_header_before_typeid));
668 if (!getLangOpts().RTTI) {
669 return ExprError(
Diag(OpLoc, diag::err_no_typeid_with_fno_rtti));
685 return BuildCXXTypeId(TypeInfoType, OpLoc, TInfo, RParenLoc);
690 BuildCXXTypeId(TypeInfoType, OpLoc, (
Expr *)TyOrExpr, RParenLoc);
692 if (!getLangOpts().RTTIData && !Result.isInvalid())
693 if (
auto *CTE = dyn_cast<CXXTypeidExpr>(Result.get()))
694 if (CTE->isPotentiallyEvaluated() && !CTE->isMostDerived(Context))
695 Diag(OpLoc, diag::warn_no_typeid_with_rtti_disabled)
696 << (getDiagnostics().getDiagnosticOptions().getFormat() ==
717 if (
const auto *Uuid = TD->getMostRecentDecl()->getAttr<UuidAttr>()) {
718 UuidAttrs.insert(Uuid);
723 if (
const auto *CTSD = dyn_cast<ClassTemplateSpecializationDecl>(TD)) {
726 const UuidAttr *UuidForTA =
nullptr;
733 UuidAttrs.insert(UuidForTA);
744 if (!Operand->getType()->isDependentType()) {
747 if (UuidAttrs.empty())
748 return ExprError(
Diag(TypeidLoc, diag::err_uuidof_without_guid));
749 if (UuidAttrs.size() > 1)
750 return ExprError(
Diag(TypeidLoc, diag::err_uuidof_with_multiple_guids));
751 Guid = UuidAttrs.back()->getGuidDecl();
769 if (UuidAttrs.empty())
770 return ExprError(
Diag(TypeidLoc, diag::err_uuidof_without_guid));
771 if (UuidAttrs.size() > 1)
772 return ExprError(
Diag(TypeidLoc, diag::err_uuidof_with_multiple_guids));
773 Guid = UuidAttrs.back()->getGuidDecl();
799 return BuildCXXUuidof(GuidType, OpLoc, TInfo, RParenLoc);
803 return BuildCXXUuidof(GuidType, OpLoc, (
Expr*)TyOrExpr, RParenLoc);
809 assert((
Kind == tok::kw_true ||
Kind == tok::kw_false) &&
810 "Unknown C++ Boolean value!");
824 bool IsThrownVarInScope =
false;
838 if (
VarDecl *Var = dyn_cast<VarDecl>(DRE->getDecl())) {
839 if (Var->hasLocalStorage() && !Var->getType().isVolatileQualified()) {
840 for( ; S; S = S->getParent()) {
841 if (S->isDeclScope(Var)) {
842 IsThrownVarInScope =
true;
856 return BuildCXXThrow(OpLoc, Ex, IsThrownVarInScope);
860 bool IsThrownVarInScope) {
862 if (!getLangOpts().CXXExceptions &&
863 !getSourceManager().isInSystemHeader(OpLoc) && !getLangOpts().
CUDA) {
865 targetDiag(OpLoc, diag::err_exceptions_disabled) <<
"throw";
869 if (getLangOpts().
CUDA)
870 CUDADiagIfDeviceCode(OpLoc, diag::err_cuda_device_exceptions)
871 <<
"throw" << CurrentCUDATarget();
873 if (getCurScope() && getCurScope()->isOpenMPSimdDirectiveScope())
874 Diag(OpLoc, diag::err_omp_simd_region_cannot_use_stmt) <<
"throw";
896 if (CheckCXXThrowOperand(OpLoc, ExceptionObjectTy, Ex))
901 ExprResult Res = PerformMoveOrCopyInitialization(Entity, NRInfo, Ex);
917 llvm::DenseMap<CXXRecordDecl *, unsigned> &SubobjectsSeen,
918 llvm::SmallPtrSetImpl<CXXRecordDecl *> &VBases,
919 llvm::SetVector<CXXRecordDecl *> &PublicSubobjectsSeen,
920 bool ParentIsPublic) {
922 CXXRecordDecl *BaseDecl = BS.getType()->getAsCXXRecordDecl();
927 NewSubobject = VBases.insert(BaseDecl).second;
932 ++SubobjectsSeen[BaseDecl];
935 bool PublicPath = ParentIsPublic && BS.getAccessSpecifier() ==
AS_public;
937 PublicSubobjectsSeen.insert(BaseDecl);
947 llvm::DenseMap<CXXRecordDecl *, unsigned> SubobjectsSeen;
948 llvm::SmallSet<CXXRecordDecl *, 2> VBases;
949 llvm::SetVector<CXXRecordDecl *> PublicSubobjectsSeen;
950 SubobjectsSeen[RD] = 1;
951 PublicSubobjectsSeen.insert(RD);
955 for (
CXXRecordDecl *PublicSubobject : PublicSubobjectsSeen) {
957 if (SubobjectsSeen[PublicSubobject] > 1)
960 Objects.push_back(PublicSubobject);
970 bool isPointer =
false;
976 if (RequireCompleteType(ThrowLoc, Ty,
977 isPointer ? diag::err_throw_incomplete_ptr
978 : diag::err_throw_incomplete,
987 if (RequireNonAbstractType(ThrowLoc, ExceptionObjectTy,
988 diag::err_throw_abstract_type, E))
999 MarkVTableUsed(ThrowLoc, RD);
1008 MarkFunctionReferenced(E->
getExprLoc(), Destructor);
1009 CheckDestructorAccess(E->
getExprLoc(), Destructor,
1010 PDiag(diag::err_access_dtor_exception) << Ty);
1011 if (DiagnoseUseOfDecl(Destructor, E->
getExprLoc()))
1026 for (
CXXRecordDecl *Subobject : UnambiguousPublicSubobjects) {
1053 for (
unsigned I = 1, E = CD->
getNumParams(); I != E; ++I) {
1054 if (CheckCXXDefaultArgExpr(ThrowLoc, CD, CD->
getParamDecl(I)))
1067 if (ExnObjAlign < TypeAlign) {
1068 Diag(ThrowLoc, diag::warn_throw_underaligned_obj);
1069 Diag(ThrowLoc, diag::note_throw_underaligned_obj)
1122 for (
int I = FunctionScopes.size();
1123 I-- && isa<LambdaScopeInfo>(FunctionScopes[I]) &&
1125 cast<LambdaScopeInfo>(FunctionScopes[I])->CallOperator);
1127 CurLSI = cast<LambdaScopeInfo>(FunctionScopes[I]);
1134 if (C.isCopyCapture()) {
1147 "While computing 'this' capture-type for a generic lambda, when we "
1148 "run out of enclosing LSI's, yet the enclosing DC is a "
1149 "lambda-call-operator we must be (i.e. Current LSI) in a generic "
1150 "lambda call oeprator");
1153 auto IsThisCaptured =
1157 for (
auto &&C : Closure->
captures()) {
1158 if (C.capturesThis()) {
1169 bool IsByCopyCapture =
false;
1170 bool IsConstCapture =
false;
1173 IsThisCaptured(Closure, IsByCopyCapture, IsConstCapture)) {
1174 if (IsByCopyCapture) {
1190 QualType ThisTy = CXXThisTypeOverride;
1193 if (method && method->isInstance())
1194 ThisTy = method->getThisType();
1198 inTemplateInstantiation() && isa<CXXRecordDecl>(DC)) {
1214 CurContext, Context);
1222 : S(S), OldCXXThisTypeOverride(S.CXXThisTypeOverride), Enabled(
false)
1224 if (!Enabled || !ContextDecl)
1229 Record = Template->getTemplatedDecl();
1231 Record = cast<CXXRecordDecl>(ContextDecl);
1238 this->Enabled =
true;
1255 Sema.
Diag(DiagLoc, diag::note_lambda_this_capture_fixit)
1261 bool BuildAndDiagnose,
const unsigned *
const FunctionScopeIndexToStopAt,
1262 const bool ByCopy) {
1267 assert((!ByCopy || Explicit) &&
"cannot implicitly capture *this by value");
1269 const int MaxFunctionScopesIndex = FunctionScopeIndexToStopAt
1270 ? *FunctionScopeIndexToStopAt
1296 unsigned NumCapturingClosures = 0;
1297 for (
int idx = MaxFunctionScopesIndex; idx >= 0; idx--) {
1300 if (CSI->CXXThisCaptureIndex != 0) {
1302 CSI->Captures[CSI->CXXThisCaptureIndex - 1].markUsed(BuildAndDiagnose);
1308 if (BuildAndDiagnose) {
1309 Diag(Loc, diag::err_this_capture)
1310 << (Explicit && idx == MaxFunctionScopesIndex);
1320 (Explicit && idx == MaxFunctionScopesIndex)) {
1326 NumCapturingClosures++;
1330 if (BuildAndDiagnose)
1331 Diag(Loc, diag::err_this_capture)
1332 << (Explicit && idx == MaxFunctionScopesIndex);
1340 if (!BuildAndDiagnose)
return false;
1353 "Only a lambda can capture the enclosing object (referred to by "
1356 for (
int idx = MaxFunctionScopesIndex; NumCapturingClosures;
1357 --idx, --NumCapturingClosures) {
1372 bool isNested = NumCapturingClosures > 1;
1385 return Diag(Loc, diag::err_invalid_this_use);
1409 return Class && Class->isBeingDefined();
1421 bool ListInitialization) {
1431 RParenOrBraceLoc, ListInitialization);
1435 if (!Result.isInvalid() && Result.get()->isInstantiationDependent() &&
1436 !Result.get()->isTypeDependent())
1438 else if (Result.isInvalid())
1440 RParenOrBraceLoc, exprs, Ty);
1449 bool ListInitialization) {
1453 assert((!ListInitialization ||
1454 (Exprs.size() == 1 && isa<InitListExpr>(Exprs[0]))) &&
1455 "List initialization must have initializer list as expression.");
1462 ? ListInitialization
1464 TyBeginLoc, LParenOrBraceLoc, RParenOrBraceLoc)
1477 if (Deduced && isa<DeducedTemplateSpecializationType>(Deduced)) {
1483 }
else if (Deduced) {
1485 if (ListInitialization) {
1486 auto *ILE = cast<InitListExpr>(Exprs[0]);
1487 Inits =
MultiExprArg(ILE->getInits(), ILE->getNumInits());
1491 return ExprError(
Diag(TyBeginLoc, diag::err_auto_expr_init_no_expression)
1492 << Ty << FullRange);
1493 if (Inits.size() > 1) {
1494 Expr *FirstBad = Inits[1];
1496 diag::err_auto_expr_init_multiple_expressions)
1497 << Ty << FullRange);
1501 Diag(TyBeginLoc, diag::warn_cxx20_compat_auto_expr) << FullRange;
1503 Expr *Deduce = Inits[0];
1504 if (isa<InitListExpr>(Deduce))
1507 << ListInitialization << Ty << FullRange);
1510 return ExprError(
Diag(TyBeginLoc, diag::err_auto_expr_deduction_failure)
1511 << Ty << Deduce->
getType() << FullRange
1525 :
SourceRange(LParenOrBraceLoc, RParenOrBraceLoc);
1535 if (Exprs.size() == 1 && !ListInitialization &&
1536 !isa<InitListExpr>(Exprs[0])) {
1537 Expr *Arg = Exprs[0];
1545 if (!ListInitialization)
1546 return ExprError(
Diag(TyBeginLoc, diag::err_value_init_for_array_type)
1556 return ExprError(
Diag(TyBeginLoc, diag::err_init_for_function_type)
1557 << Ty << FullRange);
1564 diag::err_invalid_incomplete_type_use, FullRange))
1572 if (Result.isInvalid())
1575 Expr *Inner = Result.get();
1577 Inner = BTE->getSubExpr();
1578 if (!isa<CXXTemporaryObjectExpr>(Inner) &&
1579 !isa<CXXScalarValueInitExpr>(Inner)) {
1588 QualType ResultType = Result.get()->getType();
1591 :
SourceRange(LParenOrBraceLoc, RParenOrBraceLoc);
1613 for (
const auto *D : R) {
1614 if (
const auto *FD = dyn_cast<FunctionDecl>(D)) {
1631 return llvm::none_of(PreventedBy, [&](
const FunctionDecl *FD) {
1633 "Only single-operand functions should be in PreventedBy");
1648 unsigned UsualParams = 1;
1650 if (S.
getLangOpts().SizedDeallocation && UsualParams < FD->getNumParams() &&
1656 if (S.
getLangOpts().AlignedAllocation && UsualParams < FD->getNumParams() &&
1666 struct UsualDeallocFnInfo {
1667 UsualDeallocFnInfo() : Found(), FD(nullptr) {}
1669 : Found(Found), FD(dyn_cast<
FunctionDecl>(Found->getUnderlyingDecl())),
1675 unsigned NumBaseParams = 1;
1676 if (FD->isDestroyingOperatorDelete()) {
1681 if (NumBaseParams < FD->getNumParams() &&
1683 FD->getParamDecl(NumBaseParams)->getType(),
1689 if (NumBaseParams < FD->getNumParams() &&
1690 FD->getParamDecl(NumBaseParams)->getType()->isAlignValT()) {
1692 HasAlignValT =
true;
1701 explicit operator bool()
const {
return FD; }
1703 bool isBetterThan(
const UsualDeallocFnInfo &Other,
bool WantSize,
1704 bool WantAlign)
const {
1708 if (Destroying != Other.Destroying)
1715 if (HasAlignValT != Other.HasAlignValT)
1716 return HasAlignValT == WantAlign;
1718 if (HasSizeT != Other.HasSizeT)
1719 return HasSizeT == WantSize;
1722 return CUDAPref > Other.CUDAPref;
1727 bool Destroying, HasSizeT, HasAlignValT;
1747 UsualDeallocFnInfo Best;
1749 for (
auto I = R.
begin(), E = R.
end(); I != E; ++I) {
1750 UsualDeallocFnInfo Info(S, I.getPair());
1758 BestFns->push_back(Info);
1762 if (Best.isBetterThan(Info, WantSize, WantAlign))
1767 if (BestFns && Info.isBetterThan(Best, WantSize, WantAlign))
1772 BestFns->push_back(Info);
1786 if (!record)
return false;
1799 if (ops.
empty())
return false;
1811 return Best && Best.HasSizeT;
1861 if (
Expr *NumElts = (
Expr *)Array.NumElts) {
1862 if (!NumElts->isTypeDependent() && !NumElts->isValueDependent()) {
1877 NumElts,
nullptr, diag::err_new_array_nonconst,
AllowFold)
1894 DirectInitRange = List->getSourceRange();
1897 PlacementLParen, PlacementArgs, PlacementRParen,
1898 TypeIdParens, AllocType, TInfo, ArraySize, DirectInitRange,
1907 return PLE->getNumExprs() == 0;
1908 if (isa<ImplicitValueInitExpr>(Init))
1911 return !CCE->isListInitialization() &&
1912 CCE->getConstructor()->isDefaultConstructor();
1914 assert(isa<InitListExpr>(Init) &&
1915 "Shouldn't create list CXXConstructExprs for arrays.");
1929 AlignmentParam.hasValue())
1940 StringRef OSName = AvailabilityAttr::getPlatformNameSourceSpelling(
1945 bool IsDelete =
Kind == OO_Delete ||
Kind == OO_Array_Delete;
1946 Diag(Loc, diag::err_aligned_allocation_unavailable)
1948 << OSVersion.getAsString() << OSVersion.empty();
1949 Diag(Loc, diag::note_silence_aligned_allocation_unavailable);
1963 Expr *Initializer) {
1968 if (DirectInitRange.
isValid()) {
1969 assert(
Initializer &&
"Have parens but no initializer.");
1976 "Initializer expression that cannot have been implicitly created.");
1983 Exprs =
MultiExprArg(List->getExprs(), List->getNumExprs());
2004 DirectInitRange.
getEnd());
2008 if (Deduced && isa<DeducedTemplateSpecializationType>(Deduced)) {
2011 Diag(*ArraySize ? (*ArraySize)->getExprLoc() : TypeRange.
getBegin(),
2012 diag::err_deduced_class_template_compound_type)
2014 << (*ArraySize ? (*ArraySize)->getSourceRange() : TypeRange));
2019 AllocTypeInfo, Entity,
Kind, Exprs);
2022 }
else if (Deduced) {
2026 auto *ILE = cast<InitListExpr>(Exprs[0]);
2027 Inits =
MultiExprArg(ILE->getInits(), ILE->getNumInits());
2031 return ExprError(
Diag(StartLoc, diag::err_auto_new_requires_ctor_arg)
2032 << AllocType << TypeRange);
2033 if (Inits.size() > 1) {
2034 Expr *FirstBad = Inits[1];
2036 diag::err_auto_new_ctor_multiple_expressions)
2037 << AllocType << TypeRange);
2041 << AllocType << TypeRange;
2042 Expr *Deduce = Inits[0];
2043 if (isa<InitListExpr>(Deduce))
2046 << Braced << AllocType << TypeRange);
2049 return ExprError(
Diag(StartLoc, diag::err_auto_new_deduction_failure)
2050 << AllocType << Deduce->
getType()
2065 AllocType = Array->getElementType();
2082 if (ArraySize && *ArraySize &&
2083 (*ArraySize)->getType()->isNonOverloadPlaceholderType()) {
2086 ArraySize = result.
get();
2096 if (ArraySize && *ArraySize && !(*ArraySize)->isTypeDependent()) {
2105 (*ArraySize)->getType()->getAs<
RecordType>())
2107 Diag(StartLoc, diag::warn_cxx98_compat_array_size_conversion)
2108 << (*ArraySize)->getType() << 0 <<
"'size_t'";
2115 SizeConvertDiagnoser(
Expr *ArraySize)
2117 ArraySize(ArraySize) {}
2121 return S.
Diag(Loc, diag::err_array_size_not_integral)
2127 return S.
Diag(Loc, diag::err_array_size_incomplete_type)
2133 return S.
Diag(Loc, diag::err_array_size_explicit_conversion) << T << ConvTy;
2144 return S.
Diag(Loc, diag::err_array_size_ambiguous_conversion) << T;
2158 ? diag::warn_cxx98_compat_array_size_conversion
2159 : diag::ext_array_size_conversion)
2162 } SizeDiagnoser(*ArraySize);
2170 ArraySize = ConvertedSize.
get();
2171 QualType SizeType = (*ArraySize)->getType();
2190 (*ArraySize)->getIntegerConstantExpr(
Context)) {
2191 if (
Value->isSigned() &&
Value->isNegative()) {
2193 diag::err_typecheck_negative_array_size)
2194 << (*ArraySize)->getSourceRange());
2198 unsigned ActiveSizeBits =
2202 Diag((*ArraySize)->getBeginLoc(), diag::err_array_too_large)
2206 KnownArraySize =
Value->getZExtValue();
2207 }
else if (TypeIdParens.
isValid()) {
2209 Diag((*ArraySize)->getBeginLoc(), diag::ext_new_paren_array_nonconst)
2210 << (*ArraySize)->getSourceRange()
2223 unsigned Alignment =
2226 bool PassAlignment =
getLangOpts().AlignedAllocation &&
2227 Alignment > NewAlignment;
2234 AllocType, ArraySize.hasValue(), PassAlignment, PlacementArgs,
2235 OperatorNew, OperatorDelete))
2240 bool UsualArrayDeleteWantsSize =
false;
2242 UsualArrayDeleteWantsSize =
2255 unsigned NumImplicitArgs = PassAlignment ? 2 : 1;
2257 NumImplicitArgs, PlacementArgs, AllPlaceArgs,
2261 if (!AllPlaceArgs.empty())
2262 PlacementArgs = AllPlaceArgs;
2279 AllocationSize = SingleEltSize;
2280 }
else if (KnownArraySize.hasValue() && !AllocType->
isDependentType()) {
2283 AllocationSize =
llvm::APInt(SizeTyWidth, *KnownArraySize)
2284 .umul_ov(SingleEltSize, Overflow);
2288 "Expected that all the overflows would have been handled already.");
2292 Context, AllocationSize.getValueOr(llvm::APInt::getZero(SizeTyWidth)),
2311 CK_IntegralCast, &AlignmentLiteral,
2316 CallArgs.reserve(NumImplicitArgs + PlacementArgs.size());
2317 CallArgs.emplace_back(AllocationSize.hasValue()
2318 ?
static_cast<Expr *
>(&AllocationSizeLiteral)
2319 : &OpaqueAllocationSize);
2321 CallArgs.emplace_back(&DesiredAlignment);
2322 CallArgs.insert(CallArgs.end(), PlacementArgs.begin(), PlacementArgs.end());
2326 checkCall(OperatorNew, Proto,
nullptr, CallArgs,
2327 false, StartLoc, Range, CallType);
2331 if (PlacementArgs.empty() && !PassAlignment &&
2335 if (Alignment > NewAlignment)
2336 Diag(StartLoc, diag::warn_overaligned_type)
2347 SourceRange InitRange(Exprs.front()->getBeginLoc(),
2348 Exprs.back()->getEndLoc());
2349 Diag(StartLoc, diag::err_new_array_init_args) << InitRange;
2369 InitType = AllocType;
2382 dyn_cast_or_null<CXXBindTemporaryExpr>(FullInit.
get()))
2383 FullInit = Binder->getSubExpr();
2390 if (ArraySize && !*ArraySize) {
2398 Diag(TypeRange.
getEnd(), diag::err_new_array_size_unknown_from_init)
2410 if (OperatorDelete) {
2417 PassAlignment, UsualArrayDeleteWantsSize,
2418 PlacementArgs, TypeIdParens, ArraySize, initStyle,
2430 return Diag(Loc, diag::err_bad_new_type)
2431 << AllocType << 0 << R;
2433 return Diag(Loc, diag::err_bad_new_type)
2434 << AllocType << 1 << R;
2437 Loc, AllocType, diag::err_new_incomplete_or_sizeless_type, R))
2440 diag::err_allocation_of_abstract_type))
2443 return Diag(Loc, diag::err_variably_modified_new_type)
2447 return Diag(Loc, diag::err_address_space_qualified_new)
2455 return Diag(Loc, diag::err_arc_new_array_without_ownership)
2470 Alloc != AllocEnd; ++Alloc) {
2507 if (PassAlignment) {
2508 PassAlignment =
false;
2510 Args.erase(Args.begin() + 1);
2512 Operator, &Candidates, AlignArg,
2538 (Args[1]->getType()->isObjectPointerType() ||
2539 Args[1]->getType()->isArrayType())) {
2540 S.
Diag(R.
getNameLoc(), diag::err_need_header_before_placement_new)
2555 if (AlignedCandidates) {
2557 return C.Function->getNumParams() > 1 &&
2558 C.Function->getParamDecl(1)->getType()->isAlignValT();
2562 AlignedArgs.reserve(Args.size() + 1);
2563 AlignedArgs.push_back(Args[0]);
2564 AlignedArgs.push_back(AlignArg);
2565 AlignedArgs.append(Args.begin() + 1, Args.end());
2578 if (AlignedCandidates)
2579 AlignedCandidates->
NoteCandidates(S, AlignedArgs, AlignedCands,
"",
2589 S.
PDiag(diag::err_ovl_ambiguous_call)
2599 S.
PDiag(diag::err_ovl_deleted_call)
2606 llvm_unreachable(
"Unreachable, bad result from BestViableFunction");
2628 AllocArgs.reserve((PassAlignment ? 2 : 1) + PlaceArgs.size());
2637 AllocArgs.push_back(&Size);
2640 if (PassAlignment) {
2646 AllocArgs.push_back(&Align);
2648 AllocArgs.insert(AllocArgs.end(), PlaceArgs.begin(), PlaceArgs.end());
2657 IsArray ? OO_Array_New : OO_New);
2689 if (PlaceArgs.empty()) {
2690 Diag(StartLoc, diag::err_openclcxx_not_supported) <<
"default new";
2692 Diag(StartLoc, diag::err_openclcxx_placement_new);
2697 assert(!R.
empty() &&
"implicitly declared allocation functions not found");
2698 assert(!R.
isAmbiguous() &&
"global allocation functions are ambiguous");
2704 OperatorNew,
nullptr,
2711 OperatorDelete =
nullptr;
2746 while (
Filter.hasNext()) {
2747 auto *FD = dyn_cast<FunctionDecl>(
Filter.next()->getUnderlyingDecl());
2748 if (FD && FD->isDestroyingOperatorDelete())
2754 bool FoundGlobalDelete = FoundDelete.
empty();
2755 if (FoundDelete.
empty()) {
2782 bool isPlacementNew = !PlaceArgs.empty() || OperatorNew->
param_size() != 1 ||
2785 if (isPlacementNew) {
2802 for (
unsigned I = 1, N = Proto->getNumParams(); I < N; ++I)
2803 ArgTypes.push_back(Proto->getParamType(I));
2807 EPI.
Variadic = Proto->isVariadic();
2809 ExpectedFunctionType
2814 DEnd = FoundDelete.
end();
2818 dyn_cast<FunctionTemplateDecl>((*D)->getUnderlyingDecl())) {
2826 Fn = cast<FunctionDecl>((*D)->getUnderlyingDecl());
2829 ExpectedFunctionType,
2831 ExpectedFunctionType))
2832 Matches.push_back(std::make_pair(D.getPair(), Fn));
2848 *
this, FoundDelete, FoundGlobalDelete,
2852 Matches.push_back(std::make_pair(Selected.Found, Selected.FD));
2856 for (
auto Fn : BestDeallocFns)
2857 Matches.push_back(std::make_pair(Fn.Found, Fn.FD));
2865 if (Matches.size() == 1) {
2866 OperatorDelete = Matches[0].second;
2876 UsualDeallocFnInfo Info(*
this,
2882 bool IsSizedDelete = Info.HasSizeT;
2883 if (IsSizedDelete && !FoundGlobalDelete) {
2884 auto NonSizedDelete =
2887 if (NonSizedDelete && !NonSizedDelete.HasSizeT &&
2888 NonSizedDelete.HasAlignValT == Info.HasAlignValT)
2889 IsSizedDelete =
false;
2892 if (IsSizedDelete) {
2896 PlaceArgs.back()->getEndLoc());
2897 Diag(StartLoc, diag::err_placement_new_non_placement_delete) << R;
2906 }
else if (!Matches.empty()) {
2910 Diag(StartLoc, diag::warn_ambiguous_suitable_delete_function_found)
2911 << DeleteName << AllocElemType;
2913 for (
auto &Match : Matches)
2914 Diag(Match.second->getLocation(),
2915 diag::note_member_declared_here) << DeleteName;
3001 AlignValT->setImplicit(
true);
3013 Params.push_back(Param);
3016 bool HasSizedVariant =
getLangOpts().SizedDeallocation &&
3017 (
Kind == OO_Delete ||
Kind == OO_Array_Delete);
3018 bool HasAlignedVariant =
getLangOpts().AlignedAllocation;
3020 int NumSizeVariants = (HasSizedVariant ? 2 : 1);
3021 int NumAlignVariants = (HasAlignedVariant ? 2 : 1);
3022 for (
int Sized = 0; Sized < NumSizeVariants; ++Sized) {
3024 Params.push_back(SizeT);
3026 for (
int Aligned = 0; Aligned < NumAlignVariants; ++Aligned) {
3039 DeclareGlobalAllocationFunctions(OO_New, VoidPtr, SizeT);
3040 DeclareGlobalAllocationFunctions(OO_Array_New, VoidPtr, SizeT);
3041 DeclareGlobalAllocationFunctions(OO_Delete,
Context.
VoidTy, VoidPtr);
3042 DeclareGlobalAllocationFunctions(OO_Array_Delete,
Context.
VoidTy, VoidPtr);
3055 Alloc != AllocEnd; ++Alloc) {
3058 if (
FunctionDecl *Func = dyn_cast<FunctionDecl>(*Alloc)) {
3059 if (Func->getNumParams() == Params.size()) {
3061 for (
auto *
P : Func->parameters())
3062 FuncParams.push_back(
3064 if (llvm::makeArrayRef(FuncParams) == Params) {
3068 Func->setVisibleDespiteOwningModule();
3076 false,
false,
true));
3079 bool HasBadAllocExceptionSpec
3080 = (Name.getCXXOverloadedOperator() == OO_New ||
3081 Name.getCXXOverloadedOperator() == OO_Array_New);
3082 if (HasBadAllocExceptionSpec) {
3085 assert(
StdBadAlloc &&
"Must have std::bad_alloc declared");
3097 auto CreateAllocationFunctionDecl = [&](
Attr *ExtraAttr) {
3107 if (HasBadAllocExceptionSpec &&
getLangOpts().NewInfallible)
3111 Alloc->
addAttr(VisibilityAttr::CreateImplicit(
3113 ? VisibilityAttr::Hidden
3114 : VisibilityAttr::Default));
3121 ParamDecls.back()->setImplicit();
3123 Alloc->setParams(ParamDecls);
3132 CreateAllocationFunctionDecl(
nullptr);
3136 CreateAllocationFunctionDecl(CUDAHostAttr::CreateImplicit(
Context));
3137 CreateAllocationFunctionDecl(CUDADeviceAttr::CreateImplicit(
Context));
3142 bool CanProvideSize,
3156 assert(Result.FD &&
"operator delete missing from global scope?");
3168 return OperatorDelete;
3196 Overaligned, &Matches);
3199 if (Matches.size() == 1) {
3200 Operator = cast<CXXMethodDecl>(Matches[0].FD);
3205 Diag(StartLoc, diag::err_deleted_function_use);
3221 if (!Matches.empty()) {
3223 Diag(StartLoc, diag::err_ambiguous_suitable_delete_member_function_found)
3225 for (
auto &Match : Matches)
3226 Diag(Match.FD->getLocation(), diag::note_member_declared_here) << Name;
3233 if (!Found.
empty()) {
3235 Diag(StartLoc, diag::err_no_suitable_delete_member_function_found)
3239 Diag(D->getUnderlyingDecl()->getLocation(),
3240 diag::note_member_declared_here) << Name;
3252 class MismatchingNewDeleteDetector {
3254 enum MismatchResult {
3260 MemberInitMismatches,
3269 explicit MismatchingNewDeleteDetector(
bool EndOfTU)
3270 : Field(nullptr), IsArrayForm(
false), EndOfTU(EndOfTU),
3271 HasUndefinedConstructors(
false) {}
3288 MismatchResult analyzeField(
FieldDecl *Field,
bool DeleteWasArrayForm);
3298 bool HasUndefinedConstructors;
3310 MismatchResult analyzeMemberExpr(
const MemberExpr *ME);
3333 MismatchResult analyzeInClassInitializer();
3337 MismatchingNewDeleteDetector::MismatchResult
3338 MismatchingNewDeleteDetector::analyzeDeleteExpr(
const CXXDeleteExpr *DE) {
3340 assert(DE &&
"Expected delete-expression");
3343 if (
const MemberExpr *ME = dyn_cast<const MemberExpr>(E)) {
3344 return analyzeMemberExpr(ME);
3345 }
else if (
const DeclRefExpr *D = dyn_cast<const DeclRefExpr>(E)) {
3346 if (!hasMatchingVarInit(D))
3347 return VarInitMismatches;
3353 MismatchingNewDeleteDetector::getNewExprFromInitListOrExpr(
const Expr *E) {
3354 assert(E !=
nullptr &&
"Expected a valid initializer expression");
3356 if (
const InitListExpr *ILE = dyn_cast<const InitListExpr>(E)) {
3357 if (ILE->getNumInits() == 1)
3358 E = dyn_cast<const CXXNewExpr>(ILE->getInit(0)->IgnoreParenImpCasts());
3361 return dyn_cast_or_null<const CXXNewExpr>(E);
3364 bool MismatchingNewDeleteDetector::hasMatchingNewInCtorInit(
3368 (
NE = getNewExprFromInitListOrExpr(CI->
getInit()))) {
3369 if (
NE->isArray() == IsArrayForm)
3372 NewExprs.push_back(
NE);
3377 bool MismatchingNewDeleteDetector::hasMatchingNewInCtor(
3383 HasUndefinedConstructors =
true;
3386 for (
const auto *CI : cast<const CXXConstructorDecl>(Definition)->inits()) {
3387 if (hasMatchingNewInCtorInit(CI))
3393 MismatchingNewDeleteDetector::MismatchResult
3394 MismatchingNewDeleteDetector::analyzeInClassInitializer() {
3395 assert(Field !=
nullptr &&
"This should be called only for members");
3396 const Expr *InitExpr =
Field->getInClassInitializer();
3398 return EndOfTU ? NoMismatch : AnalyzeLater;
3399 if (
const CXXNewExpr *
NE = getNewExprFromInitListOrExpr(InitExpr)) {
3400 if (
NE->isArray() != IsArrayForm) {
3401 NewExprs.push_back(
NE);
3402 return MemberInitMismatches;
3408 MismatchingNewDeleteDetector::MismatchResult
3409 MismatchingNewDeleteDetector::analyzeField(
FieldDecl *Field,
3410 bool DeleteWasArrayForm) {
3411 assert(Field !=
nullptr &&
"Analysis requires a valid class member.");
3412 this->Field =
Field;
3413 IsArrayForm = DeleteWasArrayForm;
3415 for (
const auto *CD : RD->
ctors()) {
3416 if (hasMatchingNewInCtor(CD))
3419 if (HasUndefinedConstructors)
3420 return EndOfTU ? NoMismatch : AnalyzeLater;
3421 if (!NewExprs.empty())
3422 return MemberInitMismatches;
3423 return Field->hasInClassInitializer() ? analyzeInClassInitializer()
3427 MismatchingNewDeleteDetector::MismatchResult
3428 MismatchingNewDeleteDetector::analyzeMemberExpr(
const MemberExpr *ME) {
3429 assert(ME !=
nullptr &&
"Expected a member expression");
3431 return analyzeField(F, IsArrayForm);
3435 bool MismatchingNewDeleteDetector::hasMatchingVarInit(
const DeclRefExpr *D) {
3438 if (VD->hasInit() && (
NE = getNewExprFromInitListOrExpr(VD->getInit())) &&
3439 NE->isArray() != IsArrayForm) {
3440 NewExprs.push_back(
NE);
3443 return NewExprs.empty();
3448 const MismatchingNewDeleteDetector &Detector) {
3451 if (!Detector.IsArrayForm)
3460 SemaRef.
Diag(DeleteLoc, diag::warn_mismatched_delete_new)
3461 << Detector.IsArrayForm << H;
3463 for (
const auto *
NE : Detector.NewExprs)
3464 SemaRef.
Diag(
NE->getExprLoc(), diag::note_allocated_here)
3465 << Detector.IsArrayForm;
3468 void Sema::AnalyzeDeleteExprMismatch(
const CXXDeleteExpr *DE) {
3471 MismatchingNewDeleteDetector Detector(
false);
3472 switch (Detector.analyzeDeleteExpr(DE)) {
3473 case MismatchingNewDeleteDetector::VarInitMismatches:
3474 case MismatchingNewDeleteDetector::MemberInitMismatches: {
3478 case MismatchingNewDeleteDetector::AnalyzeLater: {
3483 case MismatchingNewDeleteDetector::NoMismatch:
3489 bool DeleteWasArrayForm) {
3490 MismatchingNewDeleteDetector Detector(
true);
3491 switch (Detector.analyzeField(Field, DeleteWasArrayForm)) {
3492 case MismatchingNewDeleteDetector::VarInitMismatches:
3493 llvm_unreachable(
"This analysis should have been done for class members.");
3494 case MismatchingNewDeleteDetector::AnalyzeLater:
3495 llvm_unreachable(
"Analysis cannot be postponed any point beyond end of "
3496 "translation unit.");
3497 case MismatchingNewDeleteDetector::MemberInitMismatches:
3500 case MismatchingNewDeleteDetector::NoMismatch:
3511 bool ArrayForm,
Expr *ExE) {
3521 bool ArrayFormAsWritten = ArrayForm;
3522 bool UsualArrayDeleteWantsSize =
false;
3540 if (ConvPtrType->getPointeeType()->isIncompleteOrObjectType())
3547 return S.
Diag(Loc, diag::err_delete_operand) << T;
3552 return S.
Diag(Loc, diag::err_delete_incomplete_class_type) << T;
3558 return S.
Diag(Loc, diag::err_delete_explicit_conversion) << T << ConvTy;
3569 return S.
Diag(Loc, diag::err_ambiguous_delete_operand) << T;
3581 llvm_unreachable(
"conversion functions are permitted");
3589 if (!Converter.match(
Type))
3600 diag::err_address_space_qualified_delete)
3609 Diag(StartLoc, diag::ext_delete_void_ptr_operand)
3619 diag::warn_delete_incomplete, Ex.
get())) {
3621 PointeeRD = cast<CXXRecordDecl>(RT->getDecl());
3626 Diag(StartLoc, diag::warn_delete_array_type)
3633 ArrayForm ? OO_Array_Delete : OO_Delete);
3647 UsualArrayDeleteWantsSize =
3652 else if (OperatorDelete && isa<CXXMethodDecl>(OperatorDelete))
3653 UsualArrayDeleteWantsSize =
3654 UsualDeallocFnInfo(*
this,
3673 if (!OperatorDelete) {
3675 Diag(StartLoc, diag::err_openclcxx_not_supported) <<
"default delete";
3680 bool CanProvideSize =
3681 IsComplete && (!ArrayForm || UsualArrayDeleteWantsSize ||
3687 Overaligned, DeleteName);
3694 bool IsVirtualDelete =
false;
3698 PDiag(diag::err_access_dtor) << PointeeElem);
3699 IsVirtualDelete = Dtor->isVirtual();
3728 UsualArrayDeleteWantsSize, OperatorDelete, Ex.
get(), StartLoc);
3729 AnalyzeDeleteExprMismatch(Result);
3738 IsDelete ? OO_Delete : OO_New);
3742 assert(!R.
empty() &&
"implicitly declared allocation functions not found");
3743 assert(!R.
isAmbiguous() &&
"global allocation functions are ambiguous");
3752 FnOvl != FnOvlEnd; ++FnOvl) {
3755 NamedDecl *D = (*FnOvl)->getUnderlyingDecl();
3779 "class members should not be considered");
3782 S.
Diag(R.
getNameLoc(), diag::err_builtin_operator_new_delete_not_usual)
3783 << (IsDelete ? 1 : 0) << Range;
3784 S.
Diag(FnDecl->
getLocation(), diag::note_non_usual_function_declared_here)
3796 S.
PDiag(diag::err_ovl_no_viable_function_in_call)
3804 S.
PDiag(diag::err_ovl_ambiguous_call)
3817 llvm_unreachable(
"Unreachable, bad result from BestViableFunction");
3821 Sema::SemaBuiltinOperatorNewDeleteOverloaded(
ExprResult TheCallResult,
3823 CallExpr *TheCall = cast<CallExpr>(TheCallResult.
get());
3826 << (IsDelete ?
"__builtin_operator_delete" :
"__builtin_operator_new")
3836 OperatorNewOrDelete))
3838 assert(OperatorNewOrDelete &&
"should be found");
3844 for (
unsigned i = 0; i != TheCall->
getNumArgs(); ++i) {
3855 assert(Callee &&
Callee->getCastKind() == CK_BuiltinFnToFnPtr &&
3856 "Callee expected to be implicit cast to a builtin function pointer");
3859 return TheCallResult;
3863 bool IsDelete,
bool CallCanBeVirtual,
3864 bool WarnOnNonAbstractTypes,
3891 Diag(Loc, diag::warn_delete_abstract_non_virtual_dtor) << (IsDelete ? 0 : 1)
3893 }
else if (WarnOnNonAbstractTypes) {
3896 Diag(Loc, diag::warn_delete_non_virtual_dtor) << (IsDelete ? 0 : 1)
3902 Diag(DtorLoc, diag::note_delete_non_virtual)
3932 diag::err_invalid_use_of_function_type)
3936 diag::err_invalid_use_of_array_type)
3954 llvm_unreachable(
"unexpected condition kind");
3981 diag::err_constexpr_if_condition_expression_is_not_constant);
3993 From =
Cast->getSubExpr();
4005 if (!ToPtrType->getPointeeType().hasQualifiers()) {
4006 switch (StrLit->getKind()) {
4013 return (ToPointeeType->getKind() == BuiltinType::Char_U ||
4014 ToPointeeType->getKind() == BuiltinType::Char_S);
4031 bool HadMultipleCandidates,
4034 default: llvm_unreachable(
"Unhandled cast kind!");
4035 case CK_ConstructorConversion: {
4040 diag::err_allocation_of_abstract_type))
4053 CastLoc, Ty, FoundDecl, cast<CXXConstructorDecl>(Method),
4054 ConstructorArgs, HadMultipleCandidates,
4055 false,
false,
false,
4057 if (Result.isInvalid())
4063 case CK_UserDefinedConversion: {
4073 HadMultipleCandidates);
4074 if (Result.isInvalid())
4078 CK_UserDefinedConversion, Result.get(),
4079 nullptr, Result.get()->getValueKind(),
4116 assert(FD &&
"no conversion function for user-defined conversion seq");
4118 CastKind = CK_UserDefinedConversion;
4126 CastKind = CK_ConstructorConversion;
4154 From = CastArg.
get();
4168 PDiag(diag::err_typecheck_ambiguous_condition)
4173 llvm_unreachable(
"Cannot perform an ellipsis conversion");
4180 ToType, From->
getType(), From, Action);
4181 assert(Diagnosed &&
"failed to diagnose bad conversion"); (void)Diagnosed;
4219 ConstructorArgs,
false,
4220 false,
false,
false,
4227 false,
false,
false,
4250 From = Checked.
get();
4258 ToAtomicType = ToType;
4259 ToType = ToAtomic->getValueType();
4262 QualType InitialFromType = FromType;
4264 switch (SCS.
First) {
4267 FromType = FromAtomic->getValueType().getUnqualifiedType();
4280 From = FromRes.
get();
4300 llvm_unreachable(
"Improper first standard conversion");
4337 "only enums with fixed underlying type can promote to bool");
4362 CK = CK_FloatingComplexCast;
4364 CK = CK_FloatingComplexToIntegralComplex;
4366 CK = CK_IntegralComplexToFloatingComplex;
4368 CK = CK_IntegralComplexCast;
4389 nullptr, CCK).
get();
4398 diag::ext_typecheck_convert_incompatible_pointer)
4403 diag::ext_typecheck_convert_incompatible_pointer)
4410 }
else if (
getLangOpts().allowsNonTrivialObjCLifetimeQualifiers() &&
4416 Diag(From->
getBeginLoc(), diag::err_arc_convesion_of_weak_unavailable)
4445 if (
Kind == CK_BlockPointerToObjCPointerCast) {
4499 &BasePath, CCK).
get();
4527 QualType ElType = ToComplex->getElementType();
4535 isFloatingComplex ? CK_FloatingCast : CK_FloatingToIntegral).
get();
4539 isFloatingComplex ? CK_IntegralToFloating : CK_IntegralCast).
get();
4543 isFloatingComplex ? CK_FloatingRealToComplex
4544 : CK_IntegralRealToComplex).
get();
4549 QualType ElType = FromComplex->getElementType();
4554 isFloatingComplex ? CK_FloatingComplexToReal
4555 : CK_IntegralComplexToReal,
4564 isFloatingComplex ? CK_FloatingCast
4565 : CK_IntegralToFloating,
4571 isFloatingComplex ? CK_FloatingToIntegral
4587 AddrSpaceL != AddrSpaceR ? CK_AddressSpaceConversion : CK_BitCast;
4600 From = FromRes.
get();
4602 "Improper transparent union conversion");
4610 CK_ZeroToOCLOpaqueType,
4622 llvm_unreachable(
"Improper second standard conversion");
4625 switch (SCS.
Third) {
4648 CK = CK_AddressSpaceConversion;
4653 CK = CK_AddressSpaceConversion;
4659 << InitialFromType << ToType;
4670 ? diag::ext_deprecated_string_literal_conversion
4671 : diag::warn_deprecated_string_literal_conversion)
4679 llvm_unreachable(
"Improper third standard conversion");
4684 if (!ToAtomicType.
isNull()) {
4730 default: llvm_unreachable(
"not a UTT");
4732 case UTT_IsCompleteType:
4740 case UTT_IsIntegral:
4741 case UTT_IsFloatingPoint:
4744 case UTT_IsLvalueReference:
4745 case UTT_IsRvalueReference:
4746 case UTT_IsMemberFunctionPointer:
4747 case UTT_IsMemberObjectPointer:
4751 case UTT_IsFunction:
4752 case UTT_IsReference:
4753 case UTT_IsArithmetic:
4754 case UTT_IsFundamental:
4757 case UTT_IsCompound:
4758 case UTT_IsMemberPointer:
4767 case UTT_IsVolatile:
4769 case UTT_IsUnsigned:
4772 case UTT_IsInterfaceClass:
4778 case UTT_IsPolymorphic:
4779 case UTT_IsAbstract:
4783 Loc, ArgTy, diag::err_incomplete_type_used_in_type_trait_expr);
4792 Loc, ArgTy, diag::err_incomplete_type_used_in_type_trait_expr);
4797 case UTT_IsAggregate:
4799 case UTT_IsTriviallyCopyable:
4800 case UTT_IsStandardLayout:
4804 case UTT_IsTriviallyRelocatable:
4808 case UTT_HasNothrowAssign:
4809 case UTT_HasNothrowMoveAssign:
4810 case UTT_HasNothrowConstructor:
4811 case UTT_HasNothrowCopy:
4812 case UTT_HasTrivialAssign:
4813 case UTT_HasTrivialMoveAssign:
4814 case UTT_HasTrivialDefaultConstructor:
4815 case UTT_HasTrivialMoveConstructor:
4816 case UTT_HasTrivialCopy:
4817 case UTT_HasTrivialDestructor:
4818 case UTT_HasVirtualDestructor:
4824 case UTT_IsDestructible:
4825 case UTT_IsNothrowDestructible:
4826 case UTT_IsTriviallyDestructible:
4827 case UTT_HasUniqueObjectRepresentations:
4832 Loc, ArgTy, diag::err_incomplete_type_used_in_type_trait_expr);
4843 if ((RD->*HasTrivial)() && !(RD->*HasNonTrivial)())
4850 bool FoundOperator =
false;
4853 Op != OpEnd; ++Op) {
4854 if (isa<FunctionTemplateDecl>(*Op))
4858 if((Operator->*IsDesiredOp)()) {
4859 FoundOperator =
true;
4866 return FoundOperator;
4873 assert(!T->
isDependentType() &&
"Cannot evaluate traits of dependent type");
4877 default: llvm_unreachable(
"not a UTT");
4882 case UTT_IsIntegral:
4884 case UTT_IsFloatingPoint:
4890 case UTT_IsLvalueReference:
4892 case UTT_IsRvalueReference:
4894 case UTT_IsMemberFunctionPointer:
4896 case UTT_IsMemberObjectPointer:
4904 case UTT_IsFunction:
4909 case UTT_IsReference:
4911 case UTT_IsArithmetic:
4913 case UTT_IsFundamental:
4936 case UTT_IsCompound:
4938 case UTT_IsMemberPointer:
4945 case UTT_IsVolatile:
4949 case UTT_IsTriviallyCopyable:
4951 case UTT_IsStandardLayout:
4961 case UTT_IsPolymorphic:
4965 case UTT_IsAbstract:
4969 case UTT_IsAggregate:
4978 case UTT_IsInterfaceClass:
4983 return RD->
hasAttr<FinalAttr>();
4990 case UTT_IsUnsigned:
5009 case UTT_HasTrivialDefaultConstructor:
5016 if (
CXXRecordDecl *RD = C.getBaseElementType(T)->getAsCXXRecordDecl())
5020 case UTT_HasTrivialMoveConstructor:
5026 if (
CXXRecordDecl *RD = C.getBaseElementType(T)->getAsCXXRecordDecl())
5029 case UTT_HasTrivialCopy:
5041 case UTT_HasTrivialMoveAssign:
5047 if (
CXXRecordDecl *RD = C.getBaseElementType(T)->getAsCXXRecordDecl())
5050 case UTT_HasTrivialAssign:
5071 case UTT_IsDestructible:
5072 case UTT_IsTriviallyDestructible:
5073 case UTT_IsNothrowDestructible:
5099 if (
auto *RD = C.getBaseElementType(T)->getAsCXXRecordDecl()) {
5106 if (Destructor->isDeleted())
5108 if (C.getLangOpts().AccessControl && Destructor->getAccess() !=
AS_public)
5110 if (UTT == UTT_IsNothrowDestructible) {
5119 case UTT_HasTrivialDestructor:
5134 if (
CXXRecordDecl *RD = C.getBaseElementType(T)->getAsCXXRecordDecl())
5138 case UTT_HasNothrowAssign:
5146 if (C.getBaseElementType(T).isConstQualified())
5159 case UTT_HasNothrowMoveAssign:
5172 case UTT_HasNothrowCopy:
5185 bool FoundConstructor =
false;
5191 if (isa<FunctionTemplateDecl>(ND->getUnderlyingDecl()))
5194 if (isa<UsingDecl>(ND))
5196 auto *Constructor = cast<CXXConstructorDecl>(ND->getUnderlyingDecl());
5197 if (Constructor->isCopyConstructor(FoundTQs)) {
5198 FoundConstructor =
true;
5210 return FoundConstructor;
5213 case UTT_HasNothrowConstructor:
5221 if (
CXXRecordDecl *RD = C.getBaseElementType(T)->getAsCXXRecordDecl()) {
5226 bool FoundConstructor =
false;
5229 if (isa<FunctionTemplateDecl>(ND->getUnderlyingDecl()))
5232 if (isa<UsingDecl>(ND))
5234 auto *Constructor = cast<CXXConstructorDecl>(ND->getUnderlyingDecl());
5235 if (Constructor->isDefaultConstructor()) {
5236 FoundConstructor =
true;
5247 return FoundConstructor;
5250 case UTT_HasVirtualDestructor:
5256 return Destructor->isVirtual();
5262 case UTT_IsCompleteType:
5267 case UTT_HasUniqueObjectRepresentations:
5268 return C.hasUniqueObjectRepresentations(T);
5269 case UTT_IsTriviallyRelocatable:
5287 Args[1]->getType(), RParenLoc);
5290 case clang::BTT_ReferenceBindsToTemporary:
5291 case clang::TT_IsConstructible:
5292 case clang::TT_IsNothrowConstructible:
5293 case clang::TT_IsTriviallyConstructible: {
5307 assert(!Args.empty());
5312 for (
const auto *TSI : Args) {
5318 diag::err_incomplete_type_used_in_type_trait_expr))
5332 llvm::BumpPtrAllocator OpaqueExprAllocator;
5334 ArgExprs.reserve(Args.size() - 1);
5335 for (
unsigned I = 1, N = Args.size(); I != N; ++I) {
5336 QualType ArgTy = Args[I]->getType();
5360 ExprResult Result = Init.Perform(S, To, InitKind, ArgExprs);
5364 if (
Kind == clang::TT_IsConstructible)