From patchwork Mon Apr 18 00:49:52 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 91645 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 62F7FB6FD8 for ; Mon, 18 Apr 2011 10:50:20 +1000 (EST) Received: (qmail 29533 invoked by alias); 18 Apr 2011 00:50:15 -0000 Received: (qmail 29521 invoked by uid 22791); 18 Apr 2011 00:50:13 -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; Mon, 18 Apr 2011 00:49:54 +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 p3I0nrVG018561 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Sun, 17 Apr 2011 20:49:54 -0400 Received: from [127.0.0.1] (ovpn-113-102.phx2.redhat.com [10.3.113.102]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id p3I0nqi3017078 for ; Sun, 17 Apr 2011 20:49:53 -0400 Message-ID: <4DAB8AB0.70300@redhat.com> Date: Sun, 17 Apr 2011 17:49:52 -0700 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.15) Gecko/20110307 Fedora/3.1.9-0.39.b3pre.fc14 Lightning/1.0b2 Thunderbird/3.1.9 MIME-Version: 1.0 To: gcc-patches List Subject: C++ PATCH for c++/48531 (ICE with value-initialization of array) 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 switch to using build_value_init for value-initialization of non-class types caused us to incorrectly allow functional casts to array type, leading to an ICE. Tested x86_64-pc-linux-gnu, applied to trunk. commit 4c4d50b6852b51cd6a227a09f330a086eb3b1d63 Author: Jason Merrill Date: Sat Apr 16 17:34:10 2011 -0700 PR c++/48531 * typeck2.c (build_functional_cast): Disallow array type. diff --git a/gcc/cp/init.c b/gcc/cp/init.c index fad7f0c..3280d9b 100644 --- a/gcc/cp/init.c +++ b/gcc/cp/init.c @@ -369,6 +369,8 @@ build_value_init (tree type, tsubst_flags_t complain) tree build_value_init_noctor (tree type, tsubst_flags_t complain) { + /* FIXME the class and array cases should just use digest_init once it is + SFINAE-enabled. */ if (CLASS_TYPE_P (type)) { gcc_assert (!TYPE_NEEDS_CONSTRUCTING (type)); @@ -450,7 +452,9 @@ build_value_init_noctor (tree type, tsubst_flags_t complain) if (ce->value == error_mark_node) return error_mark_node; - /* The gimplifier can't deal with a RANGE_EXPR of TARGET_EXPRs. */ + /* We shouldn't have gotten here for anything that would need + non-trivial initialization, and gimplify_init_ctor_preeval + would need to be fixed to allow it. */ gcc_assert (TREE_CODE (ce->value) != TARGET_EXPR && TREE_CODE (ce->value) != AGGR_INIT_EXPR); } diff --git a/gcc/cp/typeck2.c b/gcc/cp/typeck2.c index 20b47d5..f0b67f7 100644 --- a/gcc/cp/typeck2.c +++ b/gcc/cp/typeck2.c @@ -1534,6 +1534,15 @@ build_functional_cast (tree exp, tree parms, tsubst_flags_t complain) else type = exp; + /* We need to check this explicitly, since value-initialization of + arrays is allowed in other situations. */ + if (TREE_CODE (type) == ARRAY_TYPE) + { + if (complain & tf_error) + error ("functional cast to array type %qT", type); + return error_mark_node; + } + if (processing_template_decl) { tree t; diff --git a/gcc/testsuite/g++.dg/cpp0x/sfinae16.C b/gcc/testsuite/g++.dg/cpp0x/sfinae16.C new file mode 100644 index 0000000..6470567 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/sfinae16.C @@ -0,0 +1,17 @@ +// PR c++/48531 +// { dg-options -std=c++0x } + +template +char f(int); + +template +double f(...); + +struct B2 { + B2(...); +}; + +#define SA(X) static_assert ((X), #X); +SA(sizeof(f(0)) != 1);