From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 12550 invoked by alias); 24 Jun 2014 21:35:51 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 12530 invoked by uid 89); 24 Jun 2014 21:35:48 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.3 required=5.0 tests=AWL,BAYES_00,SPF_PASS,T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: aserp1040.oracle.com Received: from aserp1040.oracle.com (HELO aserp1040.oracle.com) (141.146.126.69) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA encrypted) ESMTPS; Tue, 24 Jun 2014 21:35:46 +0000 Received: from ucsinet21.oracle.com (ucsinet21.oracle.com [156.151.31.93]) by aserp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id s5OLZg2p015751 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 24 Jun 2014 21:35:43 GMT Received: from userz7022.oracle.com (userz7022.oracle.com [156.151.31.86]) by ucsinet21.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id s5OLZgEb012986 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Tue, 24 Jun 2014 21:35:42 GMT Received: from abhmp0020.oracle.com (abhmp0020.oracle.com [141.146.116.26]) by userz7022.oracle.com (8.14.5+Sun/8.14.4) with ESMTP id s5OLZelc028159; Tue, 24 Jun 2014 21:35:41 GMT Received: from [192.168.1.4] (/79.3.231.38) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 24 Jun 2014 14:35:40 -0700 Message-ID: <53A9EE61.5010402@oracle.com> Date: Tue, 24 Jun 2014 21:35:00 -0000 From: Paolo Carlini User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.5.0 MIME-Version: 1.0 To: "gcc-patches@gcc.gnu.org" CC: Jason Merrill Subject: [C++ Patch/RFC] PR 49132 Content-Type: multipart/mixed; boundary="------------080002020503050908070102" X-IsSubscribed: yes X-SW-Source: 2014-06/txt/msg01947.txt.bz2 This is a multi-part message in MIME format. --------------080002020503050908070102 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-length: 422 Hi, this remained unresolved for a long time, but, if I understand correctly Jason' Comment 1, should be rather easy, just do not complain for uninitialized const members in aggregates, recursively too (per struct B in the testcases). Does the below makes sense, then?!? It passes testing, anyway. I'm also taking the occasion to guard the warnings with complain & tf_warning. Thanks, Paolo. ///////////////////// --------------080002020503050908070102 Content-Type: text/plain; charset=UTF-8; name="patch_49132" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="patch_49132" Content-length: 2492 Index: cp/typeck2.c =================================================================== --- cp/typeck2.c (revision 211955) +++ cp/typeck2.c (working copy) @@ -1342,28 +1342,15 @@ process_init_constructor_record (tree type, tree i next = massage_init_elt (TREE_TYPE (field), next, complain); /* Warn when some struct elements are implicitly initialized. */ - warning (OPT_Wmissing_field_initializers, - "missing initializer for member %qD", field); + if (complain & tf_warning) + warning (OPT_Wmissing_field_initializers, + "missing initializer for member %qD", field); } else { - if (TREE_READONLY (field)) + if (TREE_CODE (TREE_TYPE (field)) == REFERENCE_TYPE) { if (complain & tf_error) - error ("uninitialized const member %qD", field); - else - return PICFLAG_ERRONEOUS; - } - else if (CLASSTYPE_READONLY_FIELDS_NEED_INIT (TREE_TYPE (field))) - { - if (complain & tf_error) - error ("member %qD with uninitialized const fields", field); - else - return PICFLAG_ERRONEOUS; - } - else if (TREE_CODE (TREE_TYPE (field)) == REFERENCE_TYPE) - { - if (complain & tf_error) error ("member %qD is uninitialized reference", field); else return PICFLAG_ERRONEOUS; @@ -1371,8 +1358,9 @@ process_init_constructor_record (tree type, tree i /* Warn when some struct elements are implicitly initialized to zero. */ - warning (OPT_Wmissing_field_initializers, - "missing initializer for member %qD", field); + if (complain & tf_warning) + warning (OPT_Wmissing_field_initializers, + "missing initializer for member %qD", field); if (!zero_init_p (TREE_TYPE (field))) next = build_zero_init (TREE_TYPE (field), /*nelts=*/NULL_TREE, Index: testsuite/g++.dg/cpp0x/aggr1.C =================================================================== --- testsuite/g++.dg/cpp0x/aggr1.C (revision 0) +++ testsuite/g++.dg/cpp0x/aggr1.C (working copy) @@ -0,0 +1,16 @@ +// PR c++/49132 +// { dg-do compile { target c++11 } } + +struct A { + const int m; +}; + +A a1 = {}; +A a2{}; + +struct B { + A a; +}; + +B b1 = {}; +B b2{}; Index: testsuite/g++.dg/init/aggr11.C =================================================================== --- testsuite/g++.dg/init/aggr11.C (revision 0) +++ testsuite/g++.dg/init/aggr11.C (working copy) @@ -0,0 +1,13 @@ +// PR c++/49132 + +struct A { + const int m; +}; + +A a1 = {}; + +struct B { + A a; +}; + +B b1 = {}; --------------080002020503050908070102--