[cfe-commits] r161828 - in /cfe/trunk: lib/Sema/SemaDeclCXX.cpp lib/Sema/SemaExprCXX.cpp test/SemaCXX/type-traits.cpp
Eli Friedman
eli.friedman at gmail.com
Mon Aug 13 19:06:08 PDT 2012
Author: efriedma
Date: Mon Aug 13 21:06:07 2012
New Revision: 161828
URL: http://llvm.org/viewvc/llvm-project?rev=161828&view=rev
Log:
Make __is_convertible_to handle abstract types correctly. PR13591.
Modified:
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
cfe/trunk/lib/Sema/SemaExprCXX.cpp
cfe/trunk/test/SemaCXX/type-traits.cpp
Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=161828&r1=161827&r2=161828&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Mon Aug 13 21:06:07 2012
@@ -3478,6 +3478,7 @@
: TypeDiagnoser(DiagID == 0), DiagID(DiagID), SelID(SelID) { }
virtual void diagnose(Sema &S, SourceLocation Loc, QualType T) {
+ if (Suppressed) return;
if (SelID == -1)
S.Diag(Loc, DiagID) << T;
else
Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=161828&r1=161827&r2=161828&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Mon Aug 13 21:06:07 2012
@@ -3542,9 +3542,25 @@
// We model the initialization as a copy-initialization of a temporary
// of the appropriate type, which for this expression is identical to the
// return statement (since NRVO doesn't apply).
+
+ // Functions aren't allowed to return function or array types.
+ if (RhsT->isFunctionType() || RhsT->isArrayType())
+ return false;
+
+ // A return statement in a void function must have void type.
+ if (RhsT->isVoidType())
+ return LhsT->isVoidType();
+
+ // A function definition requires a complete, non-abstract return type.
+ if (Self.RequireCompleteType(KeyLoc, RhsT, 0) ||
+ Self.RequireNonAbstractType(KeyLoc, RhsT, 0))
+ return false;
+
+ // Compute the result of add_rvalue_reference.
if (LhsT->isObjectType() || LhsT->isFunctionType())
LhsT = Self.Context.getRValueReferenceType(LhsT);
-
+
+ // Build a fake source and destination for initialization.
InitializedEntity To(InitializedEntity::InitializeTemporary(RhsT));
OpaqueValueExpr From(KeyLoc, LhsT.getNonLValueExprType(Self.Context),
Expr::getValueKindForType(LhsT));
Modified: cfe/trunk/test/SemaCXX/type-traits.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/type-traits.cpp?rev=161828&r1=161827&r2=161828&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/type-traits.cpp (original)
+++ cfe/trunk/test/SemaCXX/type-traits.cpp Mon Aug 13 21:06:07 2012
@@ -1574,6 +1574,8 @@
template<typename U> X0(const X0<U>&);
};
+struct Abstract { virtual void f() = 0; };
+
void is_convertible_to() {
{ int arr[T(__is_convertible_to(Int, Int))]; }
{ int arr[F(__is_convertible_to(Int, IntAr))]; }
@@ -1598,6 +1600,7 @@
{ int arr[F(__is_convertible_to(Function, Function))]; }
{ int arr[F(__is_convertible_to(PrivateCopy, PrivateCopy))]; }
{ int arr[T(__is_convertible_to(X0<int>, X0<float>))]; }
+ { int arr[F(__is_convertible_to(Abstract, Abstract))]; }
}
namespace is_convertible_to_instantiate {
More information about the cfe-commits
mailing list