re PR c++/40370 (ICE with invalid array bound in template class)

PR c++/40370
	PR c++/40372
	* parser.c (cp_parser_direct_declarator): Don't set TREE_SIDE_EFFECTS
	on error_mark_node.  Check for VLAs outside of function context
	before check whether to wrap bounds into a NOP_EXPR with
	TREE_SIDE_EFFECTS.

	* g++.dg/template/error41.C: New test.
	* g++.dg/template/error42.C: New test.

From-SVN: r148281
This commit is contained in:
Jakub Jelinek 2009-06-08 18:31:07 +02:00 committed by Jakub Jelinek
parent 12102f3d95
commit 89f05a151b
5 changed files with 54 additions and 7 deletions

View File

@ -1,3 +1,12 @@
2009-06-08 Jakub Jelinek <jakub@redhat.com>
PR c++/40370
PR c++/40372
* parser.c (cp_parser_direct_declarator): Don't set TREE_SIDE_EFFECTS
on error_mark_node. Check for VLAs outside of function context
before check whether to wrap bounds into a NOP_EXPR with
TREE_SIDE_EFFECTS.
2009-06-02 Jason Merrill <jason@redhat.com>
PR c++/40308

View File

@ -13296,13 +13296,6 @@ cp_parser_direct_declarator (cp_parser* parser,
&non_constant_p);
if (!non_constant_p)
bounds = fold_non_dependent_expr (bounds);
else if (processing_template_decl)
{
/* Remember this wasn't a constant-expression. */
bounds = build_nop (TREE_TYPE (bounds), bounds);
TREE_SIDE_EFFECTS (bounds) = 1;
}
/* Normally, the array bound must be an integral constant
expression. However, as an extension, we allow VLAs
in function scopes. */
@ -13312,6 +13305,12 @@ cp_parser_direct_declarator (cp_parser* parser,
&token->location);
bounds = error_mark_node;
}
else if (processing_template_decl && !error_operand_p (bounds))
{
/* Remember this wasn't a constant-expression. */
bounds = build_nop (TREE_TYPE (bounds), bounds);
TREE_SIDE_EFFECTS (bounds) = 1;
}
}
else
bounds = NULL_TREE;

View File

@ -1,3 +1,10 @@
2009-06-08 Jakub Jelinek <jakub@redhat.com>
PR c++/40370
PR c++/40372
* g++.dg/template/error41.C: New test.
* g++.dg/template/error42.C: New test.
2009-06-07 H.J. Lu <hongjiu.lu@intel.com>
Backport from mainline:

View File

@ -0,0 +1,12 @@
// PR c++/40370
// { dg-do compile }
struct A
{
static int i;
};
template <int> struct B
{
int x[A::i]; // { dg-error "array bound is not an integer constant" }
};

View File

@ -0,0 +1,20 @@
// PR c++/40372
// { dg-do compile }
template <int> struct A
{
int i; // { dg-error "invalid use of non-static data member" }
friend void foo ()
{
int x[i]; // { dg-error "from this location" }
}
};
struct B
{
int j; // { dg-error "invalid use of non-static data member" }
friend int bar ()
{
return j; // { dg-error "from this location" }
}
};