From f86fcb341116e72c5497e6b57695f46eca5f29e9 Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Sat, 24 Apr 2010 21:09:25 +0000 Subject: [PATCH] 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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@102271 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Basic/DiagnosticSemaKinds.td | 4 +++- lib/Sema/SemaInit.cpp | 6 +++++- 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; } + +namespace TemporaryObjectCopy { + // Make sure we instantiate classes when we create a temporary copy. + template + struct X { + X(T); + }; + + template + void f(T t) { + const X &x = X(t); + } + + template void f(int); +} -- 2.40.0