From patchwork Thu Nov 11 06:19:21 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 70776 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 4ABAAB710F for ; Thu, 11 Nov 2010 17:19:37 +1100 (EST) Received: (qmail 9613 invoked by alias); 11 Nov 2010 06:19:34 -0000 Received: (qmail 9598 invoked by uid 22791); 11 Nov 2010 06:19:33 -0000 X-SWARE-Spam-Status: No, hits=-6.1 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; Thu, 11 Nov 2010 06:19:24 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id oAB6JMxG000969 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 11 Nov 2010 01:19:23 -0500 Received: from [127.0.0.1] (ovpn-113-26.phx2.redhat.com [10.3.113.26]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id oAB6JLk3006075 for ; Thu, 11 Nov 2010 01:19:22 -0500 Message-ID: <4CDB8AE9.4010506@redhat.com> Date: Thu, 11 Nov 2010 00:19:21 -0600 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.15) Gecko/20101108 Lightning/1.0b1 Shredder/3.0.11pre MIME-Version: 1.0 To: gcc-patches List Subject: C++ PATCH for c++/46420 (C++0x ICE with functional cast in initializer) 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 currently call fold_non_dependent_expr on initializers, which isn't quite right; we should only call it in places that require a constant expression. As a result, in C++0x mode we can end up with a TARGET_EXPR wrapped around a constant CONSTRUCTOR. For now, it's easier to just deal with it. Tested x86_64-pc-linux-gnu, applied to trunk. commit c666ae011ac0b63f554102c6fb811a7319421485 Author: Jason Merrill Date: Wed Nov 10 21:15:06 2010 -0600 PR c++/46420 * pt.c (tsubst_copy_and_build) [TARGET_EXPR]: New case. [CONSTRUCTOR]: Use the tsubsted type. diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 7a06038..56b7543 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -13197,6 +13197,7 @@ tsubst_copy_and_build (tree t, if (TREE_HAS_CONSTRUCTOR (t)) return finish_compound_literal (type, r); + TREE_TYPE (r) = type; return r; } @@ -13316,6 +13317,12 @@ tsubst_copy_and_build (tree t, return build_lambda_object (r); } + case TARGET_EXPR: + /* We can get here for a constant initializer of non-dependent type. + FIXME stop folding in cp_parser_initializer_clause. */ + gcc_assert (TREE_CONSTANT (t)); + return get_target_expr (RECUR (TARGET_EXPR_INITIAL (t))); + default: /* Handle Objective-C++ constructs, if appropriate. */ { diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-46420.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-46420.C new file mode 100644 index 0000000..757a6e3 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-46420.C @@ -0,0 +1,13 @@ +// PR c++/46420 +// { dg-options -std=c++0x } + +template class vector { }; +struct A{}; +template +void complete_test(vector data1){ + A drop=A(); +} +int main(){ + vector vect1; + complete_test(vect1); +}