From patchwork Wed May 11 21:21:19 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 95192 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 1C2C61007D1 for ; Thu, 12 May 2011 08:21:43 +1000 (EST) Received: (qmail 31616 invoked by alias); 11 May 2011 21:21:41 -0000 Received: (qmail 31591 invoked by uid 22791); 11 May 2011 21:21:38 -0000 X-SWARE-Spam-Status: No, hits=-6.3 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, SPF_HELO_PASS, 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; Wed, 11 May 2011 21:21:20 +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 p4BLLKjs017024 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 11 May 2011 17:21:20 -0400 Received: from [127.0.0.1] (ovpn-113-60.phx2.redhat.com [10.3.113.60]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id p4BLLJ1i004958 for ; Wed, 11 May 2011 17:21:20 -0400 Message-ID: <4DCAFDCF.2080507@redhat.com> Date: Wed, 11 May 2011 17:21:19 -0400 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.15) Gecko/20110421 Fedora/3.1.9-2.fc14 Lightning/1.0b2 Thunderbird/3.1.9 MIME-Version: 1.0 To: gcc-patches List Subject: C++ PATCH for c++/48745 (ICE with list-initialization in SFINAE context) 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 Here we just needed to handle CONSTRUCTOR in value_dependent_expression_p. It is also the case that a lot of crashes have been happening because build_non_dependent_expr calls null_ptr_cst_p, which wants to try to get a constant value for any expression. That's not actually necessary for semantics, so we can remove it. But it has been helpful for finding bugs, so I'm going to leave in the call to maybe_constant_value when ENABLE_CHECKING is defined. Tested x86_64-pc-linux-gnu, applying to trunk. commit 05a558e5467af165052855f290f11b20e7009450 Author: Jason Merrill Date: Tue May 10 16:40:54 2011 -0400 PR c++/48745 * pt.c (value_dependent_expr_p): Handle CONSTRUCTOR. diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 5e24977..74d4cbf 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -18273,6 +18273,16 @@ value_dependent_expression_p (tree expression) type-dependent. */ return type_dependent_expression_p (expression); + case CONSTRUCTOR: + { + unsigned ix; + tree val; + FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (expression), ix, val) + if (value_dependent_expression_p (val)) + return true; + return false; + } + default: /* A constant expression is value-dependent if any subexpression is value-dependent. */ diff --git a/gcc/testsuite/g++.dg/cpp0x/sfinae22.C b/gcc/testsuite/g++.dg/cpp0x/sfinae22.C new file mode 100644 index 0000000..1c3efd2 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/sfinae22.C @@ -0,0 +1,23 @@ +// PR c++/48745 +// { dg-options -std=c++0x } + +template +struct add_rval_ref { + typedef T&& type; +}; + +template<> +struct add_rval_ref { + typedef void type; +}; + +template +typename add_rval_ref::type create(); + +template +decltype(T{create()...}, char()) f(int); + +template +char (&f(...))[2]; + +static_assert(sizeof(f(0)) != 1, "Error"); // # commit 98b2007f0a05f07cf79711c1d29cc228cb5e9946 Author: Jason Merrill Date: Tue May 10 16:42:31 2011 -0400 * pt.c (build_non_dependent_expr): Don't check null_ptr_cst_p, do call maybe_constant_value in C++0x mode. * semantics.c (cxx_eval_constant_expression): Handle TEMPLATE_DECL. diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 74d4cbf..4b32ce9 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -18871,10 +18871,13 @@ build_non_dependent_expr (tree expr) { tree inner_expr; - /* Preserve null pointer constants so that the type of things like - "p == 0" where "p" is a pointer can be determined. */ - if (null_ptr_cst_p (expr)) - return expr; +#ifdef ENABLE_CHECKING + /* Try to get a constant value for all non-type-dependent expressions in + order to expose bugs in *_dependent_expression_p and constexpr. */ + if (cxx_dialect >= cxx0x) + maybe_constant_value (fold_non_dependent_expr (expr)); +#endif + /* Preserve OVERLOADs; the functions must be available to resolve types. */ inner_expr = expr; diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index 0ba0370..bfe233e 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -6911,6 +6911,7 @@ cxx_eval_constant_expression (const constexpr_call *call, tree t, break; case FUNCTION_DECL: + case TEMPLATE_DECL: case LABEL_DECL: return t;