From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 23984 invoked by alias); 18 Mar 2004 01:12:33 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 23947 invoked by alias); 18 Mar 2004 01:12:30 -0000 Date: Thu, 18 Mar 2004 01:12:00 -0000 Message-ID: <20040318011230.23946.qmail@sources.redhat.com> From: "giovannibajo at libero dot it" To: gcc-bugs@gcc.gnu.org In-Reply-To: <20040312062911.14545.schmid@snake.iap.physik.tu-darmstadt.de> References: <20040312062911.14545.schmid@snake.iap.physik.tu-darmstadt.de> Reply-To: gcc-bugzilla@gcc.gnu.org Subject: [Bug c++/14545] [3.4/3.5 Regression] Cannot compile pooma-gcc (regression) X-Bugzilla-Reason: CC X-SW-Source: 2004-03/txt/msg02160.txt.bz2 List-Id: ------- Additional Comments From giovannibajo at libero dot it 2004-03-18 01:12 ------- Subject: Re: [3.4/3.5 Regression] Cannot compile pooma-gcc (regression) mark at codesourcery dot com wrote: >> Patch posted, waiting for review: >> http://gcc.gnu.org/ml/gcc-patches/2004-03/msg01265.html >> > Indeed, I think you should just check "!type_dependent_expression_p > (type) && !INTEGRAL_OR_ENUMERATION_TYPE_P (type)". I can't remember > if that's *quite* right; it might be that casts to floating-point types > should also be allowed. You'll have to check the standard for that. > Would you mind trying that approach please? This patch implements your suggestion. I checked the standard and you are right, only casts to integral or enumeration types are allowed in integral constant expressions. The patch was tested on i686-pc-linux-gnu with no new regressions, OK for 3.4 and mainline? Giovanni Bajo 2004-03-16 Giovanni Bajo PR c++/14545 * parser.c (cp_parser_functional_cast): A cast to anything but integral or enumaration type is not an integral constant expression. 2004-03-16 Giovanni Bajo PR c++/14545 * g++.dg/parse/template15.C: New test. Index: parser.c =================================================================== RCS file: /cvs/gcc/gcc/gcc/cp/parser.c,v retrieving revision 1.183 diff -c -3 -p -r1.183 parser.c *** parser.c 16 Mar 2004 22:17:59 -0000 1.183 --- parser.c 18 Mar 2004 01:04:57 -0000 *************** static tree *** 14477,14488 **** cp_parser_functional_cast (cp_parser* parser, tree type) { tree expression_list; expression_list = cp_parser_parenthesized_expression_list (parser, false, /*non_constant_p=*/NULL); ! return build_functional_cast (type, expression_list); } /* Save the tokens that make up the body of a member function defined --- 14477,14499 ---- cp_parser_functional_cast (cp_parser* parser, tree type) { tree expression_list; + tree cast; expression_list = cp_parser_parenthesized_expression_list (parser, false, /*non_constant_p=*/NULL); ! cast = build_functional_cast (type, expression_list); ! /* [expr.const]/1: In an integral constant expression "only type ! conversions to integral or enumeration type can be used". */ ! if (cast != error_mark_node && !type_dependent_expression_p (type) ! && !INTEGRAL_OR_ENUMERATION_TYPE_P (TREE_TYPE (type))) ! { ! if (cp_parser_non_integral_constant_expression ! (parser, "a call to a constructor")) ! return error_mark_node; ! } ! return cast; } /* Save the tokens that make up the body of a member function defined // { dg-do compile } // Contributed by: Peter Schmid // // PR c++/14545: constructor calls are not integer constant expressions struct A1 { A1(); }; struct A2 { }; template struct B { void foo() { A1(); A1 a1 = A1(); A2(); A2 a2 = A2(); } }; template struct B; -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14545