@@ -5739,76 +5739,6 @@ static bool EvaluateUnaryTypeTrait(Sema &Self, TypeTrait UTT,
5739
5739
static bool EvaluateBinaryTypeTrait (Sema &Self, TypeTrait BTT, const TypeSourceInfo *Lhs,
5740
5740
const TypeSourceInfo *Rhs, SourceLocation KeyLoc);
5741
5741
5742
- static ExprResult CheckConvertibilityForTypeTraits (
5743
- Sema &Self, const TypeSourceInfo *Lhs, const TypeSourceInfo *Rhs,
5744
- SourceLocation KeyLoc, llvm::BumpPtrAllocator &OpaqueExprAllocator) {
5745
-
5746
- QualType LhsT = Lhs->getType ();
5747
- QualType RhsT = Rhs->getType ();
5748
-
5749
- // C++0x [meta.rel]p4:
5750
- // Given the following function prototype:
5751
- //
5752
- // template <class T>
5753
- // typename add_rvalue_reference<T>::type create();
5754
- //
5755
- // the predicate condition for a template specialization
5756
- // is_convertible<From, To> shall be satisfied if and only if
5757
- // the return expression in the following code would be
5758
- // well-formed, including any implicit conversions to the return
5759
- // type of the function:
5760
- //
5761
- // To test() {
5762
- // return create<From>();
5763
- // }
5764
- //
5765
- // Access checking is performed as if in a context unrelated to To and
5766
- // From. Only the validity of the immediate context of the expression
5767
- // of the return-statement (including conversions to the return type)
5768
- // is considered.
5769
- //
5770
- // We model the initialization as a copy-initialization of a temporary
5771
- // of the appropriate type, which for this expression is identical to the
5772
- // return statement (since NRVO doesn't apply).
5773
-
5774
- // Functions aren't allowed to return function or array types.
5775
- if (RhsT->isFunctionType () || RhsT->isArrayType ())
5776
- return ExprError ();
5777
-
5778
- // A function definition requires a complete, non-abstract return type.
5779
- if (!Self.isCompleteType (Rhs->getTypeLoc ().getBeginLoc (), RhsT) ||
5780
- Self.isAbstractType (Rhs->getTypeLoc ().getBeginLoc (), RhsT))
5781
- return ExprError ();
5782
-
5783
- // Compute the result of add_rvalue_reference.
5784
- if (LhsT->isObjectType () || LhsT->isFunctionType ())
5785
- LhsT = Self.Context .getRValueReferenceType (LhsT);
5786
-
5787
- // Build a fake source and destination for initialization.
5788
- InitializedEntity To (InitializedEntity::InitializeTemporary (RhsT));
5789
- Expr *From = new (OpaqueExprAllocator.Allocate <OpaqueValueExpr>())
5790
- OpaqueValueExpr (KeyLoc, LhsT.getNonLValueExprType (Self.Context ),
5791
- Expr::getValueKindForType (LhsT));
5792
- InitializationKind Kind =
5793
- InitializationKind::CreateCopy (KeyLoc, SourceLocation ());
5794
-
5795
- // Perform the initialization in an unevaluated context within a SFINAE
5796
- // trap at translation unit scope.
5797
- EnterExpressionEvaluationContext Unevaluated (
5798
- Self, Sema::ExpressionEvaluationContext::Unevaluated);
5799
- Sema::SFINAETrap SFINAE (Self, /* AccessCheckingSFINAE=*/ true );
5800
- Sema::ContextRAII TUContext (Self, Self.Context .getTranslationUnitDecl ());
5801
- InitializationSequence Init (Self, To, Kind, From);
5802
- if (Init.Failed ())
5803
- return ExprError ();
5804
-
5805
- ExprResult Result = Init.Perform (Self, To, Kind, From);
5806
- if (Result.isInvalid () || SFINAE.hasErrorOccurred ())
5807
- return ExprError ();
5808
-
5809
- return Result;
5810
- }
5811
-
5812
5742
static APValue EvaluateSizeTTypeTrait (Sema &S, TypeTrait Kind,
5813
5743
SourceLocation KWLoc,
5814
5744
ArrayRef<TypeSourceInfo *> Args,
@@ -5958,9 +5888,8 @@ static bool EvaluateBooleanTypeTrait(Sema &S, TypeTrait Kind,
5958
5888
S.Context .getPointerType (T.getNonReferenceType ()));
5959
5889
TypeSourceInfo *UPtr = S.Context .CreateTypeSourceInfo (
5960
5890
S.Context .getPointerType (U.getNonReferenceType ()));
5961
- return !CheckConvertibilityForTypeTraits (S, UPtr, TPtr, RParenLoc,
5962
- OpaqueExprAllocator)
5963
- .isInvalid ();
5891
+ return S.BuiltinIsConvertible (UPtr->getType (), TPtr->getType (),
5892
+ RParenLoc);
5964
5893
}
5965
5894
5966
5895
if (Kind == clang::TT_IsNothrowConstructible)
@@ -6200,20 +6129,9 @@ static bool EvaluateBinaryTypeTrait(Sema &Self, TypeTrait BTT, const TypeSourceI
6200
6129
}
6201
6130
case BTT_IsConvertible:
6202
6131
case BTT_IsConvertibleTo:
6203
- case BTT_IsNothrowConvertible: {
6204
- if (RhsT->isVoidType ())
6205
- return LhsT->isVoidType ();
6206
- llvm::BumpPtrAllocator OpaqueExprAllocator;
6207
- ExprResult Result = CheckConvertibilityForTypeTraits (Self, Lhs, Rhs, KeyLoc,
6208
- OpaqueExprAllocator);
6209
- if (Result.isInvalid ())
6210
- return false ;
6211
-
6212
- if (BTT != BTT_IsNothrowConvertible)
6213
- return true ;
6214
-
6215
- return Self.canThrow (Result.get ()) == CT_Cannot;
6216
- }
6132
+ case BTT_IsNothrowConvertible:
6133
+ return Self.BuiltinIsConvertible (LhsT, RhsT, KeyLoc,
6134
+ BTT == BTT_IsNothrowConvertible);
6217
6135
6218
6136
case BTT_IsAssignable:
6219
6137
case BTT_IsNothrowAssignable:
0 commit comments