From patchwork Tue Mar 8 05:25:01 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 85904 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 9363AB6EE8 for ; Tue, 8 Mar 2011 16:25:12 +1100 (EST) Received: (qmail 13991 invoked by alias); 8 Mar 2011 05:25:09 -0000 Received: (qmail 13969 invoked by uid 22791); 8 Mar 2011 05:25:08 -0000 X-SWARE-Spam-Status: No, hits=-6.2 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; Tue, 08 Mar 2011 05:25:04 +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.14.4/8.14.4) with ESMTP id p285P3et024345 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 8 Mar 2011 00:25:03 -0500 Received: from [127.0.0.1] (ovpn-113-31.phx2.redhat.com [10.3.113.31]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p285P2Fa001625 for ; Tue, 8 Mar 2011 00:25:02 -0500 Message-ID: <4D75BDAD.9010401@redhat.com> Date: Tue, 08 Mar 2011 00:25:01 -0500 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.13) Gecko/20101209 Fedora/3.1.7-0.35.b3pre.fc14 Lightning/1.0b2 Thunderbird/3.1.7 MIME-Version: 1.0 To: gcc-patches List Subject: C++ PATCH for c++/48015 (C++0x ICE with non-constant initializer for const int var in template) 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 constant_value_1 has been trying to pull out DECL_INITIAL for any variable with the proper type. This can be problematic in templates, where DECL_INITIAL hasn't always been properly folded yet. But since we try to reduce initializers to a constant when we process the declaration, we can just decide whether or not we want to use the initializer based on TREE_CONSTANT. Tested x86_64-pc-linux-gnu, applying to trunk. commit 9c7fa022068d56f4417aeea733e8bdf21c4a98e7 Author: Jason Merrill Date: Mon Mar 7 16:00:05 2011 -0500 PR c++/48015 * init.c (constant_value_1): Always require init to be TREE_CONSTANT. diff --git a/gcc/cp/init.c b/gcc/cp/init.c index e590118..56f66fa 100644 --- a/gcc/cp/init.c +++ b/gcc/cp/init.c @@ -1760,17 +1760,15 @@ constant_value_1 (tree decl, bool integral_p) init = TREE_VALUE (init); if (!init || !TREE_TYPE (init) - || uses_template_parms (init) - || (integral_p - ? false - : (!TREE_CONSTANT (init) - /* Do not return an aggregate constant (of which - string literals are a special case), as we do not - want to make inadvertent copies of such entities, - and we must be sure that their addresses are the - same everywhere. */ - || TREE_CODE (init) == CONSTRUCTOR - || TREE_CODE (init) == STRING_CST))) + || !TREE_CONSTANT (init) + || (!integral_p + /* Do not return an aggregate constant (of which + string literals are a special case), as we do not + want to make inadvertent copies of such entities, + and we must be sure that their addresses are the + same everywhere. */ + && (TREE_CODE (init) == CONSTRUCTOR + || TREE_CODE (init) == STRING_CST))) break; decl = unshare_expr (init); } diff --git a/gcc/testsuite/g++.dg/cpp0x/regress/non-const1.C b/gcc/testsuite/g++.dg/cpp0x/regress/non-const1.C new file mode 100644 index 0000000..7fc66a7 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/regress/non-const1.C @@ -0,0 +1,9 @@ +// PR c++/48015 +// { dg-options -std=c++0x } + +template T f(T); +template void g() +{ + int const c = f (1); + int i = c - 0; +}