From patchwork Fri Mar 25 16:15:01 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 88395 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 A0D56B6F86 for ; Sat, 26 Mar 2011 03:15:18 +1100 (EST) Received: (qmail 2114 invoked by alias); 25 Mar 2011 16:15:13 -0000 Received: (qmail 2026 invoked by uid 22791); 25 Mar 2011 16:15:12 -0000 X-SWARE-Spam-Status: No, hits=-6.2 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, SPF_HELO_PASS, TW_FN, 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; Fri, 25 Mar 2011 16:15:05 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p2PGF3uR008695 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 25 Mar 2011 12:15:04 -0400 Received: from [127.0.0.1] (ovpn-113-150.phx2.redhat.com [10.3.113.150]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p2PGF21E023872 for ; Fri, 25 Mar 2011 12:15:02 -0400 Message-ID: <4D8CBF85.10509@redhat.com> Date: Fri, 25 Mar 2011 17:15:01 +0100 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.15) Gecko/20110307 Fedora/3.1.9-0.39.b3pre.fc14 Lightning/1.0b2 Thunderbird/3.1.9 MIME-Version: 1.0 To: gcc-patches List Subject: C++ PATCH for core issue 1135 (virtual and exception-specifications with default) 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 The resolution of core issue 1135 allows defaulted functions to be declared virtual or with an exception specification that matches the one on an implicit declaration; this patch implements that. Tested x86_64-pc-linux-gnu, applied to trunk. commit c0337ba692c6eadc1d63b96a80b71ac1d59b0e51 Author: Jason Merrill Date: Fri Mar 25 16:04:09 2011 +0100 Core 1135 * method.c (defaulted_late_check): Check for exception spec mismatch. (defaultable_fn_check): Allow exception spec and virtual. * class.c (check_for_override): A virtual dtor is non-trivial. diff --git a/gcc/cp/class.c b/gcc/cp/class.c index 1325260..adae51f 100644 --- a/gcc/cp/class.c +++ b/gcc/cp/class.c @@ -2474,6 +2474,8 @@ check_for_override (tree decl, tree ctype) if (!DECL_VINDEX (decl)) DECL_VINDEX (decl) = error_mark_node; IDENTIFIER_VIRTUAL_P (DECL_NAME (decl)) = 1; + if (DECL_DESTRUCTOR_P (decl)) + TYPE_HAS_NONTRIVIAL_DESTRUCTOR (ctype) = true; } } diff --git a/gcc/cp/method.c b/gcc/cp/method.c index 0366988..386a818 100644 --- a/gcc/cp/method.c +++ b/gcc/cp/method.c @@ -1554,6 +1554,12 @@ defaulted_late_check (tree fn) if (DECL_DEFAULTED_IN_CLASS_P (fn)) { tree eh_spec = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (implicit_fn)); + if (TYPE_RAISES_EXCEPTIONS (TREE_TYPE (fn)) + && !comp_except_specs (TYPE_RAISES_EXCEPTIONS (TREE_TYPE (fn)), + eh_spec, ce_normal)) + error ("function %q+D defaulted on its first declaration " + "with an exception-specification that differs from " + "the implicit declaration %q#D", fn, implicit_fn); TREE_TYPE (fn) = build_exception_variant (TREE_TYPE (fn), eh_spec); if (DECL_DECLARED_CONSTEXPR_P (implicit_fn)) /* Hmm...should we do this for out-of-class too? Should it be OK to @@ -1619,14 +1625,7 @@ defaultable_fn_check (tree fn) break; } if (TYPE_BEING_DEFINED (DECL_CONTEXT (fn))) - { - if (TYPE_RAISES_EXCEPTIONS (TREE_TYPE (fn))) - error ("function %q+D defaulted on its first declaration " - "must not have an exception-specification", fn); - if (DECL_VIRTUAL_P (fn)) - error ("%qD declared virtual cannot be defaulted in the class " - "body", fn); - } + /* Defer checking. */; else if (!processing_template_decl) defaulted_late_check (fn); diff --git a/gcc/testsuite/g++.dg/cpp0x/defaulted15.C b/gcc/testsuite/g++.dg/cpp0x/defaulted15.C index 4c5b11c..0a47c20 100644 --- a/gcc/testsuite/g++.dg/cpp0x/defaulted15.C +++ b/gcc/testsuite/g++.dg/cpp0x/defaulted15.C @@ -54,5 +54,5 @@ struct G: public F struct H { - virtual ~H() = default; // { dg-error "declared virtual" } + virtual ~H() = default; }; diff --git a/gcc/testsuite/g++.dg/cpp0x/defaulted22.C b/gcc/testsuite/g++.dg/cpp0x/defaulted22.C new file mode 100644 index 0000000..61e9d32 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/defaulted22.C @@ -0,0 +1,23 @@ +// Test that a virtual defaulted constructor is still virtual. +// { dg-do run } +// { dg-options -std=c++0x } + +int r = 1; + +struct A +{ + virtual ~A() = default; +}; + +struct B: A +{ + ~B() noexcept { r = 0; } +}; + +A* ap = new B(); + +int main() +{ + delete ap; + return r; +} diff --git a/gcc/testsuite/g++.dg/cpp0x/defaulted23.C b/gcc/testsuite/g++.dg/cpp0x/defaulted23.C new file mode 100644 index 0000000..5b4438d --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/defaulted23.C @@ -0,0 +1,27 @@ +// Test for checking of exception specifications on defaulted fns +// { dg-options -std=c++0x } + +struct A +{ + A() noexcept = default; +}; + +struct B +{ + B() throw (int) = default; // { dg-error "exception-specification that differs from the implicit declaration" } +}; + +struct C +{ + C() throw (int) { } +}; + +struct D: C +{ + D() throw (int) = default; +}; + +struct E +{ + E() = default; +};