@@ -5743,76 +5743,6 @@ static bool EvaluateUnaryTypeTrait(Sema &Self, TypeTrait UTT,
5743
5743
static bool EvaluateBinaryTypeTrait (Sema &Self, TypeTrait BTT, const TypeSourceInfo *Lhs,
5744
5744
const TypeSourceInfo *Rhs, SourceLocation KeyLoc);
5745
5745
5746
- static ExprResult CheckConvertibilityForTypeTraits (
5747
- Sema &Self, const TypeSourceInfo *Lhs, const TypeSourceInfo *Rhs,
5748
- SourceLocation KeyLoc, llvm::BumpPtrAllocator &OpaqueExprAllocator) {
5749
-
5750
- QualType LhsT = Lhs->getType ();
5751
- QualType RhsT = Rhs->getType ();
5752
-
5753
- // C++0x [meta.rel]p4:
5754
- // Given the following function prototype:
5755
- //
5756
- // template <class T>
5757
- // typename add_rvalue_reference<T>::type create();
5758
- //
5759
- // the predicate condition for a template specialization
5760
- // is_convertible<From, To> shall be satisfied if and only if
5761
- // the return expression in the following code would be
5762
- // well-formed, including any implicit conversions to the return
5763
- // type of the function:
5764
- //
5765
- // To test() {
5766
- // return create<From>();
5767
- // }
5768
- //
5769
- // Access checking is performed as if in a context unrelated to To and
5770
- // From. Only the validity of the immediate context of the expression
5771
- // of the return-statement (including conversions to the return type)
5772
- // is considered.
5773
- //
5774
- // We model the initialization as a copy-initialization of a temporary
5775
- // of the appropriate type, which for this expression is identical to the
5776
- // return statement (since NRVO doesn't apply).
5777
-
5778
- // Functions aren't allowed to return function or array types.
5779
- if (RhsT->isFunctionType () || RhsT->isArrayType ())
5780
- return ExprError ();
5781
-
5782
- // A function definition requires a complete, non-abstract return type.
5783
- if (!Self.isCompleteType (Rhs->getTypeLoc ().getBeginLoc (), RhsT) ||
5784
- Self.isAbstractType (Rhs->getTypeLoc ().getBeginLoc (), RhsT))
5785
- return ExprError ();
5786
-
5787
- // Compute the result of add_rvalue_reference.
5788
- if (LhsT->isObjectType () || LhsT->isFunctionType ())
5789
- LhsT = Self.Context .getRValueReferenceType (LhsT);
5790
-
5791
- // Build a fake source and destination for initialization.
5792
- InitializedEntity To (InitializedEntity::InitializeTemporary (RhsT));
5793
- Expr *From = new (OpaqueExprAllocator.Allocate <OpaqueValueExpr>())
5794
- OpaqueValueExpr (KeyLoc, LhsT.getNonLValueExprType (Self.Context ),
5795
- Expr::getValueKindForType (LhsT));
5796
- InitializationKind Kind =
5797
- InitializationKind::CreateCopy (KeyLoc, SourceLocation ());
5798
-
5799
- // Perform the initialization in an unevaluated context within a SFINAE
5800
- // trap at translation unit scope.
5801
- EnterExpressionEvaluationContext Unevaluated (
5802
- Self, Sema::ExpressionEvaluationContext::Unevaluated);
5803
- Sema::SFINAETrap SFINAE (Self, /* AccessCheckingSFINAE=*/ true );
5804
- Sema::ContextRAII TUContext (Self, Self.Context .getTranslationUnitDecl ());
5805
- InitializationSequence Init (Self, To, Kind, From);
5806
- if (Init.Failed ())
5807
- return ExprError ();
5808
-
5809
- ExprResult Result = Init.Perform (Self, To, Kind, From);
5810
- if (Result.isInvalid () || SFINAE.hasErrorOccurred ())
5811
- return ExprError ();
5812
-
5813
- return Result;
5814
- }
5815
-
5816
5746
static bool EvaluateBooleanTypeTrait (Sema &S, TypeTrait Kind,
5817
5747
SourceLocation KWLoc,
5818
5748
ArrayRef<TypeSourceInfo *> Args,
@@ -5934,9 +5864,8 @@ static bool EvaluateBooleanTypeTrait(Sema &S, TypeTrait Kind,
5934
5864
S.Context .getPointerType (T.getNonReferenceType ()));
5935
5865
TypeSourceInfo *UPtr = S.Context .CreateTypeSourceInfo (
5936
5866
S.Context .getPointerType (U.getNonReferenceType ()));
5937
- return !CheckConvertibilityForTypeTraits (S, UPtr, TPtr, RParenLoc,
5938
- OpaqueExprAllocator)
5939
- .isInvalid ();
5867
+ return S.BuiltinIsConvertible (UPtr->getType (), TPtr->getType (),
5868
+ RParenLoc);
5940
5869
}
5941
5870
5942
5871
if (Kind == clang::TT_IsNothrowConstructible)
@@ -6167,20 +6096,9 @@ static bool EvaluateBinaryTypeTrait(Sema &Self, TypeTrait BTT, const TypeSourceI
6167
6096
}
6168
6097
case BTT_IsConvertible:
6169
6098
case BTT_IsConvertibleTo:
6170
- case BTT_IsNothrowConvertible: {
6171
- if (RhsT->isVoidType ())
6172
- return LhsT->isVoidType ();
6173
- llvm::BumpPtrAllocator OpaqueExprAllocator;
6174
- ExprResult Result = CheckConvertibilityForTypeTraits (Self, Lhs, Rhs, KeyLoc,
6175
- OpaqueExprAllocator);
6176
- if (Result.isInvalid ())
6177
- return false ;
6178
-
6179
- if (BTT != BTT_IsNothrowConvertible)
6180
- return true ;
6181
-
6182
- return Self.canThrow (Result.get ()) == CT_Cannot;
6183
- }
6099
+ case BTT_IsNothrowConvertible:
6100
+ return Self.BuiltinIsConvertible (LhsT, RhsT, KeyLoc,
6101
+ BTT == BTT_IsNothrowConvertible);
6184
6102
6185
6103
case BTT_IsAssignable:
6186
6104
case BTT_IsNothrowAssignable:
0 commit comments