]> granicus.if.org Git - clang/commitdiff
When we attempt to create a temporary object of class type, be sure
authorDouglas Gregor <dgregor@apple.com>
Sat, 24 Apr 2010 21:09:25 +0000 (21:09 +0000)
committerDouglas Gregor <dgregor@apple.com>
Sat, 24 Apr 2010 21:09:25 +0000 (21:09 +0000)
that the type we're copying is complete.

Boost.Regex now builds, although it's failing its regression tests
with our favorite "Sema doesn't consider destructor as used."
assertion.

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

include/clang/Basic/DiagnosticSemaKinds.td
lib/Sema/SemaInit.cpp
test/SemaTemplate/instantiate-complete.cpp

index d26566684b5b4e391a54a17e0820803546fdec51..aa1e062b313afbd8989fd9bff662b00eb59df511 100644 (file)
@@ -720,7 +720,9 @@ def err_temp_copy_deleted : Error<
   "object|copying member subobject|copying array element|allocating object|"
   "copying temporary|initializing base subobject|initializing vector element}0 "
   "of type %1 invokes deleted constructor">;
-  
+def err_temp_copy_incomplete : Error<
+  "copying a temporary object of incomplete type %0">;
+
 // C++0x decltype
 def err_cannot_determine_declared_type_of_overloaded_function : Error<
     "cannot determine the %select{type|declared type}0 of an overloaded "
index d552b163994c520a579ba610fa04b98463d42cbf..ea430bbd3ebe45dda1d930868a86a29d5272c972 100644 (file)
@@ -3232,7 +3232,11 @@ static Sema::OwningExprResult CopyObject(Sema &S,
     Loc = CurInitExpr->getLocStart();
     break;
   }
-    
+
+  // Make sure that the type we are copying is complete.   
+  if (S.RequireCompleteType(Loc, T, S.PDiag(diag::err_temp_copy_incomplete)))
+    return move(CurInit);
+
   // Perform overload resolution using the class's copy constructors.
   DeclarationName ConstructorName
     = S.Context.DeclarationNames.getCXXConstructorName(
index bc91112497de2d53d7c4a2519647afd244d348ae..d854c9e6aacc83a0858e7a694d9fb4220debb981 100644 (file)
@@ -84,3 +84,18 @@ namespace PR6376 {
 
   template struct Y<int, float>;
 }
+
+namespace TemporaryObjectCopy {
+  // Make sure we instantiate classes when we create a temporary copy.
+  template<typename T>
+  struct X {
+    X(T); 
+  };
+
+  template<typename T>
+  void f(T t) {
+    const X<int> &x = X<int>(t);
+  }
+
+  template void f(int);
+}