This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/14545] [3.4/3.5 Regression] Cannot compile pooma-gcc (regression)
- From: "giovannibajo at libero dot it" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 18 Mar 2004 01:12:30 -0000
- Subject: [Bug c++/14545] [3.4/3.5 Regression] Cannot compile pooma-gcc (regression)
- References: <20040312062911.14545.schmid@snake.iap.physik.tu-darmstadt.de>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- 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 <giovannibajo@gcc.gnu.org>
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 <giovannibajo@gcc.gnu.org>
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
// <schmid at snake dot iap dot physik dot tu-darmstadt dot de>
// PR c++/14545: constructor calls are not integer constant expressions
struct A1 { A1(); };
struct A2 { };
template <class T>
struct B
{
void foo() {
A1();
A1 a1 = A1();
A2();
A2 a2 = A2();
}
};
template struct B<void>;
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14545