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) {
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() {
129 IsARCUnbridgedCast =
true;
134 void checkNonOverloadPlaceholders() {
135 if (!isPlaceholder() || isPlaceholder(BuiltinType::Overload))
181 QualType OrigDestType,
unsigned &msg,
197 bool ListInitialization);
204 bool ListInitialization);
229 if (getLangOpts().CPlusPlus) {
231 CheckExtraCXXDefaultArguments(D);
234 return BuildCXXNamedCast(OpLoc, Kind, TInfo, E,
250 CastOperation Op(*
this, DestType, E);
252 Op.DestRange = AngleBrackets;
255 default: llvm_unreachable(
"Unknown C++ cast!");
257 case tok::kw_const_cast:
258 if (!TypeDependent) {
260 if (Op.SrcExpr.isInvalid())
262 DiscardMisalignedMemberAddress(DestType.
getTypePtr(), E);
265 Op.ValueKind, Op.SrcExpr.get(), DestTInfo,
269 case tok::kw_dynamic_cast: {
270 if (!TypeDependent) {
271 Op.CheckDynamicCast();
272 if (Op.SrcExpr.isInvalid())
276 Op.ValueKind, Op.Kind, Op.SrcExpr.get(),
277 &Op.BasePath, DestTInfo,
281 case tok::kw_reinterpret_cast: {
282 if (!TypeDependent) {
283 Op.CheckReinterpretCast();
284 if (Op.SrcExpr.isInvalid())
286 DiscardMisalignedMemberAddress(DestType.
getTypePtr(), E);
289 Op.ValueKind, Op.Kind, Op.SrcExpr.get(),
290 nullptr, DestTInfo, OpLoc,
294 case tok::kw_static_cast: {
295 if (!TypeDependent) {
296 Op.CheckStaticCast();
297 if (Op.SrcExpr.isInvalid())
299 DiscardMisalignedMemberAddress(DestType.
getTypePtr(), E);
303 Op.ValueKind, Op.Kind, Op.SrcExpr.get(),
304 &Op.BasePath, DestTInfo,
316 bool listInitialization) {
338 range, listInitialization)
344 assert(sequence.
Failed() &&
"initialization succeeded on second try?");
346 default:
return false;
359 case OR_Success: llvm_unreachable(
"successful failed overload");
361 if (candidates.
empty())
362 msg = diag::err_ovl_no_conversion_in_cast;
364 msg = diag::err_ovl_no_viable_conversion_in_cast;
369 msg = diag::err_ovl_ambiguous_conversion_in_cast;
374 msg = diag::err_ovl_deleted_conversion_in_cast;
380 << CT << srcType << destType
391 bool listInitialization) {
392 if (msg == diag::err_bad_cxx_cast_generic &&
401 int DifferentPtrness = 0;
412 if (!DifferentPtrness) {
415 if (RecFrom && RecTo) {
417 if (!DeclFrom->isCompleteDefinition())
418 S.
Diag(DeclFrom->getLocation(), diag::note_type_incomplete)
419 << DeclFrom->getDeclName();
421 if (!DeclTo->isCompleteDefinition())
422 S.
Diag(DeclTo->getLocation(), diag::note_type_incomplete)
423 << DeclTo->getDeclName();
440 if (T1PtrType && T2PtrType) {
455 else if (T2PtrType) {
461 else if (T2ObjCPtrType) {
471 if (T1MPType && T2MPType) {
479 if (T1BPType && T2BPType) {
487 if (T1RefType && T2RefType) {
518 bool CheckCVR,
bool CheckObjCLifetime,
519 QualType *TheOffendingSrcType =
nullptr,
520 QualType *TheOffendingDestType =
nullptr,
524 if (!CheckCVR && CheckObjCLifetime &&
535 "Source type is not pointer or pointer to member.");
539 "Destination type is not pointer or pointer to member, or reference.");
548 QualType PrevUnwrappedSrcType = UnwrappedSrcType;
549 QualType PrevUnwrappedDestType = UnwrappedDestType;
560 UnwrappedDestType->isObjCObjectType())
563 Qualifiers RetainedSrcQuals, RetainedDestQuals;
568 if (RetainedSrcQuals != RetainedDestQuals && TheOffendingSrcType &&
569 TheOffendingDestType && CastAwayQualifiers) {
570 *TheOffendingSrcType = PrevUnwrappedSrcType;
571 *TheOffendingDestType = PrevUnwrappedDestType;
572 *CastAwayQualifiers = RetainedSrcQuals - RetainedDestQuals;
576 if (CheckObjCLifetime &&
580 cv1.push_back(RetainedSrcQuals);
581 cv2.push_back(RetainedDestQuals);
583 PrevUnwrappedSrcType = UnwrappedSrcType;
584 PrevUnwrappedDestType = UnwrappedDestType;
596 i1 != cv1.rend(); ++i1, ++i2) {
604 bool ObjCLifetimeConversion;
605 return SrcConstruct != DestConstruct &&
607 ObjCLifetimeConversion);
613 void CastOperation::CheckDynamicCast() {
616 else if (isPlaceholder())
635 Self.
Diag(OpRange.
getBegin(), diag::err_bad_dynamic_cast_not_ref_or_ptr)
636 << this->DestType << DestRange;
643 assert(DestPointer &&
"Reference to void is not possible");
644 }
else if (DestRecord) {
646 diag::err_bad_dynamic_cast_incomplete,
652 Self.
Diag(OpRange.
getBegin(), diag::err_bad_dynamic_cast_not_class)
668 Self.
Diag(OpRange.
getBegin(), diag::err_bad_dynamic_cast_not_ptr)
669 << OrigSrcType << SrcExpr.
get()->getSourceRange();
673 }
else if (DestReference->isLValueReferenceType()) {
674 if (!SrcExpr.
get()->isLValue()) {
675 Self.
Diag(OpRange.
getBegin(), diag::err_bad_cxx_cast_rvalue)
676 <<
CT_Dynamic << OrigSrcType << this->DestType << OpRange;
678 SrcPointee = SrcType;
682 if (SrcExpr.
get()->isRValue())
684 SrcType, SrcExpr.
get(),
false);
685 SrcPointee = SrcType;
691 diag::err_bad_dynamic_cast_incomplete,
697 Self.
Diag(OpRange.
getBegin(), diag::err_bad_dynamic_cast_not_class)
703 assert((DestPointer || DestReference) &&
704 "Bad destination non-ptr/ref slipped through.");
705 assert((DestRecord || DestPointee->
isVoidType()) &&
706 "Bad destination pointee slipped through.");
707 assert(SrcRecord &&
"Bad source pointee slipped through.");
711 Self.
Diag(OpRange.
getBegin(), diag::err_bad_cxx_cast_qualifiers_away)
712 <<
CT_Dynamic << OrigSrcType << this->DestType << OpRange;
719 if (DestRecord == SrcRecord) {
735 Kind = CK_DerivedToBase;
741 assert(SrcDecl &&
"Definition missing");
742 if (!cast<CXXRecordDecl>(SrcDecl)->isPolymorphic()) {
743 Self.
Diag(OpRange.
getBegin(), diag::err_bad_dynamic_cast_not_polymorphic)
752 Self.
Diag(OpRange.
getBegin(), diag::err_no_dynamic_cast_with_fno_rtti);
766 void CastOperation::CheckConstCast() {
769 else if (isPlaceholder())
774 unsigned msg = diag::err_bad_cxx_cast_generic;
778 << SrcExpr.
get()->getType() << DestType << OpRange;
814 ReinterpretKind = ReinterpretUpcast;
816 ReinterpretKind = ReinterpretDowncast;
820 bool VirtualBase =
true;
821 bool NonZeroOffset =
false;
827 bool IsVirtual =
false;
828 for (CXXBasePath::const_iterator IElem = Path.begin(), EElem = Path.end();
829 IElem != EElem; ++IElem) {
830 IsVirtual = IElem->Base->isVirtual();
833 const CXXRecordDecl *BaseRD = IElem->Base->getType()->getAsCXXRecordDecl();
834 assert(BaseRD &&
"Base type should be a valid unqualified class type");
840 !ClassDefinition->isCompleteDefinition())
853 NonZeroOffset =
true;
855 VirtualBase = VirtualBase && IsVirtual;
858 (void) NonZeroOffset;
859 assert((VirtualBase || NonZeroOffset) &&
860 "Should have returned if has non-virtual base with zero offset");
863 ReinterpretKind == ReinterpretUpcast? DestType : SrcType;
865 ReinterpretKind == ReinterpretUpcast? SrcType : DestType;
868 Self.
Diag(BeginLoc, diag::warn_reinterpret_different_from_static)
869 << DerivedType << BaseType << !VirtualBase << int(ReinterpretKind)
871 Self.
Diag(BeginLoc, diag::note_reinterpret_updowncast_use_static)
872 << int(ReinterpretKind)
881 void CastOperation::CheckReinterpretCast() {
882 if (ValueKind ==
VK_RValue && !isPlaceholder(BuiltinType::Overload))
885 checkNonOverloadPlaceholders();
889 unsigned msg = diag::err_bad_cxx_cast_generic;
892 false, OpRange, msg,
Kind);
899 Self.
Diag(OpRange.
getBegin(), diag::err_bad_reinterpret_cast_overload)
901 << DestType << OpRange;
920 void CastOperation::CheckStaticCast() {
921 if (isPlaceholder()) {
922 checkNonOverloadPlaceholders();
933 if (claimPlaceholder(BuiltinType::Overload)) {
937 OpRange, DestType, diag::err_bad_static_cast_overload);
947 !isPlaceholder(BuiltinType::Overload)) {
953 unsigned msg = diag::err_bad_cxx_cast_generic;
956 Kind, BasePath,
false);
962 Self.
Diag(OpRange.
getBegin(), diag::err_bad_static_cast_overload)
963 << oe->
getName() << DestType << OpRange
972 if (
Kind == CK_BitCast)
976 }
else if (
Kind == CK_BitCast) {
989 bool ListInitialization) {
1015 OpRange, msg,
Kind, BasePath);
1030 Kind, ListInitialization);
1050 if (Enum->getDecl()->isScoped()) {
1052 Kind = CK_IntegralToBoolean;
1055 Kind = CK_IntegralCast;
1058 Kind = CK_IntegralToFloating;
1074 Kind = CK_IntegralCast;
1077 Kind = CK_FloatingToIntegral;
1093 OpRange, msg, Kind, BasePath);
1116 if (DestPointeeQuals != SrcPointeeQuals &&
1118 msg = diag::err_bad_cxx_cast_qualifiers_away;
1130 Self.
Diag(OpRange.getBegin(), diag::ext_ms_cast_fn_obj) << OpRange;
1138 Kind = CK_CPointerToObjCPointerCast;
1143 Kind = CK_AnyPointerToBlockPointerCast;
1164 if (SrcPointer->getPointeeType()->getAs<
RecordType>() &&
1166 msg = diag::err_bad_cxx_cast_unrelated_class;
1191 bool ObjCConversion;
1192 bool ObjCLifetimeConversion;
1201 SrcExpr->
getLocStart(), ToType, FromType, DerivedToBase, ObjCConversion,
1202 ObjCLifetimeConversion);
1209 msg = SrcExpr->
isLValue() ? diag::err_bad_lvalue_to_rvalue_cast
1210 : diag::err_bad_rvalue_to_rvalue_cast;
1214 if (DerivedToBase) {
1215 Kind = CK_DerivedToBase;
1245 if (!DestReference) {
1249 if (!RValueRef && !SrcExpr->
isLValue()) {
1251 msg = diag::err_bad_cxx_cast_rvalue;
1288 msg = diag::err_bad_static_cast_pointer_nonpointer;
1295 CStyle, OpRange, SrcType, DestType, msg, Kind,
1305 QualType OrigDestType,
unsigned &msg,
1343 msg = diag::err_bad_cxx_cast_qualifiers_away;
1347 if (Paths.
isAmbiguous(SrcType.getUnqualifiedType())) {
1357 std::string PathDisplayStr;
1358 std::set<unsigned> DisplayedPaths;
1360 if (DisplayedPaths.insert(Path.back().SubobjectNumber).second) {
1363 PathDisplayStr +=
"\n ";
1365 PathDisplayStr += PE.Base->getType().getAsString() +
" -> ";
1370 Self.
Diag(OpRange.
getBegin(), diag::err_ambiguous_base_to_derived_cast)
1373 << PathDisplayStr << OpRange;
1380 Self.
Diag(OpRange.
getBegin(), diag::err_static_downcast_via_virtual)
1381 << OrigSrcType << OrigDestType << VirtualBase << OpRange;
1390 diag::err_downcast_from_inaccessible_base)) {
1403 Kind = CK_BaseToDerived;
1424 bool WasOverloadedFunction =
false;
1433 WasOverloadedFunction =
true;
1439 msg = diag::err_bad_static_cast_member_pointer_nonmp;
1466 Paths.setRecordingPaths(
true);
1472 Self.
Diag(OpRange.
getBegin(), diag::err_ambiguous_memptr_conv)
1473 << 1 << SrcClass << DestClass << PathDisplayStr << OpRange;
1478 if (
const RecordType *VBase = Paths.getDetectedVirtual()) {
1479 Self.
Diag(OpRange.
getBegin(), diag::err_memptr_conv_via_virtual)
1480 << SrcClass << DestClass <<
QualType(VBase, 0) << OpRange;
1487 DestClass, SrcClass,
1489 diag::err_upcast_to_inaccessible_base)) {
1503 if (WasOverloadedFunction) {
1523 Kind = CK_DerivedToBaseMemberPointer;
1539 diag::err_bad_dynamic_cast_incomplete) ||
1541 diag::err_allocation_of_abstract_type)) {
1555 Expr *SrcExprRaw = SrcExpr.
get();
1578 Kind = CK_ConstructorConversion;
1593 bool NeedToMaterializeTemporary =
false;
1607 if (isa<LValueReferenceType>(DestTypeTmp) && !SrcExpr.
get()->isLValue()) {
1611 msg = diag::err_bad_cxx_cast_rvalue;
1615 if (isa<RValueReferenceType>(DestTypeTmp) && SrcExpr.
get()->isRValue()) {
1619 msg = diag::err_bad_cxx_cast_rvalue;
1625 NeedToMaterializeTemporary =
true;
1633 if (SrcExpr.
get()->refersToBitField()) {
1634 msg = diag::err_bad_cxx_cast_bitfield;
1654 msg = diag::err_bad_const_cast_dest;
1663 msg = diag::err_bad_const_cast_dest;
1673 while (SrcType != DestType &&
1683 if (SrcQuals != DestQuals)
1688 if (SrcType != DestType)
1691 if (NeedToMaterializeTemporary)
1709 unsigned DiagID = IsDereference ?
1710 diag::warn_pointer_indirection_from_incompatible_type :
1711 diag::warn_undefined_reinterpret_cast;
1713 if (Diags.isIgnored(DiagID, Range.
getBegin()))
1717 if (IsDereference) {
1753 Diag(Range.
getBegin(), DiagID) << SrcType << DestType << Range;
1762 if (SrcPtrTy->isObjCSelType()) {
1764 if (isa<PointerType>(DestType))
1767 Self.
Diag(SrcExpr.
get()->getExprLoc(),
1768 diag::warn_cast_pointer_from_sel)
1769 << SrcType << DestType << SrcExpr.
get()->getSourceRange();
1783 const auto *SrcFTy =
1785 const auto *DstFTy =
1794 Expr *Src = SrcExpr.
get()->IgnoreParenImpCasts();
1795 if (
auto *UO = dyn_cast<UnaryOperator>(Src))
1796 if (UO->getOpcode() == UO_AddrOf)
1810 FD->isVariadic(), FD->isCXXInstanceMember());
1811 if (DstCC == DefaultCC || SrcCC != DefaultCC)
1817 Self.
Diag(OpRange.
getBegin(), diag::warn_cast_calling_conv)
1818 << SrcCCName << DstCCName << OpRange;
1830 SourceLocation NameLoc = FD->getFirstDecl()->getNameInfo().getLoc();
1834 llvm::raw_svector_ostream OS(CCAttrText);
1837 OS <<
"__" << DstCCName;
1844 OS <<
"__attribute__((" << DstCCName <<
"))";
1845 AttrTokens.push_back(tok::kw___attribute);
1846 AttrTokens.push_back(tok::l_paren);
1847 AttrTokens.push_back(tok::l_paren);
1852 AttrTokens.push_back(tok::r_paren);
1853 AttrTokens.push_back(tok::r_paren);
1856 if (!AttrSpelling.empty())
1857 CCAttrText = AttrSpelling;
1859 Self.
Diag(NameLoc, diag::note_change_calling_conv_fixit)
1883 diag::warn_int_to_void_pointer_cast
1884 : diag::warn_int_to_pointer_cast;
1885 Self.
Diag(Loc, Diag) << SrcType << DestType;
1921 bool IsLValueCast =
false;
1933 assert(FixedExpr.
isUsable() &&
"Invalid result fixing overloaded expr");
1934 SrcExpr = FixedExpr;
1935 SrcType = SrcExpr.get()->getType();
1939 if (!SrcExpr.
get()->isGLValue()) {
1942 msg = diag::err_bad_cxx_cast_rvalue;
1955 const char *inappropriate =
nullptr;
1956 switch (SrcExpr.
get()->getObjectKind()) {
1960 msg = diag::err_bad_cxx_cast_bitfield;
1965 case OK_ObjCSubscript: inappropriate =
"container subscripting expression";
1968 if (inappropriate) {
1969 Self.
Diag(OpRange.
getBegin(), diag::err_bad_reinterpret_cast_reference)
1970 << inappropriate << DestType
1971 << OpRange << SrcExpr.
get()->getSourceRange();
1980 IsLValueCast =
true;
1988 if (DestMemPtr && SrcMemPtr) {
1994 SrcMemPtr->isMemberFunctionPointer())
2003 msg = diag::err_bad_cxx_cast_qualifiers_away;
2017 msg = diag::err_bad_cxx_cast_member_pointer_size;
2022 assert(!IsLValueCast);
2023 Kind = CK_ReinterpretMemberPointer;
2035 msg = diag::err_bad_reinterpret_cast_small_int;
2038 Kind = CK_PointerToIntegral;
2046 if (srcIsVector || destIsVector) {
2063 msg = diag::err_bad_cxx_cast_vector_to_scalar_different_size;
2064 else if (!srcIsVector)
2065 msg = diag::err_bad_cxx_cast_scalar_to_vector_different_size;
2067 msg = diag::err_bad_cxx_cast_vector_to_vector_different_size;
2072 if (SrcType == DestType) {
2096 if (!destIsPtr && !srcIsPtr) {
2103 assert(srcIsPtr &&
"One type must be a pointer");
2107 bool MicrosoftException = Self.
getLangOpts().MicrosoftExt &&
2111 !MicrosoftException) {
2112 msg = diag::err_bad_reinterpret_cast_small_int;
2115 Kind = CK_PointerToIntegral;
2120 assert(destIsPtr &&
"One type must be a pointer");
2127 Kind = CK_IntegralToPointer;
2131 if (!destIsPtr || !srcIsPtr) {
2141 msg = diag::err_bad_cxx_cast_qualifiers_away;
2151 Kind = CK_LValueBitCast;
2156 Kind = CK_AnyPointerToBlockPointerCast;
2192 diag::warn_cxx98_compat_cast_fn_obj : diag::ext_cast_fn_obj)
2201 diag::warn_cxx98_compat_cast_fn_obj : diag::ext_cast_fn_obj)
2214 void CastOperation::CheckCXXCStyleCast(
bool FunctionalStyle,
2215 bool ListInitialization) {
2219 if (isPlaceholder()) {
2221 if (claimPlaceholder(BuiltinType::UnknownAny)) {
2224 ValueKind, BasePath);
2228 checkNonOverloadPlaceholders();
2239 if (claimPlaceholder(BuiltinType::Overload)) {
2242 true, DestRange, DestType,
2243 diag::err_bad_cstyle_cast_overload);
2254 SrcExpr.
get()->isValueDependent()) {
2255 assert(
Kind == CK_Dependent);
2260 !isPlaceholder(BuiltinType::Overload)) {
2269 && (SrcExpr.
get()->getType()->isIntegerType()
2270 || SrcExpr.
get()->getType()->isFloatingType())) {
2271 Kind = CK_VectorSplat;
2287 unsigned msg = diag::err_bad_cxx_cast_generic;
2301 msg,
Kind, BasePath, ListInitialization);
2308 OpRange, msg,
Kind);
2316 checkObjCConversion(CCK);
2330 Self.
Diag(OpRange.
getBegin(), diag::err_bad_cstyle_cast_overload)
2331 << OE->
getName() << DestType << OpRange
2337 OpRange, SrcExpr.
get(), DestType, ListInitialization);
2339 }
else if (
Kind == CK_BitCast) {
2354 SrcExpr.
get()->getExprLoc()))
2357 if (!isa<CallExpr>(SrcExpr.
get()))
2379 Self.
Diag(SrcExpr.
get()->getExprLoc(),
2380 diag::warn_bad_function_cast)
2381 << SrcType << DestType << SrcExpr.
get()->getSourceRange();
2385 void CastOperation::CheckCStyleCast() {
2389 if (claimPlaceholder(BuiltinType::UnknownAny)) {
2392 ValueKind, BasePath);
2413 SrcExpr.
get(), DestType,
true, DAP))
2420 if (SrcExpr.isInvalid())
2422 QualType SrcType = SrcExpr.get()->getType();
2433 diag::err_typecheck_incompatible_address_space)
2435 << SrcExpr.get()->getSourceRange();
2442 diag::err_typecheck_cast_to_incomplete)) {
2452 Self.
Diag(OpRange.
getBegin(), diag::ext_typecheck_cast_nonscalar)
2453 << DestType << SrcExpr.get()->getSourceRange();
2462 Self.
Diag(OpRange.
getBegin(), diag::ext_typecheck_cast_to_union)
2463 << SrcExpr.get()->getSourceRange();
2467 Self.
Diag(OpRange.
getBegin(), diag::err_typecheck_cast_to_union_no_type)
2468 << SrcType << SrcExpr.get()->getSourceRange();
2476 llvm::APSInt CastInt;
2477 if (SrcExpr.get()->EvaluateAsInt(CastInt, Self.
Context)) {
2479 Kind = CK_ZeroToOCLEvent;
2483 diag::err_opencl_cast_non_zero_to_event_t)
2484 << CastInt.toString(10) << SrcExpr.get()->getSourceRange();
2491 Self.
Diag(OpRange.
getBegin(), diag::err_typecheck_cond_expect_scalar)
2492 << DestType << SrcExpr.get()->getSourceRange();
2501 Self.
Diag(SrcExpr.get()->getExprLoc(),
2502 diag::err_typecheck_expect_scalar_operand)
2503 << SrcType << SrcExpr.get()->getSourceRange();
2516 Kind = CK_VectorSplat;
2535 if (isa<ObjCSelectorExpr>(SrcExpr.get())) {
2536 Self.
Diag(SrcExpr.get()->getExprLoc(), diag::err_cast_selector_expr);
2545 Self.
Diag(SrcExpr.get()->getExprLoc(),
2546 diag::err_cast_pointer_from_non_pointer_int)
2547 << SrcType << SrcExpr.get()->getSourceRange();
2556 Self.
Diag(SrcExpr.get()->getLocStart(),
2557 diag::err_cast_pointer_to_non_pointer_int)
2558 << DestType << SrcExpr.get()->getSourceRange();
2567 Self.
Diag(SrcExpr.get()->getLocStart(), diag::err_opencl_cast_to_half)
2568 << DestType << SrcExpr.get()->getSourceRange();
2577 if (SrcExpr.isInvalid())
2581 if (Self.
getLangOpts().ObjCAutoRefCount && CastPtr) {
2584 Qualifiers ExprQuals = ExprPtr->getPointeeType().getQualifiers();
2586 ExprPtr->getPointeeType()->isObjCLifetimeType() &&
2588 Self.
Diag(SrcExpr.get()->getLocStart(),
2589 diag::err_typecheck_incompatible_ownership)
2591 << SrcExpr.get()->getSourceRange();
2597 Self.
Diag(SrcExpr.get()->getLocStart(),
2598 diag::err_arc_convesion_of_weak_unavailable)
2599 << 1 << SrcType << DestType << SrcExpr.get()->getSourceRange();
2609 if (SrcExpr.isInvalid())
2612 if (
Kind == CK_BitCast)
2628 QualType TheOffendingSrcType, TheOffendingDestType;
2631 &TheOffendingSrcType, &TheOffendingDestType,
2632 &CastAwayQualifiers))
2635 int qualifiers = -1;
2638 }
else if (CastAwayQualifiers.
hasConst()) {
2644 if (qualifiers == -1)
2645 Self.
Diag(SrcExpr.
get()->getLocStart(), diag::warn_cast_qual2)
2646 << SrcType << DestType;
2648 Self.
Diag(SrcExpr.
get()->getLocStart(), diag::warn_cast_qual)
2649 << TheOffendingSrcType << TheOffendingDestType << qualifiers;
2656 CastOperation Op(*
this, CastTypeInfo->
getType(), CastExpr);
2660 if (getLangOpts().CPlusPlus) {
2661 Op.CheckCXXCStyleCast(
false,
2662 isa<InitListExpr>(CastExpr));
2664 Op.CheckCStyleCast();
2667 if (Op.SrcExpr.isInvalid())
2674 Op.ValueKind, Op.Kind, Op.SrcExpr.get(),
2675 &Op.BasePath, CastTypeInfo, LPLoc, RPLoc));
2683 assert(LPLoc.
isValid() &&
"List-initialization shouldn't get here.");
2684 CastOperation Op(*
this, Type, CastExpr);
2688 Op.CheckCXXCStyleCast(
true,
false);
2689 if (Op.SrcExpr.isInvalid())
2692 auto *SubExpr = Op.SrcExpr.
get();
2693 if (
auto *BindExpr = dyn_cast<CXXBindTemporaryExpr>(SubExpr))
2694 SubExpr = BindExpr->getSubExpr();
2695 if (
auto *ConstructExpr = dyn_cast<CXXConstructExpr>(SubExpr))
2696 ConstructExpr->setParenOrBraceRange(
SourceRange(LPLoc, RPLoc));
2699 Op.ValueKind, CastTypeInfo, Op.Kind,
2700 Op.SrcExpr.get(), &Op.BasePath, LPLoc, RPLoc));
Defines the clang::ASTContext interface.
bool RequireNonAbstractType(SourceLocation Loc, QualType T, TypeDiagnoser &Diagnoser)
An instance of this class is created to represent a function declaration or definition.
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.
PointerType - C99 6.7.5.1 - Pointer Declarators.
QualType getPointeeType() const
A (possibly-)qualified type.
bool isBlockPointerType() const
bool isMemberPointerType() const
IdentifierInfo * getIdentifierInfo(StringRef Name) const
Return information about the specified preprocessor identifier token.
A cast other than a C-style cast.
SourceRange getSourceRange() const LLVM_READONLY
Retrieve the source range covering the entirety of this nested-name-specifier.
const ASTRecordLayout & getASTRecordLayout(const RecordDecl *D) const
Get or compute information about the layout of the specified record (struct/union/class) D...
bool isArithmeticType() const
FunctionType - C99 6.7.5.3 - Function Declarators.
ARCConversionResult CheckObjCConversion(SourceRange castRange, QualType castType, Expr *&op, CheckedConversionKind CCK, bool Diagnose=true, bool DiagnoseCFAudited=false, BinaryOperatorKind Opc=BO_PtrMemD)
Checks for invalid conversions and casts between retainable pointers and other pointer kinds for ARC ...
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee...
CharUnits getBaseClassOffset(const CXXRecordDecl *Base) const
getBaseClassOffset - Get the offset, in chars, for the given base class.
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 isRealFloatingType() const
Floating point categories.
bool isRecordType() const
QualType getQualifiedType(SplitQualType split) const
Un-split a SplitQualType.
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.
bool isExtVectorType() const
The cast method is appropriate and successful.
FailureKind getFailureKind() const
Determine why initialization failed.
CanQualType ARCUnbridgedCastTy
The base class of the type hierarchy.
bool isDerivedFrom(const CXXRecordDecl *Base) const
Determine whether this class is derived from the class Base.
StringRef getLastMacroWithSpelling(SourceLocation Loc, ArrayRef< TokenValue > Tokens) const
Return the name of the macro defined before Loc that has spelling Tokens.
static ExprValueKind getValueKindForType(QualType T)
getValueKindForType - Given a formal return or parameter type, give its value kind.
Overloading for a user-defined conversion failed.
bool isZero() const
isZero - Test whether the quantity equals zero.
Ambiguous candidates found.
const TargetInfo & getTargetInfo() const
A container of type source information.
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.
bool isCompleteDefinition() const
isCompleteDefinition - Return true if this decl has its body fully specified.
bool isUnsignedIntegerType() const
Return true if this is an integer type that is unsigned, according to C99 6.2.5p6 [which returns true...
bool CheckVectorCast(SourceRange R, QualType VectorTy, QualType Ty, CastKind &Kind)
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
bool isEnumeralType() const
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...
const T * getAs() const
Member-template getAs<specific type>'.
void clear()
Clear the base-paths results.
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 ...
DeclarationName getName() const
Gets the name looked up.
bool isInvalidDecl() const
OpenCLOptions & getOpenCLOptions()
Defines the clang::Expr interface and subclasses for C++ expressions.
The collection of all-type qualifiers we support.
bool isRecordingPaths() const
Whether we are recording paths.
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.
TargetCXXABI getCXXABI() const
Get the C++ ABI currently in use.
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.
QualType getPointeeType() const
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
bool allowsNonTrivialObjCLifetimeQualifiers() const
True if any ObjC types may have non-trivial lifetime qualifiers.
bool isObjCLifetimeType() const
Returns true if objects of this type have lifetime semantics under ARC.
The cast method is not applicable.
RecordDecl * getDefinition() const
getDefinition - Returns the RecordDecl that actually defines this struct/union/class.
bool IsDerivedFrom(SourceLocation Loc, QualType Derived, QualType Base)
Determine whether the type Derived is a C++ class that is derived from the type Base.
bool isReferenceType() const
static CharUnits Zero()
Zero - Construct a CharUnits quantity of zero.
Ref_Incompatible - The two types are incompatible, so direct reference binding is not possible...
bool isAtLeastAsQualifiedAs(QualType Other) const
Determine whether this type is at least as qualified as the other given type, requiring exact equalit...
bool isIntegralOrEnumerationType() const
Determine whether this type is an integral or enumeration type.
OverloadCandidateDisplayKind
An r-value expression (a pr-value in the C++11 taxonomy) produces a temporary value.
bool isInvalidType() const
bool isCompleteType(SourceLocation Loc, QualType T)
An rvalue reference type, per C++11 [dcl.ref].
bool UnwrapSimilarPointerTypes(QualType &T1, QualType &T2)
UnwrapSimilarPointerTypes - If T1 and T2 are pointer types that may be similar (C++ 4...
tok::TokenKind getTokenID() const
If this is a source-language token (e.g.
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.
Ref_Compatible - The two types are reference-compatible.
OverloadCandidateSet & getFailedCandidateSet()
Retrieve a reference to the candidate set when overload resolution fails.
ExprValueKind getValueKind() const
getValueKind - The value kind that this expression produces.
const Type * getClass() const
bool isRValueReferenceType() const
CheckedConversionKind
The kind of conversion being performed.
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 RecordType * getDetectedVirtual() const
The virtual base discovered on the path (if we are merely detecting virtuals).
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
CastExpr - Base class for type casts, including both implicit casts (ImplicitCastExpr) and explicit c...
static void DiagnoseCastQual(Sema &Self, const ExprResult &SrcExpr, QualType DestType)
DiagnoseCastQual - Warn whenever casts discards a qualifiers, be it either const, volatile or both...
const internal::VariadicDynCastAllOfMatcher< Stmt, CastExpr > castExpr
Matches any cast nodes of Clang's AST.
const LangOptions & getLangOpts() const
ExprResult DefaultFunctionArrayLvalueConversion(Expr *E, bool Diagnose=true)
bool isScalarType() const
bool compatiblyIncludesObjCLifetime(Qualifiers other) const
Determines if these qualifiers compatibly include another set of qualifiers from the narrow perspecti...
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...
CastKind PrepareScalarCast(ExprResult &src, QualType destType)
Prepares for a scalar cast, performing all the necessary stages except the final cast and returning t...
Sema - This implements semantic analysis and AST building for C.
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
bool compatiblyIncludes(Qualifiers other) const
Determines if these qualifiers compatibly include another set.
bool isComplexType() const
isComplexType() does not include complex integers (a GCC extension).
CastKind
CastKind - The kind of operation required for a conversion.
SourceLocation getLocEnd() const LLVM_READONLY
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...
bool isEnabled(llvm::StringRef Ext) const
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...
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.
QualType getPointeeType() const
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.
void BuildBasePathArray(const CXXBasePaths &Paths, CXXCastPath &BasePath)
static FindResult find(Expr *E)
Finds the overloaded expression in the given expression E of OverloadTy.
const CXXRecordDecl * getPointeeCXXRecordDecl() const
If this is a pointer or reference to a RecordType, return the CXXRecordDecl that that type refers to...
const T * castAs() const
Member-template castAs<specific type>.
OverloadingResult getFailedOverloadResult() const
Get the overloading result, for when the initialization sequence failed due to a bad overload...
Defines the clang::Preprocessor interface.
bool isNullPtrType() const
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)
CXXRecordDecl * getDefinition() const
Overload resolution succeeded.
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.
ExprResult CheckPlaceholderExpr(Expr *E)
Check for operands with placeholder types and complain if found.
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 isConstructorInitialization() const
Determine whether this initialization is direct call to a constructor.
ReferenceCompareResult
ReferenceCompareResult - Expresses the result of comparing two types (cv1 T1 and cv2 T2) to determine...
bool RequireCompleteType(SourceLocation Loc, QualType T, TypeDiagnoser &Diagnoser)
Ensure that the type T is a complete type.
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.
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 resolveAndFixAddressOfOnlyViableOverloadCandidate(ExprResult &SrcExpr, bool DoFunctionPointerConversion=false)
Given an overloaded function, tries to turn it into a non-overloaded function reference using resolve...
bool isAtLeastAsQualifiedAs(CanQual< T > Other) const
Determines whether this canonical type is at least as qualified as the Other canonical type...
SourceLocation getEnd() const
Preprocessor & getPreprocessor() const
Represents a GCC generic vector type.
An lvalue reference type, per C++11 [dcl.ref].
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.
bool CheckTollFreeBridgeStaticCast(QualType castType, Expr *castExpr, CastKind &Kind)
QualType getTypeDeclType(const TypeDecl *Decl, const TypeDecl *PrevDecl=nullptr) const
Return the unique reference to the type for the specified type declaration.
The result type of a method or function.
void removeCVRQualifiers(unsigned mask)
CallingConv
CallingConv - Specifies the calling convention that a function uses.
bool isKeyword(const LangOptions &LangOpts) const
Return true if this token is a keyword in the specified language.
ExprResult BuildCStyleCastExpr(SourceLocation LParenLoc, TypeSourceInfo *Ty, SourceLocation RParenLoc, Expr *Op)
bool isVoidPointerType() const
bool areLaxCompatibleVectorTypes(QualType srcType, QualType destType)
Are the two types lax-compatible vector types? That is, given that one of them is a vector...
RecordDecl * getDecl() const
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.
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...
ActionResult - This structure is used while parsing/acting on expressions, stmts, etc...
ASTContext & getASTContext() const
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.
static const FieldDecl * getTargetFieldForToUnionCast(QualType unionType, QualType opType)
bool isIntegralType(const ASTContext &Ctx) const
Determine whether this type is an integral type.
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 CheckObjCARCUnavailableWeakConversion(QualType castType, QualType ExprType)
std::string getAmbiguousPathsDisplayString(CXXBasePaths &Paths)
Builds a string representing ambiguous paths from a specific derived class to different subobjects of...
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...
bool isMemberFunctionPointerType() const
bool isObjCObjectPointerType() const
bool isAnyPointerType() const
bool isLValue() const
isLValue - True if this expression is an "l-value" according to the rules of the current language...
Overloading for initialization by constructor failed.
Requests that all candidates be shown.
bool isAddressSpaceOverlapping(const PointerType &other) const
Returns true if address spaces of pointers overlap.
bool isAnyCharacterType() const
Determine whether this type is any of the built-in character types.
bool isVectorType() const
OverloadCandidateSet - A set of overload candidates, used in C++ overload resolution (C++ 13...
static InitializationKind CreateCast(SourceRange TypeRange)
Create a direct initialization due to a cast that isn't a C-style or functional cast.
bool hasSameUnqualifiedType(QualType T1, QualType T2) const
Determine whether the given types are equivalent after cvr-qualifiers have been removed.
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)
CanProxy< U > getAs() const
Retrieve a canonical type pointer with a different static type, upcasting or downcasting as needed...
ExprResult checkUnknownAnyCast(SourceRange TypeRange, QualType CastType, Expr *CastExpr, CastKind &CastKind, ExprValueKind &VK, CXXCastPath &Path)
Check a cast of an unknown-any type.
A POD class for pairing a NamedDecl* with an access specifier.
bool isPlaceholderType() const
Test for a type which does not represent an actual type-system type but is instead used as a placehol...
Represents an element in a path from a derived class to a base class.
CallingConv getDefaultCallingConvention(bool IsVariadic, bool IsCXXMethod) const
Retrieves the default calling convention for the current target.
std::list< CXXBasePath >::const_iterator const_paths_iterator
Dataflow Directional Tag Classes.
bool isValid() const
Return true if this is a valid SourceLocation object.
void CheckCompatibleReinterpretCast(QualType SrcType, QualType DestType, bool IsDereference, SourceRange Range)
The cast method is appropriate, but failed.
static std::string getAsString(SplitQualType split, const PrintingPolicy &Policy)
const CXXRecordDecl * getParent() const
Returns the parent of this method declaration, which is the class in which this method is defined...
bool isBooleanType() const
ExprResult prepareVectorSplat(QualType VectorTy, Expr *SplattedExpr)
Prepare SplattedExpr for a vector splat operation, adding implicit casts if necessary.
static void checkIntToPointerCast(bool CStyle, SourceLocation Loc, const Expr *SrcExpr, QualType DestType, Sema &Self)
Requests that only viable candidates be shown.
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.
bool isIntegerConstantExpr(llvm::APSInt &Result, const ASTContext &Ctx, SourceLocation *Loc=nullptr, bool isEvaluated=true) const
isIntegerConstantExpr - Return true if this expression is a valid integer constant expression...
void setCVRQualifiers(unsigned mask)
static InitializationKind CreateCStyleCast(SourceLocation StartLoc, SourceRange TypeRange, bool InitList)
Create a direct initialization for a C-style cast.
void CheckCastAlign(Expr *Op, QualType T, SourceRange TRange)
CheckCastAlign - Implements -Wcast-align, which warns when a pointer cast increases the alignment req...
static void DiagnoseCastOfObjCSEL(Sema &Self, const ExprResult &SrcExpr, QualType DestType)
static bool fixOverloadedReinterpretCastExpr(Sema &Self, QualType DestType, ExprResult &Result)
Expr * IgnoreParenImpCasts() LLVM_READONLY
IgnoreParenImpCasts - Ignore parentheses and implicit casts.
ExprResult IgnoredValueConversions(Expr *E)
IgnoredValueConversions - Given that an expression's result is syntactically ignored, perform any conversions that are required.
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.
bool isIntegerType() const
isIntegerType() does not include complex integers (a GCC extension).
ExprResult CheckExtVectorCast(SourceRange R, QualType DestTy, Expr *CastExpr, CastKind &Kind)
static CStyleCastExpr * Create(const ASTContext &Context, QualType T, ExprValueKind VK, CastKind K, Expr *Op, const CXXCastPath *BasePath, TypeSourceInfo *WrittenTy, SourceLocation L, SourceLocation R)
bool CheckDerivedToBaseConversion(QualType Derived, QualType Base, SourceLocation Loc, SourceRange Range, CXXCastPath *BasePath=nullptr, bool IgnoreAccess=false)
bool isFunctionType() const
MaterializeTemporaryExpr * CreateMaterializeTemporaryExpr(QualType T, Expr *Temporary, bool BoundToLvalueReference)
Base for LValueReferenceType and RValueReferenceType.
bool hasSameType(QualType T1, QualType T2) const
Determine whether the given types T1 and T2 are equivalent.
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...
QualType getNonLValueExprType(const ASTContext &Context) const
Determine the type of a (typically non-lvalue) expression with the specified result type...
A bitfield object is a bitfield on a C or C++ record.
uint64_t getTypeSize(QualType T) const
Return the size of the specified (complete) type T, in bits.
bool isObjCObjectType() const
CanQualType getCanonicalType(QualType T) const
Return the canonical (structural) type corresponding to the specified potentially non-canonical type ...
bool isLValueReferenceType() const
ExprResult BuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo, QualType Type, SourceLocation LParenLoc, Expr *CastExpr, SourceLocation RParenLoc)
TypeLoc getTypeLoc() const
Return the TypeLoc wrapper for the type source info.
bool Failed() const
Determine whether the initialization sequence is invalid.
CallingConv getCallConv() const
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.
bool isMemberFunctionPointer() const
Returns true if the member type (i.e.
Qualifiers getQualifiers() const
Retrieve the set of qualifiers applied to this type.
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.
QualType getPointerType(QualType T) const
Return the uniqued reference to the type for a pointer to the specified type.
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'.
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
Defines the clang::TargetInfo interface.
bool isComplexIntegerType() const
bool isMicrosoft() const
Is this ABI an MSVC-compatible ABI?
unsigned getCVRQualifiers() const
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...
bool isDependentType() const
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
A reference to a declared variable, function, enum, etc.
bool isIgnored(unsigned DiagID, SourceLocation Loc) const
Determine whether the diagnostic is known to be ignored.
NestedNameSpecifierLoc getQualifierLoc() const
Fetches the nested-name qualifier with source-location information, if one was given.
bool isPointerType() const
void NoteAllOverloadCandidates(Expr *E, QualType DestType=QualType(), bool TakingAddress=false)
BasePaths - Represents the set of paths from a derived class to one of its (direct or indirect) bases...
No viable function found.
static StringRef getNameForCallConv(CallingConv CC)
bool isFloatingType() const
A trivial tuple used to represent a source range.
Describes an entity that is being initialized.
bool isFunctionPointerType() const
SourceLocation getLocStart() const LLVM_READONLY
SourceLocation getBegin() const
const LangOptions & getLangOpts() const
void NoteCandidates(Sema &S, OverloadCandidateDisplayKind OCD, ArrayRef< Expr *> Args, StringRef Opc="", SourceLocation Loc=SourceLocation(), llvm::function_ref< bool(OverloadCandidate &)> Filter=[](OverloadCandidate &) { return true;})
PrintOverloadCandidates - When overload resolution fails, prints diagnostic messages containing the c...
QualType getUnqualifiedArrayType(QualType T, Qualifiers &Quals)
Return this type as a completely-unqualified array type, capturing the qualifiers in Quals...
bool isIncompleteOrObjectType() const
Return true if this is an incomplete or object type, in other words, not a function type...
QualType getPointeeType() const
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...
QualType getType() const
Return the type wrapped by this type source info.
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
QualType getPointeeType() const
Gets the type pointed to by this ObjC pointer.