From patchwork Sun Oct 2 21:41:49 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 117380 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 0BBE2B6F76 for ; Mon, 3 Oct 2011 08:42:07 +1100 (EST) Received: (qmail 28508 invoked by alias); 2 Oct 2011 21:42:06 -0000 Received: (qmail 28499 invoked by uid 22791); 2 Oct 2011 21:42:05 -0000 X-SWARE-Spam-Status: No, hits=-6.7 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, SPF_HELO_PASS 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; Sun, 02 Oct 2011 21:41:51 +0000 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p92LfpPh029076 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Sun, 2 Oct 2011 17:41:51 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id p92Lfp1I000967 for ; Sun, 2 Oct 2011 17:41:51 -0400 Received: from [0.0.0.0] (ovpn-113-54.phx2.redhat.com [10.3.113.54]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id p92LfoNp009161 for ; Sun, 2 Oct 2011 17:41:50 -0400 Message-ID: <4E88DA9D.4060203@redhat.com> Date: Sun, 02 Oct 2011 17:41:49 -0400 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; Linux i686; rv:6.0.2) Gecko/20110906 Thunderbird/6.0.2 MIME-Version: 1.0 To: gcc-patches List Subject: C++ PATCH for some NSDMI bugs 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 template and non-template versions of this test run into different bugs: the template version crashes in noexcept checking because the initializer hasn't been instantiated, and the non-template version crashes in fixed_type_or_null because current_function_decl is null. Tested x86_64-pc-linux-gnu, applying to trunk. commit 990d1177f59f12fbf8bf73a215b6e43bf4b27583 Author: Jason Merrill Date: Sun Oct 2 17:02:44 2011 -0400 * class.c (fixed_type_or_null): Handle NSDMI. * method.c (walk_field_subobs): Disable NSDMI noexcept checking for now. diff --git a/gcc/cp/class.c b/gcc/cp/class.c index a7d8218..2df9177 100644 --- a/gcc/cp/class.c +++ b/gcc/cp/class.c @@ -6062,10 +6062,13 @@ fixed_type_or_null (tree instance, int *nonnull, int *cdtorp) if (nonnull) *nonnull = 1; - /* if we're in a ctor or dtor, we know our type. */ - if (DECL_LANG_SPECIFIC (current_function_decl) - && (DECL_CONSTRUCTOR_P (current_function_decl) - || DECL_DESTRUCTOR_P (current_function_decl))) + /* if we're in a ctor or dtor, we know our type. If + current_class_ptr is set but we aren't in a function, we're in + an NSDMI (and therefore a constructor). */ + if (current_scope () != current_function_decl + || (DECL_LANG_SPECIFIC (current_function_decl) + && (DECL_CONSTRUCTOR_P (current_function_decl) + || DECL_DESTRUCTOR_P (current_function_decl)))) { if (cdtorp) *cdtorp = 1; diff --git a/gcc/cp/method.c b/gcc/cp/method.c index 1316dfb..f4a3ea6 100644 --- a/gcc/cp/method.c +++ b/gcc/cp/method.c @@ -1042,12 +1042,16 @@ walk_field_subobs (tree fields, tree fnname, special_function_kind sfk, inform (0, "initializer for %q+#D is invalid", field); if (trivial_p) *trivial_p = false; +#if 0 /* Core 1351: If the field has an NSDMI that could throw, the default constructor is noexcept(false). FIXME this is - broken by deferred parsing and 1360 saying we can't - lazily declare a non-trivial default constructor. */ + broken by deferred parsing and 1360 saying we can't lazily + declare a non-trivial default constructor. Also this + needs to do deferred instantiation. Disable until the + conflict between 1351 and 1360 is resolved. */ if (spec_p && !expr_noexcept_p (DECL_INITIAL (field), complain)) *spec_p = noexcept_false_spec; +#endif /* Don't do the normal processing. */ continue; diff --git a/gcc/testsuite/g++.dg/cpp0x/nsdmi5.C b/gcc/testsuite/g++.dg/cpp0x/nsdmi5.C new file mode 100644 index 0000000..62803b0 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/nsdmi5.C @@ -0,0 +1,20 @@ +// { dg-options -std=c++0x } + +struct X +{ + int x = 5; + int f() { return x; } +}; +struct Y : X +{ + int y = this->x; +}; +template struct Z : T +{ + int y = this->f(); +}; +int main() +{ + Y foo; + Z bar; +}