* 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.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@79672
138bc75d-0d04-0410-961f-
82ee72b054a4
+2004-03-19 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.
+ * pt.c (value_dependent_expression_p): Handle cast expressions
+ without operands (such as "int()").
+
2004-03-18 Mark Mitchell <mark@codesourcery.com>
* semantics.c (finish_pseudo_destructor_expr): Allow differing
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
|| 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
+2004-03-19 Giovanni Bajo <giovannibajo@gcc.gnu.org>
+
+ PR c++/14545
+ * g++.dg/parse/template15.C: New test.
+
2004-03-18 Mark Mitchell <mark@codesourcery.com>
* g++.dg/expr/dtor2.C: New test.
--- /dev/null
+// { 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();
+
+ int();
+ int a3 = int();
+ float();
+ float a4 = float();
+ }
+};
+
+template struct B<void>;