From patchwork Tue Feb 26 04:19:51 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 223107 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 9ED662C029E for ; Tue, 26 Feb 2013 15:20:09 +1100 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1362457209; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Message-ID:Date:From:User-Agent:MIME-Version:To:Subject: Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:Sender:Delivered-To; bh=V1oTG9O +MQhtzgfB6zv/FYZJlLw=; b=aq4ydIv/bjcOrtnAmizAlEb5O1qCx9uDoDsqnNe nmarsViKQXMtaA7hiQZIOqdkzb2HrSZuqQm6JM85RCVhiZzSmcaYOsNCOHyC29nt UIOZgTknkkwnWo3d4D/wFmzEoY8k6OGFU4lkzwiMeUAwMF6SWe2zZJkBJgXXi3uU tEqw= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Received:Message-ID:Date:From:User-Agent:MIME-Version:To:Subject:Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=CYCFhk2Fqo+qIz+GhdmBP+UwAbOV9iXacjIlnL+rcCmmOMV5IrMWiHDdKXxQog DQqz6s8qmEsEnBlf2YEW8I1hWXRYzK6NNANQt9BzuRT/Vzqij6k8VpiIE8m9haTv 3NA1ZF8MvbJrdorJo3wd5miD3I92Skj95R/X4pj7iOtdE=; Received: (qmail 20310 invoked by alias); 26 Feb 2013 04:20:00 -0000 Received: (qmail 20301 invoked by uid 22791); 26 Feb 2013 04:19:58 -0000 X-SWARE-Spam-Status: No, hits=-6.6 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, KHOP_SPAMHAUS_DROP, RCVD_IN_DNSWL_HI, RCVD_IN_HOSTKARMA_W, RP_MATCHES_RCVD, SPF_HELO_PASS, TW_CX 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, 26 Feb 2013 04:19:52 +0000 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r1Q4Jq4d027792 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 25 Feb 2013 23:19:52 -0500 Received: from [10.3.113.106] (ovpn-113-106.phx2.redhat.com [10.3.113.106]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r1Q4JpfO023560 for ; Mon, 25 Feb 2013 23:19:52 -0500 Message-ID: <512C37E7.60502@redhat.com> Date: Mon, 25 Feb 2013 23:19:51 -0500 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; Linux i686; rv:21.0) Gecko/20100101 Thunderbird/21.0a2 MIME-Version: 1.0 To: gcc-patches List Subject: C++ PATCH for c++/56438 (ICE with cast 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 Here, the problem is that value_dependent_expression_p only expects to see constant expressions, but potential_constant_expression_1 was letting through some things that aren't in a way that the former function was checking for. Fixed by returning false from the latter function in that case. Tested x86_64-pc-linux-gnu, applying to trunk. commit 97bd6eae21005915c47eea8f3b52aff72ba3238d Author: Jason Merrill Date: Mon Feb 25 16:05:19 2013 -0500 PR c++/56438 * semantics.c (potential_constant_expression_1): In C++98, a cast to non-integral type can't be a constant expression. diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index 458ed26..60271b5 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -8607,6 +8607,18 @@ potential_constant_expression_1 (tree t, bool want_rval, tsubst_flags_t flags) case STATIC_CAST_EXPR: case REINTERPRET_CAST_EXPR: case IMPLICIT_CONV_EXPR: + if (cxx_dialect < cxx0x + && !dependent_type_p (TREE_TYPE (t)) + && !INTEGRAL_OR_ENUMERATION_TYPE_P (TREE_TYPE (t))) + /* In C++98, a conversion to non-integral type can't be part of a + constant expression. */ + { + if (flags & tf_error) + error ("cast to non-integral type %qT in a constant expression", + TREE_TYPE (t)); + return false; + } + return (potential_constant_expression_1 (TREE_OPERAND (t, 0), TREE_CODE (TREE_TYPE (t)) != REFERENCE_TYPE, flags)); diff --git a/gcc/testsuite/g++.dg/template/cast3.C b/gcc/testsuite/g++.dg/template/cast3.C new file mode 100644 index 0000000..b343ee4 --- /dev/null +++ b/gcc/testsuite/g++.dg/template/cast3.C @@ -0,0 +1,22 @@ +// PR c++/56438 + +struct A { }; +A& operator<<(A&, const char*); + +struct B { + int size(); +}; + +struct C { }; + +template +S bar(const S& s, const T& t) { + return s; +} + +template +void foo() { + A a; + B b; + a << bar(b.size(), C()); // { dg-error "no match" } +}