From patchwork Wed Mar 30 20:30: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: 88977 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 8E51AB6EF2 for ; Thu, 31 Mar 2011 07:30:49 +1100 (EST) Received: (qmail 13527 invoked by alias); 30 Mar 2011 20:30:43 -0000 Received: (qmail 13515 invoked by uid 22791); 30 Mar 2011 20:30:40 -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, 30 Mar 2011 20:30:27 +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 p2UKUQhS030699 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 30 Mar 2011 16:30:26 -0400 Received: from [127.0.0.1] (ovpn-113-113.phx2.redhat.com [10.3.113.113]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id p2UKUPJT008351 for ; Wed, 30 Mar 2011 16:30:25 -0400 Message-ID: <4D9392E0.8090808@redhat.com> Date: Wed, 30 Mar 2011 16:30:24 -0400 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++/48212 (ICE after error on invalid constant 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 non_const_var_error wasn't considering the possibility that the variable is unsuitable for a constant expression because its initializer is erroneous. Tested x86_64-pc-linux-gnu, applied to trunk and 4.6. commit 95a1f4128e0d9fb5480f0ae83240a6d339cf012e Author: Jason Merrill Date: Wed Mar 30 16:05:52 2011 -0400 PR c++/48212 * semantics.c (non_const_var_error): Just return if DECL_INITIAL is error_mark_node. diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index 3300c3f..e444d91 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -6753,6 +6753,9 @@ non_const_var_error (tree r) tree type = TREE_TYPE (r); error ("the value of %qD is not usable in a constant " "expression", r); + /* Avoid error cascade. */ + if (DECL_INITIAL (r) == error_mark_node) + return; if (DECL_DECLARED_CONSTEXPR_P (r)) inform (DECL_SOURCE_LOCATION (r), "%qD used in its own initializer", r); diff --git a/gcc/testsuite/g++.dg/cpp0x/regress/error-recovery1.C b/gcc/testsuite/g++.dg/cpp0x/regress/error-recovery1.C new file mode 100644 index 0000000..2094d3e --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/regress/error-recovery1.C @@ -0,0 +1,9 @@ +// PR c++/48212 +// { dg-options -std=c++0x } + +template < bool > void +foo () +{ + const bool b =; // { dg-error "" } + foo < b > (); // { dg-error "constant expression" } +};