27 #include "llvm/ADT/SmallVector.h"
29 using namespace clang;
50 struct CastOperation {
52 : Self(S), SrcExpr(src), DestType(destType),
55 Kind(CK_Dependent), IsARCUnbridgedCast(
false) {
58 src.
get()->getType()->getAsPlaceholderType()) {
59 PlaceholderKind = placeholder->getKind();
73 bool IsARCUnbridgedCast;
79 void CheckConstCast();
80 void CheckReinterpretCast();
81 void CheckStaticCast();
82 void CheckDynamicCast();
83 void CheckCXXCStyleCast(
bool FunctionalCast,
bool ListInitialization);
84 void CheckCStyleCast();
91 if (IsARCUnbridgedCast) {
93 Self.Context.ARCUnbridgedCastTy,
94 CK_Dependent, castExpr,
nullptr,
106 if (PlaceholderKind != K)
return false;
112 bool isPlaceholder()
const {
113 return PlaceholderKind != 0;
116 return PlaceholderKind == K;
119 void checkCastAlign() {
120 Self.CheckCastAlign(SrcExpr.get(), DestType, OpRange);
124 assert(Self.getLangOpts().ObjCAutoRefCount);
127 if (Self.CheckObjCARCConversion(OpRange, DestType, src, CCK) ==
129 IsARCUnbridgedCast =
true;
134 void checkNonOverloadPlaceholders() {
135 if (!isPlaceholder() || isPlaceholder(BuiltinType::Overload))
138 SrcExpr = Self.CheckPlaceholderExpr(SrcExpr.get());
139 if (SrcExpr.isInvalid())
178 QualType OrigDestType,
unsigned &msg,
194 bool ListInitialization);
201 bool ListInitialization);
247 CastOperation Op(*
this, DestType, E);
249 Op.DestRange = AngleBrackets;
252 default: llvm_unreachable(
"Unknown C++ cast!");
254 case tok::kw_const_cast:
255 if (!TypeDependent) {
257 if (Op.SrcExpr.isInvalid())
261 Op.ValueKind, Op.SrcExpr.get(), DestTInfo,
265 case tok::kw_dynamic_cast: {
266 if (!TypeDependent) {
267 Op.CheckDynamicCast();
268 if (Op.SrcExpr.isInvalid())
272 Op.ValueKind, Op.Kind, Op.SrcExpr.get(),
273 &Op.BasePath, DestTInfo,
277 case tok::kw_reinterpret_cast: {
278 if (!TypeDependent) {
279 Op.CheckReinterpretCast();
280 if (Op.SrcExpr.isInvalid())
284 Op.ValueKind, Op.Kind, Op.SrcExpr.get(),
285 nullptr, DestTInfo, OpLoc,
289 case tok::kw_static_cast: {
290 if (!TypeDependent) {
291 Op.CheckStaticCast();
292 if (Op.SrcExpr.isInvalid())
297 Op.ValueKind, Op.Kind, Op.SrcExpr.get(),
298 &Op.BasePath, DestTInfo,
310 bool listInitialization) {
332 range, listInitialization)
338 assert(sequence.
Failed() &&
"initialization succeeded on second try?");
340 default:
return false;
353 case OR_Success: llvm_unreachable(
"successful failed overload");
355 if (candidates.
empty())
356 msg = diag::err_ovl_no_conversion_in_cast;
358 msg = diag::err_ovl_no_viable_conversion_in_cast;
363 msg = diag::err_ovl_ambiguous_conversion_in_cast;
368 msg = diag::err_ovl_deleted_conversion_in_cast;
374 << CT << srcType << destType
375 << range << src->getSourceRange();
385 bool listInitialization) {
386 if (msg == diag::err_bad_cxx_cast_generic &&
392 << src->
getType() << destType << opRange << src->getSourceRange();
395 int DifferentPtrness = 0;
406 if (!DifferentPtrness) {
409 if (RecFrom && RecTo) {
411 if (!DeclFrom->isCompleteDefinition())
412 S.
Diag(DeclFrom->getLocation(), diag::note_type_incomplete)
413 << DeclFrom->getDeclName();
415 if (!DeclTo->isCompleteDefinition())
416 S.
Diag(DeclTo->getLocation(), diag::note_type_incomplete)
417 << DeclTo->getDeclName();
430 if (T1PtrType && T2PtrType) {
445 else if (T2PtrType) {
451 else if (T2ObjCPtrType) {
461 if (T1MPType && T2MPType) {
469 if (T1BPType && T2BPType) {
488 bool CheckCVR,
bool CheckObjCLifetime,
489 QualType *TheOffendingSrcType =
nullptr,
490 QualType *TheOffendingDestType =
nullptr,
494 if (!CheckCVR && CheckObjCLifetime &&
504 "Source type is not pointer or pointer to member.");
507 "Destination type is not pointer or pointer to member.");
516 QualType PrevUnwrappedSrcType = UnwrappedSrcType;
517 QualType PrevUnwrappedDestType = UnwrappedDestType;
524 Qualifiers RetainedSrcQuals, RetainedDestQuals;
529 if (RetainedSrcQuals != RetainedDestQuals && TheOffendingSrcType &&
530 TheOffendingDestType && CastAwayQualifiers) {
531 *TheOffendingSrcType = PrevUnwrappedSrcType;
532 *TheOffendingDestType = PrevUnwrappedDestType;
533 *CastAwayQualifiers = RetainedSrcQuals - RetainedDestQuals;
537 if (CheckObjCLifetime &&
541 cv1.push_back(RetainedSrcQuals);
542 cv2.push_back(RetainedDestQuals);
544 PrevUnwrappedSrcType = UnwrappedSrcType;
545 PrevUnwrappedDestType = UnwrappedDestType;
557 i1 != cv1.rend(); ++i1, ++i2) {
565 bool ObjCLifetimeConversion;
566 return SrcConstruct != DestConstruct &&
568 ObjCLifetimeConversion);
574 void CastOperation::CheckDynamicCast() {
576 SrcExpr = Self.DefaultFunctionArrayLvalueConversion(SrcExpr.get());
577 else if (isPlaceholder())
578 SrcExpr = Self.CheckPlaceholderExpr(SrcExpr.get());
579 if (SrcExpr.isInvalid())
582 QualType OrigSrcType = SrcExpr.get()->getType();
596 Self.Diag(OpRange.getBegin(), diag::err_bad_dynamic_cast_not_ref_or_ptr)
597 << this->DestType << DestRange;
604 assert(DestPointer &&
"Reference to void is not possible");
605 }
else if (DestRecord) {
606 if (Self.RequireCompleteType(OpRange.getBegin(), DestPointee,
607 diag::err_bad_dynamic_cast_incomplete,
613 Self.Diag(OpRange.getBegin(), diag::err_bad_dynamic_cast_not_class)
629 Self.Diag(OpRange.getBegin(), diag::err_bad_dynamic_cast_not_ptr)
630 << OrigSrcType << SrcExpr.get()->getSourceRange();
634 }
else if (DestReference->isLValueReferenceType()) {
635 if (!SrcExpr.get()->isLValue()) {
636 Self.Diag(OpRange.getBegin(), diag::err_bad_cxx_cast_rvalue)
637 <<
CT_Dynamic << OrigSrcType << this->DestType << OpRange;
639 SrcPointee = SrcType;
643 if (SrcExpr.get()->isRValue())
644 SrcExpr = Self.CreateMaterializeTemporaryExpr(
645 SrcType, SrcExpr.get(),
false);
646 SrcPointee = SrcType;
651 if (Self.RequireCompleteType(OpRange.getBegin(), SrcPointee,
652 diag::err_bad_dynamic_cast_incomplete,
658 Self.Diag(OpRange.getBegin(), diag::err_bad_dynamic_cast_not_class)
664 assert((DestPointer || DestReference) &&
665 "Bad destination non-ptr/ref slipped through.");
666 assert((DestRecord || DestPointee->
isVoidType()) &&
667 "Bad destination pointee slipped through.");
668 assert(SrcRecord &&
"Bad source pointee slipped through.");
672 Self.Diag(OpRange.getBegin(), diag::err_bad_cxx_cast_qualifiers_away)
673 <<
CT_Dynamic << OrigSrcType << this->DestType << OpRange;
680 if (DestRecord == SrcRecord) {
688 Self.IsDerivedFrom(OpRange.getBegin(), SrcPointee, DestPointee)) {
689 if (Self.CheckDerivedToBaseConversion(SrcPointee, DestPointee,
690 OpRange.getBegin(), OpRange,
696 Kind = CK_DerivedToBase;
702 assert(SrcDecl &&
"Definition missing");
703 if (!cast<CXXRecordDecl>(SrcDecl)->isPolymorphic()) {
704 Self.Diag(OpRange.getBegin(), diag::err_bad_dynamic_cast_not_polymorphic)
712 if (!Self.getLangOpts().RTTI && !DestPointee->
isVoidType()) {
713 Self.Diag(OpRange.getBegin(), diag::err_no_dynamic_cast_with_fno_rtti);
727 void CastOperation::CheckConstCast() {
729 SrcExpr = Self.DefaultFunctionArrayLvalueConversion(SrcExpr.get());
730 else if (isPlaceholder())
731 SrcExpr = Self.CheckPlaceholderExpr(SrcExpr.get());
732 if (SrcExpr.isInvalid())
735 unsigned msg = diag::err_bad_cxx_cast_generic;
738 Self.Diag(OpRange.getBegin(), msg) <<
CT_Const
739 << SrcExpr.get()->getType() << DestType << OpRange;
775 ReinterpretKind = ReinterpretUpcast;
777 ReinterpretKind = ReinterpretDowncast;
781 bool VirtualBase =
true;
782 bool NonZeroOffset =
false;
788 bool IsVirtual =
false;
789 for (CXXBasePath::const_iterator IElem = Path.begin(), EElem = Path.end();
790 IElem != EElem; ++IElem) {
791 IsVirtual = IElem->Base->isVirtual();
794 const CXXRecordDecl *BaseRD = IElem->Base->getType()->getAsCXXRecordDecl();
795 assert(BaseRD &&
"Base type should be a valid unqualified class type");
800 if (Class->isInvalidDecl() || !ClassDefinition ||
814 NonZeroOffset =
true;
816 VirtualBase = VirtualBase && IsVirtual;
819 (void) NonZeroOffset;
820 assert((VirtualBase || NonZeroOffset) &&
821 "Should have returned if has non-virtual base with zero offset");
824 ReinterpretKind == ReinterpretUpcast? DestType : SrcType;
826 ReinterpretKind == ReinterpretUpcast? SrcType : DestType;
829 Self.
Diag(BeginLoc, diag::warn_reinterpret_different_from_static)
830 << DerivedType << BaseType << !VirtualBase << int(ReinterpretKind)
832 Self.
Diag(BeginLoc, diag::note_reinterpret_updowncast_use_static)
833 << int(ReinterpretKind)
842 void CastOperation::CheckReinterpretCast() {
843 if (ValueKind ==
VK_RValue && !isPlaceholder(BuiltinType::Overload))
844 SrcExpr = Self.DefaultFunctionArrayLvalueConversion(SrcExpr.get());
846 checkNonOverloadPlaceholders();
847 if (SrcExpr.isInvalid())
850 unsigned msg = diag::err_bad_cxx_cast_generic;
853 false, OpRange, msg,
Kind);
856 if (SrcExpr.isInvalid())
858 if (SrcExpr.get()->getType() == Self.Context.OverloadTy) {
860 Self.Diag(OpRange.getBegin(), diag::err_bad_reinterpret_cast_overload)
862 << DestType << OpRange;
863 Self.NoteAllOverloadCandidates(SrcExpr.get());
871 if (Self.getLangOpts().ObjCAutoRefCount)
881 void CastOperation::CheckStaticCast() {
882 if (isPlaceholder()) {
883 checkNonOverloadPlaceholders();
884 if (SrcExpr.isInvalid())
894 if (claimPlaceholder(BuiltinType::Overload)) {
895 Self.ResolveAndFixSingleFunctionTemplateSpecialization(SrcExpr,
898 OpRange, DestType, diag::err_bad_static_cast_overload);
899 if (SrcExpr.isInvalid())
903 SrcExpr = Self.IgnoredValueConversions(SrcExpr.get());
908 !isPlaceholder(BuiltinType::Overload)) {
909 SrcExpr = Self.DefaultFunctionArrayLvalueConversion(SrcExpr.get());
910 if (SrcExpr.isInvalid())
914 unsigned msg = diag::err_bad_cxx_cast_generic;
917 Kind, BasePath,
false);
919 if (SrcExpr.isInvalid())
921 if (SrcExpr.get()->getType() == Self.Context.OverloadTy) {
923 Self.Diag(OpRange.getBegin(), diag::err_bad_static_cast_overload)
924 << oe->
getName() << DestType << OpRange
926 Self.NoteAllOverloadCandidates(SrcExpr.get());
933 if (
Kind == CK_BitCast)
935 if (Self.getLangOpts().ObjCAutoRefCount)
937 }
else if (
Kind == CK_BitCast) {
950 bool ListInitialization) {
976 OpRange, msg,
Kind, BasePath);
991 Kind, ListInitialization);
1011 if (Enum->getDecl()->isScoped()) {
1013 Kind = CK_IntegralToBoolean;
1016 Kind = CK_IntegralCast;
1019 Kind = CK_IntegralToFloating;
1035 Kind = CK_IntegralCast;
1038 Kind = CK_FloatingToIntegral;
1054 OpRange, msg, Kind, BasePath);
1077 if (DestPointeeQuals != SrcPointeeQuals &&
1079 msg = diag::err_bad_cxx_cast_qualifiers_away;
1091 Self.
Diag(OpRange.getBegin(), diag::ext_ms_cast_fn_obj) << OpRange;
1099 Kind = CK_CPointerToObjCPointerCast;
1104 Kind = CK_AnyPointerToBlockPointerCast;
1125 if (SrcPointer->getPointeeType()->getAs<
RecordType>() &&
1127 msg = diag::err_bad_cxx_cast_unrelated_class;
1152 bool ObjCConversion;
1153 bool ObjCLifetimeConversion;
1163 DerivedToBase, ObjCConversion,
1164 ObjCLifetimeConversion)
1168 msg = diag::err_bad_lvalue_to_rvalue_cast;
1172 if (DerivedToBase) {
1173 Kind = CK_DerivedToBase;
1203 if (!DestReference) {
1207 if (!RValueRef && !SrcExpr->
isLValue()) {
1209 msg = diag::err_bad_cxx_cast_rvalue;
1246 msg = diag::err_bad_static_cast_pointer_nonpointer;
1253 CStyle, OpRange, SrcType, DestType, msg, Kind,
1263 QualType OrigDestType,
unsigned &msg,
1301 msg = diag::err_bad_cxx_cast_qualifiers_away;
1305 if (Paths.
isAmbiguous(SrcType.getUnqualifiedType())) {
1315 std::string PathDisplayStr;
1316 std::set<unsigned> DisplayedPaths;
1318 if (DisplayedPaths.insert(Path.back().SubobjectNumber).second) {
1321 PathDisplayStr +=
"\n ";
1323 PathDisplayStr += PE.Base->getType().getAsString() +
" -> ";
1328 Self.
Diag(OpRange.
getBegin(), diag::err_ambiguous_base_to_derived_cast)
1331 << PathDisplayStr << OpRange;
1338 Self.
Diag(OpRange.
getBegin(), diag::err_static_downcast_via_virtual)
1339 << OrigSrcType << OrigDestType << VirtualBase << OpRange;
1348 diag::err_downcast_from_inaccessible_base)) {
1361 Kind = CK_BaseToDerived;
1382 bool WasOverloadedFunction =
false;
1391 WasOverloadedFunction =
true;
1397 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) {
1481 Kind = CK_DerivedToBaseMemberPointer;
1497 diag::err_bad_dynamic_cast_incomplete) ||
1499 diag::err_allocation_of_abstract_type)) {
1513 Expr *SrcExprRaw = SrcExpr.
get();
1533 Kind = CK_ConstructorConversion;
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)
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();
1737 const auto *SrcFTy =
1739 const auto *DstFTy =
1748 Expr *Src = SrcExpr.
get()->IgnoreParenImpCasts();
1749 if (
auto *UO = dyn_cast<UnaryOperator>(Src))
1750 if (UO->getOpcode() == UO_AddrOf)
1757 if (!FD || !FD->hasBody(Definition))
1765 FD->isVariadic(), FD->isCXXInstanceMember());
1766 if (DstCC == DefaultCC || SrcCC != DefaultCC)
1772 Self.
Diag(OpRange.
getBegin(), diag::warn_cast_calling_conv)
1773 << SrcCCName << DstCCName << OpRange;
1789 llvm::raw_svector_ostream OS(CCAttrText);
1792 OS <<
"__" << DstCCName;
1799 OS <<
"__attribute__((" << DstCCName <<
"))";
1800 AttrTokens.push_back(tok::kw___attribute);
1801 AttrTokens.push_back(tok::l_paren);
1802 AttrTokens.push_back(tok::l_paren);
1807 AttrTokens.push_back(tok::r_paren);
1808 AttrTokens.push_back(tok::r_paren);
1811 if (!AttrSpelling.empty())
1812 CCAttrText = AttrSpelling;
1814 Self.
Diag(NameLoc, diag::note_change_calling_conv_fixit)
1838 diag::warn_int_to_void_pointer_cast
1839 : diag::warn_int_to_pointer_cast;
1840 Self.
Diag(Loc, Diag) << SrcType << DestType;
1875 bool IsLValueCast =
false;
1887 assert(FixedExpr.
isUsable() &&
"Invalid result fixing overloaded expr");
1888 SrcExpr = FixedExpr;
1889 SrcType = SrcExpr.get()->getType();
1893 if (!SrcExpr.
get()->isGLValue()) {
1896 msg = diag::err_bad_cxx_cast_rvalue;
1909 const char *inappropriate =
nullptr;
1910 switch (SrcExpr.
get()->getObjectKind()) {
1913 case OK_BitField: inappropriate =
"bit-field";
break;
1916 case OK_ObjCSubscript: inappropriate =
"container subscripting expression";
1919 if (inappropriate) {
1920 Self.
Diag(OpRange.
getBegin(), diag::err_bad_reinterpret_cast_reference)
1921 << inappropriate << DestType
1922 << OpRange << SrcExpr.
get()->getSourceRange();
1931 IsLValueCast =
true;
1939 if (DestMemPtr && SrcMemPtr) {
1945 SrcMemPtr->isMemberFunctionPointer())
1954 msg = diag::err_bad_cxx_cast_qualifiers_away;
1968 msg = diag::err_bad_cxx_cast_member_pointer_size;
1973 assert(!IsLValueCast);
1974 Kind = CK_ReinterpretMemberPointer;
1986 msg = diag::err_bad_reinterpret_cast_small_int;
1989 Kind = CK_PointerToIntegral;
1997 if (srcIsVector || destIsVector) {
2014 msg = diag::err_bad_cxx_cast_vector_to_scalar_different_size;
2015 else if (!srcIsVector)
2016 msg = diag::err_bad_cxx_cast_scalar_to_vector_different_size;
2018 msg = diag::err_bad_cxx_cast_vector_to_vector_different_size;
2023 if (SrcType == DestType) {
2047 if (!destIsPtr && !srcIsPtr) {
2054 assert(srcIsPtr &&
"One type must be a pointer");
2058 bool MicrosoftException = Self.
getLangOpts().MicrosoftExt &&
2062 !MicrosoftException) {
2063 msg = diag::err_bad_reinterpret_cast_small_int;
2066 Kind = CK_PointerToIntegral;
2071 assert(destIsPtr &&
"One type must be a pointer");
2078 Kind = CK_IntegralToPointer;
2082 if (!destIsPtr || !srcIsPtr) {
2092 msg = diag::err_bad_cxx_cast_qualifiers_away;
2102 Kind = CK_LValueBitCast;
2107 Kind = CK_AnyPointerToBlockPointerCast;
2143 diag::warn_cxx98_compat_cast_fn_obj : diag::ext_cast_fn_obj)
2152 diag::warn_cxx98_compat_cast_fn_obj : diag::ext_cast_fn_obj)
2165 void CastOperation::CheckCXXCStyleCast(
bool FunctionalStyle,
2166 bool ListInitialization) {
2168 if (isPlaceholder()) {
2170 if (claimPlaceholder(BuiltinType::UnknownAny)) {
2171 SrcExpr = Self.checkUnknownAnyCast(DestRange, DestType,
2172 SrcExpr.get(),
Kind,
2173 ValueKind, BasePath);
2177 checkNonOverloadPlaceholders();
2178 if (SrcExpr.isInvalid())
2188 if (claimPlaceholder(BuiltinType::Overload)) {
2189 Self.ResolveAndFixSingleFunctionTemplateSpecialization(
2191 true, DestRange, DestType,
2192 diag::err_bad_cstyle_cast_overload);
2193 if (SrcExpr.isInvalid())
2197 SrcExpr = Self.IgnoredValueConversions(SrcExpr.get());
2202 if (DestType->
isDependentType() || SrcExpr.get()->isTypeDependent() ||
2203 SrcExpr.get()->isValueDependent()) {
2204 assert(
Kind == CK_Dependent);
2209 !isPlaceholder(BuiltinType::Overload)) {
2210 SrcExpr = Self.DefaultFunctionArrayLvalueConversion(SrcExpr.get());
2211 if (SrcExpr.isInvalid())
2218 && (SrcExpr.get()->getType()->isIntegerType()
2219 || SrcExpr.get()->getType()->isFloatingType())) {
2220 Kind = CK_VectorSplat;
2221 SrcExpr = Self.prepareVectorSplat(DestType, SrcExpr.get());
2236 unsigned msg = diag::err_bad_cxx_cast_generic;
2239 if (SrcExpr.isInvalid())
2250 msg,
Kind, BasePath, ListInitialization);
2251 if (SrcExpr.isInvalid())
2257 OpRange, msg,
Kind);
2258 if (SrcExpr.isInvalid())
2263 if (Self.getLangOpts().ObjCAutoRefCount && tcr ==
TC_Success)
2264 checkObjCARCConversion(CCK);
2267 if (SrcExpr.get()->getType() == Self.Context.OverloadTy) {
2269 FunctionDecl *Fn = Self.ResolveAddressOfOverloadedFunction(SrcExpr.get(),
2278 Self.Diag(OpRange.getBegin(), diag::err_bad_cstyle_cast_overload)
2279 << OE->
getName() << DestType << OpRange
2281 Self.NoteAllOverloadCandidates(SrcExpr.get());
2285 OpRange, SrcExpr.get(), DestType, ListInitialization);
2287 }
else if (
Kind == CK_BitCast) {
2302 SrcExpr.
get()->getExprLoc()))
2305 if (!isa<CallExpr>(SrcExpr.
get()))
2327 Self.
Diag(SrcExpr.
get()->getExprLoc(),
2328 diag::warn_bad_function_cast)
2329 << SrcType << DestType << SrcExpr.
get()->getSourceRange();
2333 void CastOperation::CheckCStyleCast() {
2334 assert(!Self.getLangOpts().CPlusPlus);
2337 if (claimPlaceholder(BuiltinType::UnknownAny)) {
2338 SrcExpr = Self.checkUnknownAnyCast(DestRange, DestType,
2339 SrcExpr.get(),
Kind,
2340 ValueKind, BasePath);
2348 SrcExpr = Self.IgnoredValueConversions(SrcExpr.get());
2349 if (SrcExpr.isInvalid())
2358 if (SrcExpr.get()->getType() == Self.Context.OverloadTy) {
2360 if (
FunctionDecl *FD = Self.ResolveAddressOfOverloadedFunction(
2361 SrcExpr.get(), DestType,
true, DAP))
2362 SrcExpr = Self.FixOverloadedFunctionReference(SrcExpr.get(), DAP, FD);
2365 assert(SrcExpr.isUsable());
2367 SrcExpr = Self.DefaultFunctionArrayLvalueConversion(SrcExpr.get());
2368 if (SrcExpr.isInvalid())
2370 QualType SrcType = SrcExpr.get()->getType();
2376 if (Self.getLangOpts().OpenCL && DestType->
isPointerType() &&
2380 Self.Diag(OpRange.getBegin(),
2381 diag::err_typecheck_incompatible_address_space)
2383 << SrcExpr.get()->getSourceRange();
2389 if (Self.RequireCompleteType(OpRange.getBegin(), DestType,
2390 diag::err_typecheck_cast_to_incomplete)) {
2398 if (DestRecordTy && Self.Context.hasSameUnqualifiedType(DestType, SrcType)){
2400 Self.Diag(OpRange.getBegin(), diag::ext_typecheck_cast_nonscalar)
2401 << DestType << SrcExpr.get()->getSourceRange();
2411 Field != FieldEnd; ++Field) {
2412 if (Self.Context.hasSameUnqualifiedType(Field->getType(), SrcType) &&
2413 !Field->isUnnamedBitfield()) {
2414 Self.Diag(OpRange.getBegin(), diag::ext_typecheck_cast_to_union)
2415 << SrcExpr.get()->getSourceRange();
2419 if (Field == FieldEnd) {
2420 Self.Diag(OpRange.getBegin(), diag::err_typecheck_cast_to_union_no_type)
2421 << SrcType << SrcExpr.get()->getSourceRange();
2430 if (Self.getLangOpts().OpenCL && DestType->
isEventT()) {
2431 llvm::APSInt CastInt;
2432 if (SrcExpr.get()->EvaluateAsInt(CastInt, Self.Context)) {
2434 Kind = CK_ZeroToOCLEvent;
2437 Self.Diag(OpRange.getBegin(),
2438 diag::error_opencl_cast_non_zero_to_event_t)
2439 << CastInt.toString(10) << SrcExpr.get()->getSourceRange();
2446 Self.Diag(OpRange.getBegin(), diag::err_typecheck_cond_expect_scalar)
2447 << DestType << SrcExpr.get()->getSourceRange();
2456 Self.Diag(SrcExpr.get()->getExprLoc(),
2457 diag::err_typecheck_expect_scalar_operand)
2458 << SrcType << SrcExpr.get()->getSourceRange();
2464 SrcExpr = Self.CheckExtVectorCast(OpRange, DestType, SrcExpr.get(),
Kind);
2471 Kind = CK_VectorSplat;
2472 SrcExpr = Self.prepareVectorSplat(DestType, SrcExpr.get());
2473 }
else if (Self.CheckVectorCast(OpRange, DestType, SrcType,
Kind)) {
2480 if (Self.CheckVectorCast(OpRange, SrcType, DestType,
Kind))
2490 if (isa<ObjCSelectorExpr>(SrcExpr.get())) {
2491 Self.Diag(SrcExpr.get()->getExprLoc(), diag::err_cast_selector_expr);
2500 Self.Diag(SrcExpr.get()->getExprLoc(),
2501 diag::err_cast_pointer_from_non_pointer_int)
2502 << SrcType << SrcExpr.get()->getSourceRange();
2511 Self.Diag(SrcExpr.get()->getLocStart(),
2512 diag::err_cast_pointer_to_non_pointer_int)
2513 << DestType << SrcExpr.get()->getSourceRange();
2519 if (Self.getLangOpts().OpenCL && !Self.getOpenCLOptions().cl_khr_fp16) {
2521 Self.Diag(SrcExpr.get()->getLocStart(), diag::err_opencl_cast_to_half)
2522 << DestType << SrcExpr.get()->getSourceRange();
2529 if (Self.getLangOpts().ObjCAutoRefCount) {
2531 if (SrcExpr.isInvalid())
2536 Qualifiers CastQuals = CastPtr->getPointeeType().getQualifiers();
2537 Qualifiers ExprQuals = ExprPtr->getPointeeType().getQualifiers();
2538 if (CastPtr->getPointeeType()->isObjCLifetimeType() &&
2539 ExprPtr->getPointeeType()->isObjCLifetimeType() &&
2541 Self.Diag(SrcExpr.get()->getLocStart(),
2542 diag::err_typecheck_incompatible_ownership)
2544 << SrcExpr.get()->getSourceRange();
2549 else if (!Self.CheckObjCARCUnavailableWeakConversion(DestType, SrcType)) {
2550 Self.Diag(SrcExpr.get()->getLocStart(),
2551 diag::err_arc_convesion_of_weak_unavailable)
2552 << 1 << SrcType << DestType << SrcExpr.get()->getSourceRange();
2561 Kind = Self.PrepareScalarCast(SrcExpr, DestType);
2562 if (SrcExpr.isInvalid())
2565 if (
Kind == CK_BitCast)
2569 QualType TheOffendingSrcType, TheOffendingDestType;
2573 &TheOffendingSrcType, &TheOffendingDestType,
2574 &CastAwayQualifiers)) {
2575 int qualifiers = -1;
2578 }
else if (CastAwayQualifiers.
hasConst()) {
2584 if (qualifiers == -1)
2585 Self.Diag(SrcExpr.get()->getLocStart(), diag::warn_cast_qual2) <<
2586 SrcType << DestType;
2588 Self.Diag(SrcExpr.get()->getLocStart(), diag::warn_cast_qual) <<
2589 TheOffendingSrcType << TheOffendingDestType << qualifiers;
2597 CastOperation Op(*
this, CastTypeInfo->
getType(), CastExpr);
2599 Op.OpRange =
SourceRange(LPLoc, CastExpr->getLocEnd());
2602 Op.CheckCXXCStyleCast(
false,
2603 isa<InitListExpr>(CastExpr));
2605 Op.CheckCStyleCast();
2608 if (Op.SrcExpr.isInvalid())
2612 Op.ValueKind, Op.Kind, Op.SrcExpr.get(),
2613 &Op.BasePath, CastTypeInfo, LPLoc, RPLoc));
2620 assert(LPLoc.
isValid() &&
"List-initialization shouldn't get here.");
2621 CastOperation Op(*
this, CastTypeInfo->
getType(), CastExpr);
2623 Op.OpRange =
SourceRange(Op.DestRange.getBegin(), CastExpr->getLocEnd());
2625 Op.CheckCXXCStyleCast(
true,
false);
2626 if (Op.SrcExpr.isInvalid())
2629 auto *SubExpr = Op.SrcExpr.
get();
2630 if (
auto *BindExpr = dyn_cast<CXXBindTemporaryExpr>(SubExpr))
2631 SubExpr = BindExpr->getSubExpr();
2632 if (
auto *ConstructExpr = dyn_cast<CXXConstructExpr>(SubExpr))
2633 ConstructExpr->setParenOrBraceRange(
SourceRange(LPLoc, RPLoc));
2636 Op.ValueKind, CastTypeInfo, Op.Kind,
2637 Op.SrcExpr.get(), &Op.BasePath, LPLoc, RPLoc));
StringRef getLastMacroWithSpelling(SourceLocation Loc, ArrayRef< TokenValue > Tokens) const
Return the name of the macro defined before Loc that has spelling Tokens.
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.
FunctionType - C99 6.7.5.3 - Function Declarators.
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)
IdentifierInfo * getIdentifierInfo(StringRef Name) const
Return information about the specified preprocessor identifier token.
bool isRecordType() const
SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID)
Emit a diagnostic.
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.
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...
static InitializedEntity InitializeTemporary(QualType Type)
Create the initialization entity for a temporary.
An Objective-C array/dictionary subscripting which reads an object or writes at the subscripted array...
Information about one declarator, including the parsed type information and the identifier.
void removeObjCLifetime()
DiagnosticsEngine & Diags
static void DiagnoseCallingConvCast(Sema &Self, const ExprResult &SrcExpr, QualType DstType, SourceRange OpRange)
Diagnose casts that change the calling convention of a pointer to a function defined in the current T...
void clear()
Clear the base-paths results.
CallingConv getCallConv() const
field_iterator field_begin() const
uint64_t getTypeSize(QualType T) const
Return the size of the specified (complete) type T, in bits.
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.
One of these records is kept for each identifier that is lexed.
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.
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.
OverloadCandidateDisplayKind
An r-value expression (a pr-value in the C++11 taxonomy) produces a temporary value.
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...
tok::TokenKind getTokenID() const
If this is a source-language token (e.g.
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
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.
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.
Defines the clang::Preprocessor interface.
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)
Stores token information for comparing actual tokens with predefined values.
bool resolveAndFixAddressOfOnlyViableOverloadCandidate(ExprResult &SrcExpr)
Given an overloaded function, tries to turn it into a non-overloaded function reference using resolve...
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...
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)
CallingConv
CallingConv - Specifies the calling convention that a function uses.
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...
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.
ASTContext & getASTContext() const
Represents a static or instance method of a struct/union/class.
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.
bool isKeyword(const LangOptions &LangOpts)
Return true if this token is a keyword in the specified language.
std::string getAmbiguousPathsDisplayString(CXXBasePaths &Paths)
Builds a string representing ambiguous paths from a specific derived class to different subobjects of...
bool isIntegralType(const ASTContext &Ctx) const
Determine whether this type is an integral type.
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.
const T * castAs() const
Member-template castAs<specific type>.
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.
Represents an element in a path from a derived class to a base class.
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.
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)
static bool fixOverloadedReinterpretCastExpr(Sema &Self, QualType DestType, ExprResult &Result)
specific_decl_iterator - Iterates over a subrange of declarations stored in a DeclContext, providing only those that are of type SpecificDecl (or a class derived from it).
Expr * IgnoreParenImpCasts() LLVM_READONLY
IgnoreParenImpCasts - Ignore parentheses and implicit casts.
bool isRValueReferenceType() const
QualType 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
MaterializeTemporaryExpr * CreateMaterializeTemporaryExpr(QualType T, Expr *Temporary, bool BoundToLvalueReference)
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.
static FixItHint CreateInsertion(SourceLocation InsertionLoc, StringRef Code, bool BeforePreviousInsertions=false)
Create a code modification hint that inserts the given code string at a specific location.
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...
CallingConv getDefaultCallingConvention(bool isVariadic, bool IsCXXMethod) const
Retrieves the default calling convention for the current target.
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...
A reference to a declared variable, function, enum, etc.
ExprValueKind getValueKind() const
getValueKind - The value kind that this expression produces.
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.
static StringRef getNameForCallConv(CallingConv CC)
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.
Preprocessor & getPreprocessor() const
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).
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
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...