From patchwork Wed Feb 16 00:39:36 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 83320 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 80BEBB716A for ; Wed, 16 Feb 2011 11:39:47 +1100 (EST) Received: (qmail 22089 invoked by alias); 16 Feb 2011 00:39:45 -0000 Received: (qmail 22077 invoked by uid 22791); 16 Feb 2011 00:39:44 -0000 X-SWARE-Spam-Status: No, hits=-6.2 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, SPF_HELO_PASS, TW_CX, 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; Wed, 16 Feb 2011 00:39:39 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p1G0dbg7023339 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 15 Feb 2011 19:39:37 -0500 Received: from [127.0.0.1] (ovpn-113-50.phx2.redhat.com [10.3.113.50]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p1G0dbI8022729 for ; Tue, 15 Feb 2011 19:39:37 -0500 Message-ID: <4D5B1CC8.5000303@redhat.com> Date: Tue, 15 Feb 2011 19:39:36 -0500 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.13) Gecko/20101209 Fedora/3.1.7-0.35.b3pre.fc14 Lightning/1.0b2 Thunderbird/3.1.7 MIME-Version: 1.0 To: gcc-patches List Subject: C++ PATCH for c++/46807 (ICE with synthesized ctor and mutable) 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 So, in 4.6 I've started using overload resolution early to determine what constructor will actually be called by a synthesized constructor in order to determine the right exception specification for it. In C++0x mode this can also affect the triviality of the function. But in C++98/03, triviality is not specified in terms of what base constructor would be called, but just whether the base has a trivial copy constructor. This is not terribly consistent, but changing it at this point could cause trouble with existing code. Previously I had been thinking that the overload resolution would always give the same answer as the determination based on simple analysis of the copy constructor; this PR demonstrated that this was wrong. So in C++98 mode we always exit early if the simple analysis decided that the function is trivial; we choose to respect that even if it would differ from the full analysis. This preserves the behavior of previous compiler versions in C++98 mode. Tested x86_64-pc-linux-gnu, applied to trunk. commit 2fd22fda4391675ca08f73223ebfaeaa302561c2 Author: Jason Merrill Date: Mon Feb 14 17:34:47 2011 -0500 PR c++/46807 * method.c (synthesized_method_walk): Always exit early for trivial fn in C++98 mode. diff --git a/gcc/cp/method.c b/gcc/cp/method.c index 3f0baed..bfe8a06 100644 --- a/gcc/cp/method.c +++ b/gcc/cp/method.c @@ -1153,13 +1153,15 @@ synthesized_method_walk (tree ctype, special_function_kind sfk, bool const_p, if (trivial_p) *trivial_p = expected_trivial; -#ifndef ENABLE_CHECKING /* The TYPE_HAS_COMPLEX_* flags tell us about constraints from base class versions and other properties of the type. But a subobject class can be trivially copyable and yet have overload resolution choose a template constructor for initialization, depending on rvalueness and cv-quals. So we can't exit early for copy/move - methods in C++0x. */ + methods in C++0x. The same considerations apply in C++98/03, but + there the definition of triviality does not consider overload + resolution, so a constructor can be trivial even if it would otherwise + call a non-trivial constructor. */ if (expected_trivial && (!copy_arg_p || cxx_dialect < cxx0x)) { @@ -1167,7 +1169,6 @@ synthesized_method_walk (tree ctype, special_function_kind sfk, bool const_p, *constexpr_p = synthesized_default_constructor_is_constexpr (ctype); return; } -#endif ++cp_unevaluated_operand; ++c_inhibit_evaluation_warnings; @@ -1300,14 +1301,6 @@ synthesized_method_walk (tree ctype, special_function_kind sfk, bool const_p, if (spec_p) *spec_p = merge_exception_specifiers (*spec_p, cleanup_spec); } - -#ifdef ENABLE_CHECKING - /* If we expected this to be trivial but it isn't, then either we're in - C++0x mode and this is a copy/move ctor/op= or there's an error. */ - gcc_assert (!(trivial_p && expected_trivial && !*trivial_p) - || (copy_arg_p && cxx_dialect >= cxx0x) - || errorcount); -#endif } /* DECL is a deleted function. If it's implicitly deleted, explain why and diff --git a/gcc/testsuite/g++.dg/cpp0x/implicit-trivial1.C b/gcc/testsuite/g++.dg/cpp0x/implicit-trivial1.C new file mode 100644 index 0000000..64084c1 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/implicit-trivial1.C @@ -0,0 +1,23 @@ +// PR c++/46807 +// { dg-options -std=c++0x } +// In C++98/03, B::B(const B&) is trivial because A::A(const A&) is trivial, +// even though doing overload resolution would mean calling the template +// constructor. In C++0x, we do overload resolution to determine triviality. + +struct A +{ + A() {} +private: + template A(T&); // { dg-error "private" } +}; + +struct B // { dg-error "implicitly deleted|this context" } +{ + mutable A a; +}; + +int main() +{ + B b; + B b2(b); // { dg-error "deleted" } +} diff --git a/gcc/testsuite/g++.dg/inherit/implicit-trivial1.C b/gcc/testsuite/g++.dg/inherit/implicit-trivial1.C new file mode 100644 index 0000000..e63bd34 --- /dev/null +++ b/gcc/testsuite/g++.dg/inherit/implicit-trivial1.C @@ -0,0 +1,23 @@ +// PR c++/46807 +// { dg-options -std=c++98 } +// In C++98/03, B::B(const B&) is trivial because A::A(const A&) is trivial, +// even though doing overload resolution would mean calling the template +// constructor. In C++0x, we do overload resolution to determine triviality. + +struct A +{ + A() {} +private: + template A(T&); +}; + +struct B +{ + mutable A a; +}; + +int main() +{ + B b; + B b2(b); +}