From patchwork Tue May 24 03:46:52 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 97120 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 89C07B6FB3 for ; Tue, 24 May 2011 13:47:13 +1000 (EST) Received: (qmail 28697 invoked by alias); 24 May 2011 03:47:11 -0000 Received: (qmail 28682 invoked by uid 22791); 24 May 2011 03:47:11 -0000 X-SWARE-Spam-Status: No, hits=-6.3 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, SPF_HELO_PASS, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 24 May 2011 03:46:54 +0000 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p4O3krvP008227 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 23 May 2011 23:46:53 -0400 Received: from [127.0.0.1] ([10.3.113.3]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p4O3kqmu030043 for ; Mon, 23 May 2011 23:46:53 -0400 Message-ID: <4DDB2A2C.9050805@redhat.com> Date: Mon, 23 May 2011 23:46:52 -0400 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.17) Gecko/20110428 Fedora/3.1.10-1.fc14 Lightning/1.0b2 Thunderbird/3.1.10 MIME-Version: 1.0 To: gcc-patches List Subject: C++ PATCH for c++/49102 (missing error with private defaulted copy ctor and ellipsis) Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org In this case, the copy constructor is trivial, so we don't complain about having a non-trivial copy constructor. But we should still be doing the lvalue-rvalue conversion, which strictly speaking involves a copy constructor call. Tested x86_64-pc-linux-gnu, applying to trunk. commit a3138b14669986fe312a9579e79edcf091026eec Author: Jason Merrill Date: Mon May 23 13:52:01 2011 -0400 PR c++/49102 * call.c (convert_arg_to_ellipsis): Call force_rvalue. diff --git a/gcc/cp/call.c b/gcc/cp/call.c index 8503f5e..ff3dc06 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -5905,10 +5905,13 @@ convert_arg_to_ellipsis (tree arg) /* In a template (or ill-formed code), we can have an incomplete type even after require_complete_type, in which case we don't know whether it has trivial copy or not. */ - && COMPLETE_TYPE_P (arg_type) - && (type_has_nontrivial_copy_init (arg_type) - || TYPE_HAS_NONTRIVIAL_DESTRUCTOR (arg_type))) + && COMPLETE_TYPE_P (arg_type)) { + /* Build up a real lvalue-to-rvalue conversion in case the + copy constructor is trivial but not callable. */ + if (CLASS_TYPE_P (arg_type)) + force_rvalue (arg, tf_warning_or_error); + /* [expr.call] 5.2.2/7: Passing a potentially-evaluated argument of class type (Clause 9) with a non-trivial copy constructor or a non-trivial destructor @@ -5920,7 +5923,9 @@ convert_arg_to_ellipsis (tree arg) If the call appears in the context of a sizeof expression, it is not potentially-evaluated. */ - if (cp_unevaluated_operand == 0) + if (cp_unevaluated_operand == 0 + && (type_has_nontrivial_copy_init (arg_type) + || TYPE_HAS_NONTRIVIAL_DESTRUCTOR (arg_type))) error ("cannot pass objects of non-trivially-copyable " "type %q#T through %<...%>", arg_type); } diff --git a/gcc/testsuite/g++.dg/cpp0x/defaulted28.C b/gcc/testsuite/g++.dg/cpp0x/defaulted28.C new file mode 100644 index 0000000..15caef6 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/defaulted28.C @@ -0,0 +1,15 @@ +// PR c++/49102 +// { dg-options -std=c++0x } + +struct A { + A() = default; + +private: + A(A const&) = default; // { dg-error "private" } +}; + +void f(...) { } +int main() { + A a; + f(a); // { dg-error "this context" } +}