]> granicus.if.org Git - clang/commitdiff
When we're type-checking the result of calling a conversion function
authorDouglas Gregor <dgregor@apple.com>
Sat, 13 Nov 2010 19:36:57 +0000 (19:36 +0000)
committerDouglas Gregor <dgregor@apple.com>
Sat, 13 Nov 2010 19:36:57 +0000 (19:36 +0000)
(while computing user conversion sequences), make sure that a result
of class type is a complete class type. Had we gone through
ActOnCallExpr, this would have happened when we built the CallExpr.

Fixes PR8425.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@119005 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaOverload.cpp
test/SemaTemplate/instantiate-complete.cpp

index d82f8854080cd92a85e3bb7caf0e12e08d46e3fc..f8c6f6971da13acd2394fac5a98d2494bd7c6af3 100644 (file)
@@ -3877,11 +3877,18 @@ Sema::AddConversionCandidate(CXXConversionDecl *Conversion,
                                 CK_FunctionToPointerDecay,
                                 &ConversionRef, VK_RValue);
 
+  QualType CallResultType
+    = Conversion->getConversionType().getNonLValueExprType(Context);
+  if (RequireCompleteType(From->getLocStart(), CallResultType, 0)) {
+    Candidate.Viable = false;
+    Candidate.FailureKind = ovl_fail_bad_final_conversion;
+    return;
+  }
+
   // Note that it is safe to allocate CallExpr on the stack here because
   // there are 0 arguments (i.e., nothing is allocated using ASTContext's
   // allocator).
-  CallExpr Call(Context, &ConversionFn, 0, 0,
-                Conversion->getConversionType().getNonLValueExprType(Context),
+  CallExpr Call(Context, &ConversionFn, 0, 0, CallResultType, 
                 From->getLocStart());
   ImplicitConversionSequence ICS =
     TryCopyInitialization(*this, &Call, ToType,
index 91d4d327073ed4e1136c42945de59f757467ee77..4b27da7349f9b533d41bb5fb1b35f249fbccd5b9 100644 (file)
@@ -126,3 +126,23 @@ namespace pr7199 {
 
   template class B<int>; // expected-note {{in instantiation}}
 }
+
+namespace PR8425 {
+  template <typename T>
+  class BaseT {};
+
+  template <typename T>
+  class DerivedT : public BaseT<T> {};
+
+  template <typename T>
+  class FromT {
+  public:
+    operator DerivedT<T>() const { return DerivedT<T>(); }
+  };
+
+  void test() {
+    FromT<int> ft;
+    BaseT<int> bt(ft);
+  }
+}
+