From d36d56001a298d89b6d69750cb6dfee4653aa2b8 Mon Sep 17 00:00:00 2001 From: Giovanni Bajo Date: Fri, 19 Mar 2004 09:58:50 +0000 Subject: [PATCH] re PR c++/14545 (Cannot compile pooma-gcc (regression)) PR c++/14545 * parser.c (cp_parser_functional_cast): A cast to anything but integral or enumaration type is not an integral constant expression. * pt.c (value_dependent_expression_p): Handle cast expressions without operands (such as "int()"). PR c++/14545 * g++.dg/parse/template15.C: New test. From-SVN: r79672 --- gcc/cp/ChangeLog | 9 +++++++++ gcc/cp/parser.c | 13 ++++++++++++- gcc/cp/pt.c | 13 ++++++++++++- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/g++.dg/parse/template15.C | 26 +++++++++++++++++++++++++ 5 files changed, 64 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/g++.dg/parse/template15.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 38225639236..77e30a55288 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,12 @@ +2004-03-19 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. + * pt.c (value_dependent_expression_p): Handle cast expressions + without operands (such as "int()"). + 2004-03-18 Mark Mitchell * semantics.c (finish_pseudo_destructor_expr): Allow differing diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index c05e3754218..e964f48753f 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -14494,12 +14494,23 @@ static tree 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); - return build_functional_cast (type, expression_list); + 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 diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 365cb18bf66..3719410ad0d 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -11776,10 +11776,21 @@ value_dependent_expression_p (tree expression) || TREE_CODE (expression) == REINTERPRET_CAST_EXPR || TREE_CODE (expression) == CAST_EXPR) { - if (dependent_type_p (TREE_TYPE (expression))) + tree type = TREE_TYPE (expression); + if (dependent_type_p (type)) return true; /* A functional cast has a list of operands. */ expression = TREE_OPERAND (expression, 0); + if (!expression) + { + /* If there are no operands, it must be an expression such + as "int()". This should not happen for aggregate types + because it would form non-constant expressions. */ + my_friendly_assert (INTEGRAL_OR_ENUMERATION_TYPE_P (type), + 20040318); + + return false; + } if (TREE_CODE (expression) == TREE_LIST) { do diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 391bfa3844c..7ae25a39be6 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2004-03-19 Giovanni Bajo + + PR c++/14545 + * g++.dg/parse/template15.C: New test. + 2004-03-18 Mark Mitchell * g++.dg/expr/dtor2.C: New test. diff --git a/gcc/testsuite/g++.dg/parse/template15.C b/gcc/testsuite/g++.dg/parse/template15.C new file mode 100644 index 00000000000..ce2d130360f --- /dev/null +++ b/gcc/testsuite/g++.dg/parse/template15.C @@ -0,0 +1,26 @@ +// { 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(); + + int(); + int a3 = int(); + float(); + float a4 = float(); + } +}; + +template struct B; -- 2.30.2