[cfe-commits] r102271 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaInit.cpp test/SemaTemplate/instantiate-complete.cpp

Douglas Gregor dgregor at apple.com
Sat Apr 24 14:09:25 PDT 2010


Author: dgregor
Date: Sat Apr 24 16:09:25 2010
New Revision: 102271

URL: http://llvm.org/viewvc/llvm-project?rev=102271&view=rev
Log:
When we attempt to create a temporary object of class type, be sure
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.

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

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=102271&r1=102270&r2=102271&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Sat Apr 24 16:09:25 2010
@@ -720,7 +720,9 @@
   "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 "

Modified: cfe/trunk/lib/Sema/SemaInit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaInit.cpp?rev=102271&r1=102270&r2=102271&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaInit.cpp (original)
+++ cfe/trunk/lib/Sema/SemaInit.cpp Sat Apr 24 16:09:25 2010
@@ -3232,7 +3232,11 @@
     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(

Modified: cfe/trunk/test/SemaTemplate/instantiate-complete.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/instantiate-complete.cpp?rev=102271&r1=102270&r2=102271&view=diff
==============================================================================
--- cfe/trunk/test/SemaTemplate/instantiate-complete.cpp (original)
+++ cfe/trunk/test/SemaTemplate/instantiate-complete.cpp Sat Apr 24 16:09:25 2010
@@ -84,3 +84,18 @@
 
   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);
+}





More information about the cfe-commits mailing list