26 #include "llvm/ADT/SmallVector.h"
28 using namespace clang;
49 struct CastOperation {
51 : Self(S), SrcExpr(src), DestType(destType),
57 src.
get()->getType()->getAsPlaceholderType()) {
58 PlaceholderKind = placeholder->getKind();
72 bool IsARCUnbridgedCast;
78 void CheckConstCast();
79 void CheckReinterpretCast();
80 void CheckStaticCast();
81 void CheckDynamicCast();
82 void CheckCXXCStyleCast(
bool FunctionalCast,
bool ListInitialization);
83 void CheckCStyleCast();
90 if (IsARCUnbridgedCast) {
92 Self.Context.ARCUnbridgedCastTy,
105 if (PlaceholderKind != K)
return false;
111 bool isPlaceholder()
const {
112 return PlaceholderKind != 0;
115 return PlaceholderKind == K;
118 void checkCastAlign() {
119 Self.CheckCastAlign(SrcExpr.get(), DestType, OpRange);
123 assert(Self.getLangOpts().ObjCAutoRefCount);
126 if (Self.CheckObjCARCConversion(OpRange, DestType, src, CCK) ==
128 IsARCUnbridgedCast =
true;
133 void checkNonOverloadPlaceholders() {
134 if (!isPlaceholder() || isPlaceholder(BuiltinType::Overload))
137 SrcExpr = Self.CheckPlaceholderExpr(SrcExpr.get());
138 if (SrcExpr.isInvalid())
177 QualType OrigDestType,
unsigned &msg,
193 bool ListInitialization);
200 bool ListInitialization);
246 CastOperation Op(*
this, DestType, E);
248 Op.DestRange = AngleBrackets;
251 default: llvm_unreachable(
"Unknown C++ cast!");
253 case tok::kw_const_cast:
254 if (!TypeDependent) {
256 if (Op.SrcExpr.isInvalid())
260 Op.ValueKind, Op.SrcExpr.get(), DestTInfo,
264 case tok::kw_dynamic_cast: {
265 if (!TypeDependent) {
266 Op.CheckDynamicCast();
267 if (Op.SrcExpr.isInvalid())
271 Op.ValueKind, Op.Kind, Op.SrcExpr.get(),
272 &Op.BasePath, DestTInfo,
276 case tok::kw_reinterpret_cast: {
277 if (!TypeDependent) {
278 Op.CheckReinterpretCast();
279 if (Op.SrcExpr.isInvalid())
283 Op.ValueKind, Op.Kind, Op.SrcExpr.get(),
284 nullptr, DestTInfo, OpLoc,
288 case tok::kw_static_cast: {
289 if (!TypeDependent) {
290 Op.CheckStaticCast();
291 if (Op.SrcExpr.isInvalid())
296 Op.ValueKind, Op.Kind, Op.SrcExpr.get(),
297 &Op.BasePath, DestTInfo,
309 bool listInitialization) {
331 range, listInitialization)
337 assert(sequence.
Failed() &&
"initialization succeeded on second try?");
339 default:
return false;
352 case OR_Success: llvm_unreachable(
"successful failed overload");
354 if (candidates.
empty())
355 msg = diag::err_ovl_no_conversion_in_cast;
357 msg = diag::err_ovl_no_viable_conversion_in_cast;
362 msg = diag::err_ovl_ambiguous_conversion_in_cast;
367 msg = diag::err_ovl_deleted_conversion_in_cast;
373 << CT << srcType << destType
374 << range << src->getSourceRange();
384 bool listInitialization) {
385 if (msg == diag::err_bad_cxx_cast_generic &&
391 << src->
getType() << destType << opRange << src->getSourceRange();
394 int DifferentPtrness = 0;
405 if (!DifferentPtrness) {
408 if (RecFrom && RecTo) {
410 if (!DeclFrom->isCompleteDefinition())
411 S.
Diag(DeclFrom->getLocation(), diag::note_type_incomplete)
412 << DeclFrom->getDeclName();
414 if (!DeclTo->isCompleteDefinition())
415 S.
Diag(DeclTo->getLocation(), diag::note_type_incomplete)
416 << DeclTo->getDeclName();
429 if (T1PtrType && T2PtrType) {
444 else if (T2PtrType) {
450 else if (T2ObjCPtrType) {
460 if (T1MPType && T2MPType) {
468 if (T1BPType && T2BPType) {
487 bool CheckCVR,
bool CheckObjCLifetime,
488 QualType *TheOffendingSrcType =
nullptr,
489 QualType *TheOffendingDestType =
nullptr,
493 if (!CheckCVR && CheckObjCLifetime &&
503 "Source type is not pointer or pointer to member.");
506 "Destination type is not pointer or pointer to member.");
515 QualType PrevUnwrappedSrcType = UnwrappedSrcType;
516 QualType PrevUnwrappedDestType = UnwrappedDestType;
523 Qualifiers RetainedSrcQuals, RetainedDestQuals;
528 if (RetainedSrcQuals != RetainedDestQuals && TheOffendingSrcType &&
529 TheOffendingDestType && CastAwayQualifiers) {
530 *TheOffendingSrcType = PrevUnwrappedSrcType;
531 *TheOffendingDestType = PrevUnwrappedDestType;
532 *CastAwayQualifiers = RetainedSrcQuals - RetainedDestQuals;
536 if (CheckObjCLifetime &&
540 cv1.push_back(RetainedSrcQuals);
541 cv2.push_back(RetainedDestQuals);
543 PrevUnwrappedSrcType = UnwrappedSrcType;
544 PrevUnwrappedDestType = UnwrappedDestType;
556 i1 != cv1.rend(); ++i1, ++i2) {
564 bool ObjCLifetimeConversion;
565 return SrcConstruct != DestConstruct &&
567 ObjCLifetimeConversion);
573 void CastOperation::CheckDynamicCast() {
575 SrcExpr = Self.DefaultFunctionArrayLvalueConversion(SrcExpr.get());
576 else if (isPlaceholder())
577 SrcExpr = Self.CheckPlaceholderExpr(SrcExpr.get());
578 if (SrcExpr.isInvalid())
581 QualType OrigSrcType = SrcExpr.get()->getType();
595 Self.Diag(OpRange.getBegin(), diag::err_bad_dynamic_cast_not_ref_or_ptr)
596 << this->DestType << DestRange;
603 assert(DestPointer &&
"Reference to void is not possible");
604 }
else if (DestRecord) {
605 if (Self.RequireCompleteType(OpRange.getBegin(), DestPointee,
606 diag::err_bad_dynamic_cast_incomplete,
612 Self.Diag(OpRange.getBegin(), diag::err_bad_dynamic_cast_not_class)
628 Self.Diag(OpRange.getBegin(), diag::err_bad_dynamic_cast_not_ptr)
629 << OrigSrcType << SrcExpr.get()->getSourceRange();
633 }
else if (DestReference->isLValueReferenceType()) {
634 if (!SrcExpr.get()->isLValue()) {
635 Self.Diag(OpRange.getBegin(), diag::err_bad_cxx_cast_rvalue)
636 <<
CT_Dynamic << OrigSrcType << this->DestType << OpRange;
638 SrcPointee = SrcType;
642 if (SrcExpr.get()->isRValue())
644 SrcType, SrcExpr.get(),
false);
645 SrcPointee = SrcType;
650 if (Self.RequireCompleteType(OpRange.getBegin(), SrcPointee,
651 diag::err_bad_dynamic_cast_incomplete,
657 Self.Diag(OpRange.getBegin(), diag::err_bad_dynamic_cast_not_class)
663 assert((DestPointer || DestReference) &&
664 "Bad destination non-ptr/ref slipped through.");
665 assert((DestRecord || DestPointee->
isVoidType()) &&
666 "Bad destination pointee slipped through.");
667 assert(SrcRecord &&
"Bad source pointee slipped through.");
671 Self.Diag(OpRange.getBegin(), diag::err_bad_cxx_cast_qualifiers_away)
672 <<
CT_Dynamic << OrigSrcType << this->DestType << OpRange;
679 if (DestRecord == SrcRecord) {
687 Self.IsDerivedFrom(OpRange.getBegin(), SrcPointee, DestPointee)) {
688 if (Self.CheckDerivedToBaseConversion(SrcPointee, DestPointee,
689 OpRange.getBegin(), OpRange,
701 assert(SrcDecl &&
"Definition missing");
702 if (!cast<CXXRecordDecl>(SrcDecl)->isPolymorphic()) {
703 Self.Diag(OpRange.getBegin(), diag::err_bad_dynamic_cast_not_polymorphic)
711 if (!Self.getLangOpts().RTTI && !DestPointee->
isVoidType()) {
712 Self.Diag(OpRange.getBegin(), diag::err_no_dynamic_cast_with_fno_rtti);
726 void CastOperation::CheckConstCast() {
728 SrcExpr = Self.DefaultFunctionArrayLvalueConversion(SrcExpr.get());
729 else if (isPlaceholder())
730 SrcExpr = Self.CheckPlaceholderExpr(SrcExpr.get());
731 if (SrcExpr.isInvalid())
734 unsigned msg = diag::err_bad_cxx_cast_generic;
737 Self.Diag(OpRange.getBegin(), msg) <<
CT_Const
738 << SrcExpr.get()->getType() << DestType << OpRange;
774 ReinterpretKind = ReinterpretUpcast;
776 ReinterpretKind = ReinterpretDowncast;
780 bool VirtualBase =
true;
781 bool NonZeroOffset =
false;
787 bool IsVirtual =
false;
788 for (CXXBasePath::const_iterator IElem = Path.begin(), EElem = Path.end();
789 IElem != EElem; ++IElem) {
790 IsVirtual = IElem->Base->isVirtual();
793 const CXXRecordDecl *BaseRD = IElem->Base->getType()->getAsCXXRecordDecl();
794 assert(BaseRD &&
"Base type should be a valid unqualified class type");
800 !ClassDefinition->isCompleteDefinition())
813 NonZeroOffset =
true;
815 VirtualBase = VirtualBase && IsVirtual;
818 (void) NonZeroOffset;
819 assert((VirtualBase || NonZeroOffset) &&
820 "Should have returned if has non-virtual base with zero offset");
823 ReinterpretKind == ReinterpretUpcast? DestType : SrcType;
825 ReinterpretKind == ReinterpretUpcast? SrcType : DestType;
828 Self.
Diag(BeginLoc, diag::warn_reinterpret_different_from_static)
829 << DerivedType << BaseType << !VirtualBase << int(ReinterpretKind)
831 Self.
Diag(BeginLoc, diag::note_reinterpret_updowncast_use_static)
832 << int(ReinterpretKind)
841 void CastOperation::CheckReinterpretCast() {
842 if (ValueKind ==
VK_RValue && !isPlaceholder(BuiltinType::Overload))
843 SrcExpr = Self.DefaultFunctionArrayLvalueConversion(SrcExpr.get());
845 checkNonOverloadPlaceholders();
846 if (SrcExpr.isInvalid())
849 unsigned msg = diag::err_bad_cxx_cast_generic;
852 false, OpRange, msg,
Kind);
855 if (SrcExpr.isInvalid())
857 if (SrcExpr.get()->getType() == Self.Context.OverloadTy) {
859 Self.Diag(OpRange.getBegin(), diag::err_bad_reinterpret_cast_overload)
861 << DestType << OpRange;
862 Self.NoteAllOverloadCandidates(SrcExpr.get());
870 if (Self.getLangOpts().ObjCAutoRefCount)
880 void CastOperation::CheckStaticCast() {
881 if (isPlaceholder()) {
882 checkNonOverloadPlaceholders();
883 if (SrcExpr.isInvalid())
893 if (claimPlaceholder(BuiltinType::Overload)) {
894 Self.ResolveAndFixSingleFunctionTemplateSpecialization(SrcExpr,
897 OpRange, DestType, diag::err_bad_static_cast_overload);
898 if (SrcExpr.isInvalid())
902 SrcExpr = Self.IgnoredValueConversions(SrcExpr.get());
907 !isPlaceholder(BuiltinType::Overload)) {
908 SrcExpr = Self.DefaultFunctionArrayLvalueConversion(SrcExpr.get());
909 if (SrcExpr.isInvalid())
913 unsigned msg = diag::err_bad_cxx_cast_generic;
916 Kind, BasePath,
false);
918 if (SrcExpr.isInvalid())
920 if (SrcExpr.get()->getType() == Self.Context.OverloadTy) {
922 Self.Diag(OpRange.getBegin(), diag::err_bad_static_cast_overload)
923 << oe->
getName() << DestType << OpRange
925 Self.NoteAllOverloadCandidates(SrcExpr.get());
934 if (Self.getLangOpts().ObjCAutoRefCount)
949 bool ListInitialization) {
975 OpRange, msg,
Kind, BasePath);
990 Kind, ListInitialization);
1010 if (Enum->getDecl()->isScoped()) {
1053 OpRange, msg, Kind, BasePath);
1076 if (DestPointeeQuals != SrcPointeeQuals &&
1078 msg = diag::err_bad_cxx_cast_qualifiers_away;
1090 Self.
Diag(OpRange.getBegin(), diag::ext_ms_cast_fn_obj) << OpRange;
1124 if (SrcPointer->getPointeeType()->getAs<
RecordType>() &&
1126 msg = diag::err_bad_cxx_cast_unrelated_class;
1151 bool ObjCConversion;
1152 bool ObjCLifetimeConversion;
1162 DerivedToBase, ObjCConversion,
1163 ObjCLifetimeConversion)
1167 msg = diag::err_bad_lvalue_to_rvalue_cast;
1171 if (DerivedToBase) {
1202 if (!DestReference) {
1206 if (!RValueRef && !SrcExpr->
isLValue()) {
1208 msg = diag::err_bad_cxx_cast_rvalue;
1245 msg = diag::err_bad_static_cast_pointer_nonpointer;
1252 CStyle, OpRange, SrcType, DestType, msg, Kind,
1262 QualType OrigDestType,
unsigned &msg,
1300 msg = diag::err_bad_cxx_cast_qualifiers_away;
1304 if (Paths.
isAmbiguous(SrcType.getUnqualifiedType())) {
1314 std::string PathDisplayStr;
1315 std::set<unsigned> DisplayedPaths;
1318 if (DisplayedPaths.insert(PI->back().SubobjectNumber).second) {
1321 PathDisplayStr +=
"\n ";
1322 for (CXXBasePath::const_reverse_iterator EI = PI->rbegin(),
1325 PathDisplayStr += EI->Base->getType().getAsString() +
" -> ";
1330 Self.
Diag(OpRange.
getBegin(), diag::err_ambiguous_base_to_derived_cast)
1333 << PathDisplayStr << OpRange;
1340 Self.
Diag(OpRange.
getBegin(), diag::err_static_downcast_via_virtual)
1341 << OrigSrcType << OrigDestType << VirtualBase << OpRange;
1350 diag::err_downcast_from_inaccessible_base)) {
1384 bool WasOverloadedFunction =
false;
1393 WasOverloadedFunction =
true;
1399 msg = diag::err_bad_static_cast_member_pointer_nonmp;
1424 Paths.setRecordingPaths(
true);
1430 Self.
Diag(OpRange.
getBegin(), diag::err_ambiguous_memptr_conv)
1431 << 1 << SrcClass << DestClass << PathDisplayStr << OpRange;
1436 if (
const RecordType *VBase = Paths.getDetectedVirtual()) {
1437 Self.
Diag(OpRange.
getBegin(), diag::err_memptr_conv_via_virtual)
1438 << SrcClass << DestClass <<
QualType(VBase, 0) << OpRange;
1445 DestClass, SrcClass,
1447 diag::err_upcast_to_inaccessible_base)) {
1461 if (WasOverloadedFunction) {
1497 diag::err_bad_dynamic_cast_incomplete) ||
1499 diag::err_allocation_of_abstract_type)) {
1513 Expr *SrcExprRaw = SrcExpr.
get();
1548 bool NeedToMaterializeTemporary =
false;
1562 if (isa<LValueReferenceType>(DestTypeTmp) && !SrcExpr.
get()->isLValue()) {
1566 msg = diag::err_bad_cxx_cast_rvalue;
1570 if (isa<RValueReferenceType>(DestTypeTmp) && SrcExpr.
get()->isRValue()) {
1574 msg = diag::err_bad_cxx_cast_rvalue;
1580 NeedToMaterializeTemporary =
true;
1588 if (SrcExpr.
get()->refersToBitField()) {
1589 msg = diag::err_bad_cxx_cast_bitfield;
1609 msg = diag::err_bad_const_cast_dest;
1618 msg = diag::err_bad_const_cast_dest;
1628 while (SrcType != DestType &&
1638 if (SrcQuals != DestQuals)
1643 if (SrcType != DestType)
1646 if (NeedToMaterializeTemporary)
1650 SrcType, SrcExpr.
get(),
false);
1663 unsigned DiagID = IsDereference ?
1664 diag::warn_pointer_indirection_from_incompatible_type :
1665 diag::warn_undefined_reinterpret_cast;
1671 if (IsDereference) {
1707 Diag(Range.
getBegin(), DiagID) << SrcType << DestType << Range;
1716 if (SrcPtrTy->isObjCSelType()) {
1718 if (isa<PointerType>(DestType))
1721 Self.
Diag(SrcExpr.
get()->getExprLoc(),
1722 diag::warn_cast_pointer_from_sel)
1723 << SrcType << DestType << SrcExpr.
get()->getSourceRange();
1747 diag::warn_int_to_void_pointer_cast
1748 : diag::warn_int_to_pointer_cast;
1749 Self.
Diag(Loc, Diag) << SrcType << DestType;
1758 bool IsLValueCast =
false;
1773 ) && SingleFunctionExpr.
isUsable()) {
1774 SrcExpr = SingleFunctionExpr;
1775 SrcType = SrcExpr.
get()->getType();
1782 if (!SrcExpr.
get()->isGLValue()) {
1785 msg = diag::err_bad_cxx_cast_rvalue;
1798 const char *inappropriate =
nullptr;
1799 switch (SrcExpr.
get()->getObjectKind()) {
1802 case OK_BitField: inappropriate =
"bit-field";
break;
1805 case OK_ObjCSubscript: inappropriate =
"container subscripting expression";
1808 if (inappropriate) {
1809 Self.
Diag(OpRange.
getBegin(), diag::err_bad_reinterpret_cast_reference)
1810 << inappropriate << DestType
1811 << OpRange << SrcExpr.
get()->getSourceRange();
1820 IsLValueCast =
true;
1828 if (DestMemPtr && SrcMemPtr) {
1834 SrcMemPtr->isMemberFunctionPointer())
1843 msg = diag::err_bad_cxx_cast_qualifiers_away;
1857 msg = diag::err_bad_cxx_cast_member_pointer_size;
1862 assert(!IsLValueCast);
1875 msg = diag::err_bad_reinterpret_cast_small_int;
1886 if (srcIsVector || destIsVector) {
1903 msg = diag::err_bad_cxx_cast_vector_to_scalar_different_size;
1904 else if (!srcIsVector)
1905 msg = diag::err_bad_cxx_cast_scalar_to_vector_different_size;
1907 msg = diag::err_bad_cxx_cast_vector_to_vector_different_size;
1912 if (SrcType == DestType) {
1936 if (!destIsPtr && !srcIsPtr) {
1943 assert(srcIsPtr &&
"One type must be a pointer");
1947 bool MicrosoftException = Self.
getLangOpts().MicrosoftExt &&
1951 !MicrosoftException) {
1952 msg = diag::err_bad_reinterpret_cast_small_int;
1960 assert(destIsPtr &&
"One type must be a pointer");
1971 if (!destIsPtr || !srcIsPtr) {
1981 msg = diag::err_bad_cxx_cast_qualifiers_away;
2030 diag::warn_cxx98_compat_cast_fn_obj : diag::ext_cast_fn_obj)
2039 diag::warn_cxx98_compat_cast_fn_obj : diag::ext_cast_fn_obj)
2052 void CastOperation::CheckCXXCStyleCast(
bool FunctionalStyle,
2053 bool ListInitialization) {
2055 if (isPlaceholder()) {
2057 if (claimPlaceholder(BuiltinType::UnknownAny)) {
2058 SrcExpr = Self.checkUnknownAnyCast(DestRange, DestType,
2059 SrcExpr.get(),
Kind,
2060 ValueKind, BasePath);
2064 checkNonOverloadPlaceholders();
2065 if (SrcExpr.isInvalid())
2075 if (claimPlaceholder(BuiltinType::Overload)) {
2076 Self.ResolveAndFixSingleFunctionTemplateSpecialization(
2078 true, DestRange, DestType,
2079 diag::err_bad_cstyle_cast_overload);
2080 if (SrcExpr.isInvalid())
2084 SrcExpr = Self.IgnoredValueConversions(SrcExpr.get());
2089 if (DestType->
isDependentType() || SrcExpr.get()->isTypeDependent() ||
2090 SrcExpr.get()->isValueDependent()) {
2096 !isPlaceholder(BuiltinType::Overload)) {
2097 SrcExpr = Self.DefaultFunctionArrayLvalueConversion(SrcExpr.get());
2098 if (SrcExpr.isInvalid())
2105 && (SrcExpr.get()->getType()->isIntegerType()
2106 || SrcExpr.get()->getType()->isFloatingType())) {
2108 SrcExpr = Self.prepareVectorSplat(DestType, SrcExpr.get());
2123 unsigned msg = diag::err_bad_cxx_cast_generic;
2126 if (SrcExpr.isInvalid())
2137 msg,
Kind, BasePath, ListInitialization);
2138 if (SrcExpr.isInvalid())
2144 OpRange, msg,
Kind);
2145 if (SrcExpr.isInvalid())
2150 if (Self.getLangOpts().ObjCAutoRefCount && tcr ==
TC_Success)
2151 checkObjCARCConversion(CCK);
2154 if (SrcExpr.get()->getType() == Self.Context.OverloadTy) {
2156 FunctionDecl *Fn = Self.ResolveAddressOfOverloadedFunction(SrcExpr.get(),
2165 Self.Diag(OpRange.getBegin(), diag::err_bad_cstyle_cast_overload)
2166 << OE->
getName() << DestType << OpRange
2168 Self.NoteAllOverloadCandidates(SrcExpr.get());
2172 OpRange, SrcExpr.get(), DestType, ListInitialization);
2189 SrcExpr.
get()->getExprLoc()))
2192 if (!isa<CallExpr>(SrcExpr.
get()))
2214 Self.
Diag(SrcExpr.
get()->getExprLoc(),
2215 diag::warn_bad_function_cast)
2216 << SrcType << DestType << SrcExpr.
get()->getSourceRange();
2220 void CastOperation::CheckCStyleCast() {
2221 assert(!Self.getLangOpts().CPlusPlus);
2224 if (claimPlaceholder(BuiltinType::UnknownAny)) {
2225 SrcExpr = Self.checkUnknownAnyCast(DestRange, DestType,
2226 SrcExpr.get(),
Kind,
2227 ValueKind, BasePath);
2235 SrcExpr = Self.IgnoredValueConversions(SrcExpr.get());
2236 if (SrcExpr.isInvalid())
2245 if (SrcExpr.get()->getType() == Self.Context.OverloadTy) {
2247 if (
FunctionDecl *FD = Self.ResolveAddressOfOverloadedFunction(
2248 SrcExpr.get(), DestType,
true, DAP))
2249 SrcExpr = Self.FixOverloadedFunctionReference(SrcExpr.get(), DAP, FD);
2252 assert(SrcExpr.isUsable());
2254 SrcExpr = Self.DefaultFunctionArrayLvalueConversion(SrcExpr.get());
2255 if (SrcExpr.isInvalid())
2257 QualType SrcType = SrcExpr.get()->getType();
2263 if (Self.getLangOpts().OpenCL && DestType->
isPointerType() &&
2267 Self.Diag(OpRange.getBegin(),
2268 diag::err_typecheck_incompatible_address_space)
2270 << SrcExpr.get()->getSourceRange();
2276 if (Self.RequireCompleteType(OpRange.getBegin(), DestType,
2277 diag::err_typecheck_cast_to_incomplete)) {
2285 if (DestRecordTy && Self.Context.hasSameUnqualifiedType(DestType, SrcType)){
2287 Self.Diag(OpRange.getBegin(), diag::ext_typecheck_cast_nonscalar)
2288 << DestType << SrcExpr.get()->getSourceRange();
2298 Field != FieldEnd; ++Field) {
2299 if (Self.Context.hasSameUnqualifiedType(Field->getType(), SrcType) &&
2300 !Field->isUnnamedBitfield()) {
2301 Self.Diag(OpRange.getBegin(), diag::ext_typecheck_cast_to_union)
2302 << SrcExpr.get()->getSourceRange();
2306 if (Field == FieldEnd) {
2307 Self.Diag(OpRange.getBegin(), diag::err_typecheck_cast_to_union_no_type)
2308 << SrcType << SrcExpr.get()->getSourceRange();
2317 Self.Diag(OpRange.getBegin(), diag::err_typecheck_cond_expect_scalar)
2318 << DestType << SrcExpr.get()->getSourceRange();
2327 Self.Diag(SrcExpr.get()->getExprLoc(),
2328 diag::err_typecheck_expect_scalar_operand)
2329 << SrcType << SrcExpr.get()->getSourceRange();
2335 SrcExpr = Self.CheckExtVectorCast(OpRange, DestType, SrcExpr.get(),
Kind);
2343 SrcExpr = Self.prepareVectorSplat(DestType, SrcExpr.get());
2344 }
else if (Self.CheckVectorCast(OpRange, DestType, SrcType,
Kind)) {
2351 if (Self.CheckVectorCast(OpRange, SrcType, DestType,
Kind))
2361 if (isa<ObjCSelectorExpr>(SrcExpr.get())) {
2362 Self.Diag(SrcExpr.get()->getExprLoc(), diag::err_cast_selector_expr);
2371 Self.Diag(SrcExpr.get()->getExprLoc(),
2372 diag::err_cast_pointer_from_non_pointer_int)
2373 << SrcType << SrcExpr.get()->getSourceRange();
2382 Self.Diag(SrcExpr.get()->getLocStart(),
2383 diag::err_cast_pointer_to_non_pointer_int)
2384 << DestType << SrcExpr.get()->getSourceRange();
2390 if (Self.getLangOpts().OpenCL && !Self.getOpenCLOptions().cl_khr_fp16) {
2392 Self.Diag(SrcExpr.get()->getLocStart(), diag::err_opencl_cast_to_half)
2393 << DestType << SrcExpr.get()->getSourceRange();
2400 if (Self.getLangOpts().ObjCAutoRefCount) {
2402 if (SrcExpr.isInvalid())
2407 Qualifiers CastQuals = CastPtr->getPointeeType().getQualifiers();
2408 Qualifiers ExprQuals = ExprPtr->getPointeeType().getQualifiers();
2409 if (CastPtr->getPointeeType()->isObjCLifetimeType() &&
2410 ExprPtr->getPointeeType()->isObjCLifetimeType() &&
2412 Self.Diag(SrcExpr.get()->getLocStart(),
2413 diag::err_typecheck_incompatible_ownership)
2415 << SrcExpr.get()->getSourceRange();
2420 else if (!Self.CheckObjCARCUnavailableWeakConversion(DestType, SrcType)) {
2421 Self.Diag(SrcExpr.get()->getLocStart(),
2422 diag::err_arc_convesion_of_weak_unavailable)
2423 << 1 << SrcType << DestType << SrcExpr.get()->getSourceRange();
2431 Kind = Self.PrepareScalarCast(SrcExpr, DestType);
2432 if (SrcExpr.isInvalid())
2439 QualType TheOffendingSrcType, TheOffendingDestType;
2443 &TheOffendingSrcType, &TheOffendingDestType,
2444 &CastAwayQualifiers)) {
2445 int qualifiers = -1;
2448 }
else if (CastAwayQualifiers.
hasConst()) {
2454 if (qualifiers == -1)
2455 Self.Diag(SrcExpr.get()->getLocStart(), diag::warn_cast_qual2) <<
2456 SrcType << DestType;
2458 Self.Diag(SrcExpr.get()->getLocStart(), diag::warn_cast_qual) <<
2459 TheOffendingSrcType << TheOffendingDestType << qualifiers;
2467 CastOperation Op(*
this, CastTypeInfo->
getType(), CastExpr);
2469 Op.OpRange =
SourceRange(LPLoc, CastExpr->getLocEnd());
2472 Op.CheckCXXCStyleCast(
false,
2473 isa<InitListExpr>(CastExpr));
2475 Op.CheckCStyleCast();
2478 if (Op.SrcExpr.isInvalid())
2482 Op.ValueKind, Op.Kind, Op.SrcExpr.get(),
2483 &Op.BasePath, CastTypeInfo, LPLoc, RPLoc));
2490 assert(LPLoc.
isValid() &&
"List-initialization shouldn't get here.");
2491 CastOperation Op(*
this, CastTypeInfo->
getType(), CastExpr);
2493 Op.OpRange =
SourceRange(Op.DestRange.getBegin(), CastExpr->getLocEnd());
2495 Op.CheckCXXCStyleCast(
true,
false);
2496 if (Op.SrcExpr.isInvalid())
2499 auto *SubExpr = Op.SrcExpr.
get();
2500 if (
auto *BindExpr = dyn_cast<CXXBindTemporaryExpr>(SubExpr))
2501 SubExpr = BindExpr->getSubExpr();
2502 if (
auto *ConstructExpr = dyn_cast<CXXConstructExpr>(SubExpr))
2503 ConstructExpr->setParenOrBraceRange(
SourceRange(LPLoc, RPLoc));
2506 Op.ValueKind, CastTypeInfo, Op.Kind,
2507 Op.SrcExpr.get(), &Op.BasePath, LPLoc, RPLoc));
bool compatiblyIncludesObjCLifetime(Qualifiers other) const
Determines if these qualifiers compatibly include another set of qualifiers from the narrow perspecti...
Defines the clang::ASTContext interface.
SourceLocation getEnd() const
bool RequireNonAbstractType(SourceLocation Loc, QualType T, TypeDiagnoser &Diagnoser)
const RecordType * getDetectedVirtual() const
The virtual base discovered on the path (if we are merely detecting virtuals).
FunctionDecl - An instance of this class is created to represent a function declaration or definition...
bool isDerivedFrom(const CXXRecordDecl *Base) const
Determine whether this class is derived from the class Base.
static DiagnosticBuilder Diag(DiagnosticsEngine *Diags, const LangOptions &Features, FullSourceLoc TokLoc, const char *TokBegin, const char *TokRangeBegin, const char *TokRangeEnd, unsigned DiagID)
Produce a diagnostic highlighting some portion of a literal.
bool isNullPtrType() const
PointerType - C99 6.7.5.1 - Pointer Declarators.
bool isAtLeastAsQualifiedAs(QualType Other) const
Determine whether this type is at least as qualified as the other given type, requiring exact equalit...
A (possibly-)qualified type.
A cast other than a C-style cast.
bool isMemberPointerType() const
SourceRange getSourceRange() const LLVM_READONLY
Retrieve the source range covering the entirety of this nested-name-specifier.
QualType getNonLValueExprType(const ASTContext &Context) const
Determine the type of a (typically non-lvalue) expression with the specified result type...
QualType getQualifiedType(SplitQualType split) const
Un-split a SplitQualType.
const LangOptions & getLangOpts() const
bool isAnyCharacterType() const
Determine whether this type is any of the built-in character types.
static CXXDynamicCastExpr * Create(const ASTContext &Context, QualType T, ExprValueKind VK, CastKind Kind, Expr *Op, const CXXCastPath *Path, TypeSourceInfo *Written, SourceLocation L, SourceLocation RParenLoc, SourceRange AngleBrackets)
bool isRecordType() const
SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID)
Emit a diagnostic.
CK_ToUnion - The GCC cast-to-union extension.
static TryCastResult TryStaticCast(Sema &Self, ExprResult &SrcExpr, QualType DestType, Sema::CheckedConversionKind CCK, SourceRange OpRange, unsigned &msg, CastKind &Kind, CXXCastPath &BasePath, bool ListInitialization)
TryStaticCast - Check if a static cast can be performed, and do so if possible.
The cast method is appropriate and successful.
bool isVoidPointerType() const
bool isEnumeralType() const
std::string getAsString() const
QualType getPointeeType() const
static ExprValueKind getValueKindForType(QualType T)
getValueKindForType - Given a formal return or parameter type, give its value kind.
Overloading for a user-defined conversion failed.
Ambiguous candidates found.
CK_FloatingToIntegral - Floating point to integral.
bool isBooleanType() const
bool compatiblyIncludes(Qualifiers other) const
Determines if these qualifiers compatibly include another set.
A container of type source information.
bool isBlockPointerType() const
static CXXFunctionalCastExpr * Create(const ASTContext &Context, QualType T, ExprValueKind VK, TypeSourceInfo *Written, CastKind Kind, Expr *Op, const CXXCastPath *Path, SourceLocation LPLoc, SourceLocation RPLoc)
Represents a path from a specific derived class (which is not represented as part of the path) to a p...
Represents a prvalue temporary that is written into memory so that a reference can bind to it...
static InitializedEntity InitializeTemporary(QualType Type)
Create the initialization entity for a temporary.
CK_IntegralToFloating - Integral to floating point.
An Objective-C array/dictionary subscripting which reads an object or writes at the subscripted array...
CK_IntegralCast - A cast between integral types (other than to boolean).
Information about one declarator, including the parsed type information and the identifier.
void removeObjCLifetime()
DiagnosticsEngine & Diags
void clear()
Clear the base-paths results.
field_iterator field_begin() const
uint64_t getTypeSize(QualType T) const
Return the size of the specified (complete) type T, in bits.
CK_Dynamic - A C++ dynamic_cast.
CK_Dependent - A conversion which cannot yet be analyzed because either the expression or target type...
Defines the clang::Expr interface and subclasses for C++ expressions.
The collection of all-type qualifiers we support.
std::list< CXXBasePath >::const_iterator const_paths_iterator
Expr * FixOverloadedFunctionReference(Expr *E, DeclAccessPair FoundDecl, FunctionDecl *Fn)
FixOverloadedFunctionReference - E is an expression that refers to a C++ overloaded function (possibl...
RecordDecl - Represents a struct/union/class.
bool isScalarType() const
void setRecordingPaths(bool RP)
Specify whether we should be recording paths or not.
A vector component is an element or range of elements on a vector.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
The cast method is not applicable.
bool IsDerivedFrom(SourceLocation Loc, QualType Derived, QualType Base)
Determine whether the type Derived is a C++ class that is derived from the type Base.
bool isRecordingPaths() const
Whether we are recording paths.
bool isReferenceType() const
bool isCompleteDefinition() const
isCompleteDefinition - Return true if this decl has its body fully specified.
bool isAnyPointerType() const
const CXXRecordDecl * getPointeeCXXRecordDecl() const
If this is a pointer or reference to a RecordType, return the CXXRecordDecl that that type refers to...
CXXRecordDecl * getDefinition() const
unsigned getCVRQualifiers() const
bool hasSameType(QualType T1, QualType T2) const
Determine whether the given types T1 and T2 are equivalent.
CK_VectorSplat - A conversion from an arithmetic type to a vector of that element type...
static CharUnits Zero()
Zero - Construct a CharUnits quantity of zero.
QualType getTypeDeclType(const TypeDecl *Decl, const TypeDecl *PrevDecl=nullptr) const
Return the unique reference to the type for the specified type declaration.
bool hasSameUnqualifiedType(QualType T1, QualType T2) const
Determine whether the given types are equivalent after cvr-qualifiers have been removed.
void CheckExtraCXXDefaultArguments(Declarator &D)
CheckExtraCXXDefaultArguments - Check for any extra default arguments in the declarator, which is not a function declaration or definition and therefore is not permitted to have default arguments.
CK_PointerToIntegral - Pointer to integral.
CK_IntegralToPointer - Integral to pointer.
OverloadCandidateDisplayKind
An r-value expression (a pr-value in the C++11 taxonomy) produces a temporary value.
CK_IntegralToBoolean - Integral to boolean.
bool isCompleteType(SourceLocation Loc, QualType T)
An rvalue reference type, per C++11 [dcl.ref].
const TargetInfo & getTargetInfo() const
bool UnwrapSimilarPointerTypes(QualType &T1, QualType &T2)
UnwrapSimilarPointerTypes - If T1 and T2 are pointer types that may be similar (C++ 4...
const LangOptions & getLangOpts() const
CharUnits - This is an opaque type for sizes expressed in character units.
ReferenceCompareResult CompareReferenceRelationship(SourceLocation Loc, QualType T1, QualType T2, bool &DerivedToBase, bool &ObjCConversion, bool &ObjCLifetimeConversion)
CompareReferenceRelationship - Compare the two types T1 and T2 to determine whether they are referenc...
Succeeded, but refers to a deleted function.
CanProxy< U > getAs() const
Retrieve a canonical type pointer with a different static type, upcasting or downcasting as needed...
OverloadCandidateSet & getFailedCandidateSet()
Retrieve a reference to the candidate set when overload resolution fails.
const CXXRecordDecl * getParent() const
Returns the parent of this method declaration, which is the class in which this method is defined...
RecordDecl * getDecl() const
CheckedConversionKind
The kind of conversion being performed.
bool isUnsignedIntegerType() const
Return true if this is an integer type that is unsigned, according to C99 6.2.5p6 [which returns true...
static TryCastResult TryReinterpretCast(Sema &Self, ExprResult &SrcExpr, QualType DestType, bool CStyle, SourceRange OpRange, unsigned &msg, CastKind &Kind)
FunctionDecl * ResolveAddressOfOverloadedFunction(Expr *AddressOfExpr, QualType TargetType, bool Complain, DeclAccessPair &Found, bool *pHadMultipleCandidates=nullptr)
ResolveAddressOfOverloadedFunction - Try to resolve the address of an overloaded function (C++ [over...
ExprResult Perform(Sema &S, const InitializedEntity &Entity, const InitializationKind &Kind, MultiExprArg Args, QualType *ResultType=nullptr)
Perform the actual initialization of the given entity based on the computed initialization sequence...
const ASTRecordLayout & getASTRecordLayout(const RecordDecl *D) const
Get or compute information about the layout of the specified record (struct/union/class) D...
CastExpr - Base class for type casts, including both implicit casts (ImplicitCastExpr) and explicit c...
An ordinary object is located at an address in memory.
static bool UnwrapDissimilarPointerTypes(QualType &T1, QualType &T2)
UnwrapDissimilarPointerTypes - Like Sema::UnwrapSimilarPointerTypes, this removes one level of indire...
bool isExtVectorType() const
detail::InMemoryDirectory::const_iterator I
bool isMemberFunctionPointer() const
Returns true if the member type (i.e.
field_iterator field_end() const
CK_AnyPointerToBlockPointerCast - Casting any non-block pointer to a block pointer.
Sema - This implements semantic analysis and AST building for C.
CastKind
CastKind - The kind of operation required for a conversion.
static ImplicitCastExpr * Create(const ASTContext &Context, QualType T, CastKind Kind, Expr *Operand, const CXXCastPath *BasePath, ExprValueKind Cat)
static TryCastResult TryConstCast(Sema &Self, ExprResult &SrcExpr, QualType DestType, bool CStyle, unsigned &msg)
TryConstCast - See if a const_cast from source to destination is allowed, and perform it if it is...
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee...
bool isFunctionPointerType() const
bool isRealFloatingType() const
Floating point categories.
ASTRecordLayout - This class contains layout information for one RecordDecl, which is a struct/union/...
An Objective-C property is a logical field of an Objective-C object which is read and written via Obj...
bool isMicrosoft() const
Is this ABI an MSVC-compatible ABI?
QualType getPointeeType() const
Expr - This represents one expression.
static void diagnoseBadCast(Sema &S, unsigned msg, CastType castType, SourceRange opRange, Expr *src, QualType destType, bool listInitialization)
Diagnose a failed cast.
ExprValueKind
The categorization of expression values, currently following the C++11 scheme.
CK_BitCast - A conversion which causes a bit pattern of one type to be reinterpreted as a bit pattern...
static InitializationKind CreateFunctionalCast(SourceRange TypeRange, bool InitList)
Create a direct initialization for a functional cast.
NestedNameSpecifierLoc getQualifierLoc() const
Fetches the nested-name qualifier with source-location information, if one was given.
void BuildBasePathArray(const CXXBasePaths &Paths, CXXCastPath &BasePath)
static FindResult find(Expr *E)
Finds the overloaded expression in the given expression E of OverloadTy.
static CXXStaticCastExpr * Create(const ASTContext &Context, QualType T, ExprValueKind VK, CastKind K, Expr *Op, const CXXCastPath *Path, TypeSourceInfo *Written, SourceLocation L, SourceLocation RParenLoc, SourceRange AngleBrackets)
CharUnits getBaseClassOffset(const CXXRecordDecl *Base) const
getBaseClassOffset - Get the offset, in chars, for the given base class.
Overload resolution succeeded.
bool isFloatingType() const
ExprResult BuildCXXNamedCast(SourceLocation OpLoc, tok::TokenKind Kind, TypeSourceInfo *Ty, Expr *E, SourceRange AngleBrackets, SourceRange Parens)
static TryCastResult TryStaticImplicitCast(Sema &Self, ExprResult &SrcExpr, QualType DestType, Sema::CheckedConversionKind CCK, SourceRange OpRange, unsigned &msg, CastKind &Kind, bool ListInitialization)
TryStaticImplicitCast - Tests whether a conversion according to C++ 5.2.9p2 is valid: ...
bool RequireCompleteType(SourceLocation Loc, QualType T, TypeDiagnoser &Diagnoser)
Ensure that the type T is a complete type.
void NoteCandidates(Sema &S, OverloadCandidateDisplayKind OCD, ArrayRef< Expr * > Args, StringRef Opc="", SourceLocation Loc=SourceLocation())
PrintOverloadCandidates - When overload resolution fails, prints diagnostic messages containing the c...
bool isDependentType() const
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
CK_ConstructorConversion - Conversion by constructor.
static TryCastResult TryStaticMemberPointerUpcast(Sema &Self, ExprResult &SrcExpr, QualType SrcType, QualType DestType, bool CStyle, SourceRange OpRange, unsigned &msg, CastKind &Kind, CXXCastPath &BasePath)
TryStaticMemberPointerUpcast - Tests whether a conversion according to C++ 5.2.9p9 is valid: ...
bool ResolveAndFixSingleFunctionTemplateSpecialization(ExprResult &SrcExpr, bool DoFunctionPointerConverion=false, bool Complain=false, SourceRange OpRangeForComplaining=SourceRange(), QualType DestTypeForComplaining=QualType(), unsigned DiagIDForComplaining=0)
bool isAtLeastAsQualifiedAs(CanQual< T > Other) const
Determines whether this canonical type is at least as qualified as the Other canonical type...
Represents a GCC generic vector type.
static TryCastResult TryStaticReferenceDowncast(Sema &Self, Expr *SrcExpr, QualType DestType, bool CStyle, SourceRange OpRange, unsigned &msg, CastKind &Kind, CXXCastPath &BasePath)
Tests whether a conversion according to C++ 5.2.9p5 is valid.
FailureKind getFailureKind() const
Determine why initialization failed.
bool CheckTollFreeBridgeStaticCast(QualType castType, Expr *castExpr, CastKind &Kind)
bool isComplexIntegerType() const
The result type of a method or function.
RecordDecl * getDefinition() const
getDefinition - Returns the RecordDecl that actually defines this struct/union/class.
void removeCVRQualifiers(unsigned mask)
TypeSourceInfo * GetTypeForDeclaratorCast(Declarator &D, QualType FromTy)
ExprResult BuildCStyleCastExpr(SourceLocation LParenLoc, TypeSourceInfo *Ty, SourceLocation RParenLoc, Expr *Op)
bool areLaxCompatibleVectorTypes(QualType srcType, QualType destType)
Are the two types lax-compatible vector types? That is, given that one of them is a vector...
CK_CPointerToObjCPointerCast - Casting a C pointer kind to an Objective-C pointer.
static TryCastResult TryStaticDowncast(Sema &Self, CanQualType SrcType, CanQualType DestType, bool CStyle, SourceRange OpRange, QualType OrigSrcType, QualType OrigDestType, unsigned &msg, CastKind &Kind, CXXCastPath &BasePath)
TryStaticDowncast - Common functionality of TryStaticReferenceDowncast and TryStaticPointerDowncast.
TypeLoc getTypeLoc() const
Return the TypeLoc wrapper for the type source info.
static CXXConstCastExpr * Create(const ASTContext &Context, QualType T, ExprValueKind VK, Expr *Op, TypeSourceInfo *WrittenTy, SourceLocation L, SourceLocation RParenLoc, SourceRange AngleBrackets)
A reference to an overloaded function set, either an UnresolvedLookupExpr or an UnresolvedMemberExpr...
bool isIntegralOrEnumerationType() const
Determine whether this type is an integral or enumeration type.
ActionResult - This structure is used while parsing/acting on expressions, stmts, etc...
Encodes a location in the source.
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of enums...
CastKind PrepareCastToObjCObjectPointer(ExprResult &E)
Prepare a conversion of the given expression to an ObjC object pointer type.
static TryCastResult TryStaticPointerDowncast(Sema &Self, QualType SrcType, QualType DestType, bool CStyle, SourceRange OpRange, unsigned &msg, CastKind &Kind, CXXCastPath &BasePath)
Tests whether a conversion according to C++ 5.2.9p8 is valid.
bool isComplexType() const
isComplexType() does not include complex integers (a GCC extension).
bool isValid() const
Return true if this is a valid SourceLocation object.
Represents a static or instance method of a struct/union/class.
CK_ReinterpretMemberPointer - Reinterpret a member pointer as a different kind of member pointer...
ExprResult ActOnCXXNamedCast(SourceLocation OpLoc, tok::TokenKind Kind, SourceLocation LAngleBracketLoc, Declarator &D, SourceLocation RAngleBracketLoc, SourceLocation LParenLoc, Expr *E, SourceLocation RParenLoc)
ActOnCXXNamedCast - Parse {dynamic,static,reinterpret,const}_cast's.
CK_DerivedToBase - A conversion from a C++ class pointer to a base class pointer. ...
std::string getAmbiguousPathsDisplayString(CXXBasePaths &Paths)
Builds a string representing ambiguous paths from a specific derived class to different subobjects of...
Ref_Compatible_With_Added_Qualification - The two types are reference-compatible with added qualifica...
bool isIntegerConstantExpr(llvm::APSInt &Result, const ASTContext &Ctx, SourceLocation *Loc=nullptr, bool isEvaluated=true) const
isIntegerConstantExpr - Return true if this expression is a valid integer constant expression...
Represents a canonical, potentially-qualified type.
TokenKind
Provides a simple uniform namespace for tokens from all C languages.
Describes the kind of initialization being performed, along with location information for tokens rela...
Overloading for initialization by constructor failed.
SourceLocation getBegin() const
Requests that all candidates be shown.
bool isTypeDependent() const
isTypeDependent - Determines whether this expression is type-dependent (C++ [temp.dep.expr]), which means that its type could change from one template instantiation to the next.
bool isVectorType() const
bool isMemberFunctionPointerType() const
OverloadCandidateSet - A set of overload candidates, used in C++ overload resolution (C++ 13...
bool isIgnored(unsigned DiagID, SourceLocation Loc) const
Determine whether the diagnostic is known to be ignored.
QualType getType() const
Return the type wrapped by this type source info.
static InitializationKind CreateCast(SourceRange TypeRange)
Create a direct initialization due to a cast that isn't a C-style or functional cast.
static CXXReinterpretCastExpr * Create(const ASTContext &Context, QualType T, ExprValueKind VK, CastKind Kind, Expr *Op, const CXXCastPath *Path, TypeSourceInfo *WrittenTy, SourceLocation L, SourceLocation RParenLoc, SourceRange AngleBrackets)
QualType getPointeeType() const
A POD class for pairing a NamedDecl* with an access specifier.
QualType getMemberPointerType(QualType T, const Type *Cls) const
Return the uniqued reference to the type for a member pointer to the specified type in the specified ...
bool isZero() const
isZero - Test whether the quantity equals zero.
bool isInvalidDecl() const
CK_BaseToDerived - A conversion from a C++ class pointer/reference to a derived class pointer/referen...
void CheckCompatibleReinterpretCast(QualType SrcType, QualType DestType, bool IsDereference, SourceRange Range)
The cast method is appropriate, but failed.
QualType getPointerType(QualType T) const
Return the uniqued reference to the type for a pointer to the specified type.
bool isLValue() const
isLValue - True if this expression is an "l-value" according to the rules of the current language...
static void checkIntToPointerCast(bool CStyle, SourceLocation Loc, const Expr *SrcExpr, QualType DestType, Sema &Self)
Requests that only viable candidates be shown.
detail::InMemoryDirectory::const_iterator E
bool isAmbiguous(CanQualType BaseType)
Determine whether the path from the most-derived type to the given base type is ambiguous (i...
A pointer to member type per C++ 8.3.3 - Pointers to members.
ExprResult BuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo, SourceLocation LParenLoc, Expr *CastExpr, SourceLocation RParenLoc)
void setCVRQualifiers(unsigned mask)
static InitializationKind CreateCStyleCast(SourceLocation StartLoc, SourceRange TypeRange, bool InitList)
Create a direct initialization for a C-style cast.
CanQualType getCanonicalType(QualType T) const
Return the canonical (structural) type corresponding to the specified potentially non-canonical type ...
static void DiagnoseCastOfObjCSEL(Sema &Self, const ExprResult &SrcExpr, QualType DestType)
specific_decl_iterator - Iterates over a subrange of declarations stored in a DeclContext, providing only those that are of type SpecificDecl (or a class derived from it).
bool isRValueReferenceType() const
QualType getPointeeType() const
Gets the type pointed to by this ObjC pointer.
Represents a pointer to an Objective C object.
SourceRange getSourceRange() const LLVM_READONLY
Get the full source range.
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
static bool tryDiagnoseOverloadedCast(Sema &S, CastType CT, SourceRange range, Expr *src, QualType destType, bool listInitialization)
Try to diagnose a failed overloaded cast.
const T * getAs() const
Member-template getAs<specific type>'.
bool isAddressSpaceOverlapping(const PointerType &other) const
Returns true if address spaces of pointers overlap.
QualType getCanonicalType() const
static CStyleCastExpr * Create(const ASTContext &Context, QualType T, ExprValueKind VK, CastKind K, Expr *Op, const CXXCastPath *BasePath, TypeSourceInfo *WrittenTy, SourceLocation L, SourceLocation R)
bool isFunctionType() const
CK_LValueBitCast - A conversion which reinterprets the address of an l-value as an l-value of a diffe...
Base for LValueReferenceType and RValueReferenceType.
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
static bool CastsAwayConstness(Sema &Self, QualType SrcType, QualType DestType, bool CheckCVR, bool CheckObjCLifetime, QualType *TheOffendingSrcType=nullptr, QualType *TheOffendingDestType=nullptr, Qualifiers *CastAwayQualifiers=nullptr)
CastsAwayConstness - Check if the pointer conversion from SrcType to DestType casts away constness as...
static TryCastResult TryLValueToRValueCast(Sema &Self, Expr *SrcExpr, QualType DestType, bool CStyle, CastKind &Kind, CXXCastPath &BasePath, unsigned &msg)
Tests whether a conversion according to N2844 is valid.
Implements a partial diagnostic that can be emitted anwyhere in a DiagnosticBuilder stream...
A bitfield object is a bitfield on a C or C++ record.
QualType getPointeeType() const
OverloadingResult getFailedOverloadResult() const
Get the overloading result, for when the initialization sequence failed due to a bad overload...
const Type * getClass() const
const internal::VariadicDynCastAllOfMatcher< Stmt, CastExpr > castExpr
Matches any cast nodes of Clang's AST.
bool Failed() const
Determine whether the initialization sequence is invalid.
Describes the sequence of initializations required to initialize a given object or reference with a s...
QualType getUnqualifiedType() const
Retrieve the unqualified variant of the given type, removing as little sugar as possible.
Represents a C++ struct/union/class.
TargetCXXABI getCXXABI() const
Get the C++ ABI currently in use.
bool isObjCObjectPointerType() const
bool isPlaceholderType() const
Test for a type which does not represent an actual type-system type but is instead used as a placehol...
AccessResult CheckBaseClassAccess(SourceLocation AccessLoc, QualType Base, QualType Derived, const CXXBasePath &Path, unsigned DiagID, bool ForceCheck=false, bool ForceUnprivileged=false)
Checks access for a hierarchy conversion.
static FixItHint CreateReplacement(CharSourceRange RemoveRange, StringRef Code)
Create a code modification hint that replaces the given source range with the given code string...
This class is used for builtin types like 'int'.
Defines the clang::TargetInfo interface.
DeclarationName getName() const
Gets the name looked up.
bool IsQualificationConversion(QualType FromType, QualType ToType, bool CStyle, bool &ObjCLifetimeConversion)
IsQualificationConversion - Determines whether the conversion from an rvalue of type FromType to ToTy...
static void DiagnoseBadFunctionCast(Sema &Self, const ExprResult &SrcExpr, QualType DestType)
DiagnoseBadFunctionCast - Warn whenever a function call is cast to a non-matching type...
CK_NoOp - A conversion which does not affect the type other than (possibly) adding qualifiers...
ExprValueKind getValueKind() const
getValueKind - The value kind that this expression produces.
CK_DerivedToBaseMemberPointer - Member pointer in derived class to member pointer in base class...
BasePaths - Represents the set of paths from a derived class to one of its (direct or indirect) bases...
No viable function found.
bool isConstructorInitialization() const
Determine whether this initialization is direct call to a constructor.
A trivial tuple used to represent a source range.
bool isInvalidType() const
bool isArithmeticType() const
bool isSignedIntegerType() const
Return true if this is an integer type that is signed, according to C99 6.2.5p4 [char, signed char, short, int, long..], or an enum decl which has a signed representation.
Describes an entity that is being initialized.
CK_ToVoid - Cast to void, discarding the computed value.
bool isIntegralType(ASTContext &Ctx) const
Determine whether this type is an integral type.
std::list< CXXBasePath >::iterator paths_iterator
QualType getUnqualifiedArrayType(QualType T, Qualifiers &Quals)
Return this type as a completely-unqualified array type, capturing the qualifiers in Quals...
static void DiagnoseReinterpretUpDownCast(Sema &Self, const Expr *SrcExpr, QualType DestType, SourceRange OpRange)
Check that a reinterpret_cast<DestType>(SrcExpr) is not used as upcast or downcast between respective...
bool isIntegerType() const
isIntegerType() does not include complex integers (a GCC extension).
Qualifiers getQualifiers() const
Retrieve the set of qualifiers applied to this type.
bool isPointerType() const
bool isIncompleteOrObjectType() const
Return true if this is an incomplete or object type, in other words, not a function type...