From patchwork Fri Oct 14 17:57:20 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 119882 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 F2DE0B6FA2 for ; Sat, 15 Oct 2011 04:57:42 +1100 (EST) Received: (qmail 8453 invoked by alias); 14 Oct 2011 17:57:39 -0000 Received: (qmail 8440 invoked by uid 22791); 14 Oct 2011 17:57:36 -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; Fri, 14 Oct 2011 17:57:23 +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 p9EHvMuh013433 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 14 Oct 2011 13:57:22 -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 p9EHvMXV014993 for ; Fri, 14 Oct 2011 13:57:22 -0400 Received: from [0.0.0.0] (ovpn-113-74.phx2.redhat.com [10.3.113.74]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id p9EHvKcs018714 for ; Fri, 14 Oct 2011 13:57:21 -0400 Message-ID: <4E987800.1090107@redhat.com> Date: Fri, 14 Oct 2011 13:57:20 -0400 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; Linux i686; rv:7.0.1) Gecko/20111001 Thunderbird/7.0.1 MIME-Version: 1.0 To: gcc-patches List Subject: C++ PATCH for c++/50507 (NSDMI for const field) 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 We should check for an initializer before complaining about lack thereof. :) Tested x86_64-pc-linux-gnu, applying to trunk. commit fc150101bb79b3b328263e272a44eecd1083e6cd Author: Jason Merrill Date: Thu Oct 13 21:57:21 2011 -0400 PR c++/50507 * method.c (walk_field_subobs): Check for NSDMI before complaining about uninitialized fields. diff --git a/gcc/cp/method.c b/gcc/cp/method.c index f4a3ea6..0718f47 100644 --- a/gcc/cp/method.c +++ b/gcc/cp/method.c @@ -1016,25 +1016,7 @@ walk_field_subobs (tree fields, tree fnname, special_function_kind sfk, } else if (sfk == sfk_constructor) { - bool bad = true; - if (CP_TYPE_CONST_P (mem_type) - && default_init_uninitialized_part (mem_type)) - { - if (msg) - error ("uninitialized non-static const member %q#D", - field); - } - else if (TREE_CODE (mem_type) == REFERENCE_TYPE) - { - if (msg) - error ("uninitialized non-static reference member %q#D", - field); - } - else - bad = false; - - if (bad && deleted_p) - *deleted_p = true; + bool bad; if (DECL_INITIAL (field)) { @@ -1057,6 +1039,26 @@ walk_field_subobs (tree fields, tree fnname, special_function_kind sfk, continue; } + bad = false; + if (CP_TYPE_CONST_P (mem_type) + && default_init_uninitialized_part (mem_type)) + { + if (msg) + error ("uninitialized non-static const member %q#D", + field); + bad = true; + } + else if (TREE_CODE (mem_type) == REFERENCE_TYPE) + { + if (msg) + error ("uninitialized non-static reference member %q#D", + field); + bad = true; + } + + if (bad && deleted_p) + *deleted_p = true; + /* For an implicitly-defined default constructor to be constexpr, every member must have a user-provided default constructor or an explicit initializer. */ diff --git a/gcc/testsuite/g++.dg/cpp0x/nsdmi-const1.C b/gcc/testsuite/g++.dg/cpp0x/nsdmi-const1.C new file mode 100644 index 0000000..ddf9f04 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/nsdmi-const1.C @@ -0,0 +1,10 @@ +// PR c++/50707 +// { dg-options -std=c++0x } + +int g; + +struct S { + int const v=g; +}; + +S s;