diff options
-rw-r--r-- | include/clang/Basic/DiagnosticSemaKinds.td | 4 | ||||
-rw-r--r-- | lib/Sema/SemaInit.cpp | 6 | ||||
-rw-r--r-- | test/SemaTemplate/instantiate-complete.cpp | 15 |
3 files changed, 23 insertions, 2 deletions
diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index d26566684b..aa1e062b31 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -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 " diff --git a/lib/Sema/SemaInit.cpp b/lib/Sema/SemaInit.cpp index d552b16399..ea430bbd3e 100644 --- a/lib/Sema/SemaInit.cpp +++ b/lib/Sema/SemaInit.cpp @@ -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( diff --git a/test/SemaTemplate/instantiate-complete.cpp b/test/SemaTemplate/instantiate-complete.cpp index bc91112497..d854c9e6aa 100644 --- a/test/SemaTemplate/instantiate-complete.cpp +++ b/test/SemaTemplate/instantiate-complete.cpp @@ -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); +} |