From patchwork Tue Aug 30 15:26:24 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 112354 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 7BC39B6F7D for ; Wed, 31 Aug 2011 01:26:47 +1000 (EST) Received: (qmail 24669 invoked by alias); 30 Aug 2011 15:26:45 -0000 Received: (qmail 24660 invoked by uid 22791); 30 Aug 2011 15:26:44 -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; Tue, 30 Aug 2011 15:26:30 +0000 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p7UFQTnK027243 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 30 Aug 2011 11:26:29 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id p7UFQTQJ014713 for ; Tue, 30 Aug 2011 11:26:29 -0400 Received: from [0.0.0.0] (ovpn-113-136.phx2.redhat.com [10.3.113.136]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id p7UFQSO9032680 for ; Tue, 30 Aug 2011 11:26:28 -0400 Message-ID: <4E5D0120.7080903@redhat.com> Date: Tue, 30 Aug 2011 11:26:24 -0400 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; Linux i686; rv:6.0) Gecko/20110817 Thunderbird/6.0 MIME-Version: 1.0 To: gcc-patches List Subject: C++ PATCH for c++/50234 (ICE with constexpr and empty init-list) 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 This is basically the same as c++/49924, but for classes instead of arrays: if there is no explicit initializer written in the init-list, the member is value-initialized. Tested x86_64-pc-linux-gnu, applying to trunk and 4.6. commit eccc1f7f9987a394dcf9856d43244a95c51bc880 Author: Jason Merrill Date: Tue Aug 30 10:28:05 2011 -0400 PR c++/50234 * semantics.c (cxx_eval_component_reference): Handle value-initialization for omitted initializers. diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index 07f53b5..1ad991f 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -6518,7 +6518,8 @@ cxx_eval_component_reference (const constexpr_call *call, tree t, if (field == part) return value; } - if (TREE_CODE (TREE_TYPE (whole)) == UNION_TYPE) + if (TREE_CODE (TREE_TYPE (whole)) == UNION_TYPE + && CONSTRUCTOR_NELTS (whole) > 0) { /* DR 1188 says we don't have to deal with this. */ if (!allow_non_constant) @@ -6527,8 +6528,12 @@ cxx_eval_component_reference (const constexpr_call *call, tree t, *non_constant_p = true; return t; } - gcc_unreachable(); - return error_mark_node; + + /* If there's no explicit init for this field, it's value-initialized. */ + value = build_value_init (TREE_TYPE (t), tf_warning_or_error); + return cxx_eval_constant_expression (call, value, + allow_non_constant, addr, + non_constant_p); } /* Subroutine of cxx_eval_constant_expression. diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-value3.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-value3.C new file mode 100644 index 0000000..38d8993 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-value3.C @@ -0,0 +1,10 @@ +// PR c++/50234 +// { dg-options -std=c++0x } + +#define SA(X) static_assert((X),#X) + +struct A { int i; }; + +constexpr int f(A a) { return a.i; } + +SA(f({}) == 0);