From 85a988d14eba08447282db312f99637a527bfba0 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Mon, 8 Jun 2009 18:26:01 +0200 Subject: [PATCH] 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: r148278 --- gcc/cp/ChangeLog | 9 +++++++++ gcc/cp/parser.c | 13 ++++++------- gcc/testsuite/ChangeLog | 9 ++++++++- gcc/testsuite/g++.dg/template/error41.C | 12 ++++++++++++ gcc/testsuite/g++.dg/template/error42.C | 20 ++++++++++++++++++++ 5 files changed, 55 insertions(+), 8 deletions(-) create mode 100644 gcc/testsuite/g++.dg/template/error41.C create mode 100644 gcc/testsuite/g++.dg/template/error42.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 12020e84bea..5c0d4730ce6 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,12 @@ +2009-06-08 Jakub Jelinek + + 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-08 Alexandre Oliva * repo.c (get_base_filename): Use aux_base_name rather than diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 00f25806082..05ae257fbf7 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -13336,13 +13336,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. */ @@ -13352,6 +13345,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; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index eec29c75a26..9c7651db722 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,6 +1,13 @@ +2009-06-08 Jakub Jelinek + + PR c++/40370 + PR c++/40372 + * g++.dg/template/error41.C: New test. + * g++.dg/template/error42.C: New test. + 2009-06-08 Revital Eres - PR40359 + PR testsuite/40359 * gcc.dg/vect/vect-58.c: Change checks to use vect_hw_misalign. * gcc.dg/vect/vect-88.c: Likewise. * gcc.dg/vect/no-section-anchors-vect-66.c: Likewise. diff --git a/gcc/testsuite/g++.dg/template/error41.C b/gcc/testsuite/g++.dg/template/error41.C new file mode 100644 index 00000000000..c92b8497aff --- /dev/null +++ b/gcc/testsuite/g++.dg/template/error41.C @@ -0,0 +1,12 @@ +// PR c++/40370 +// { dg-do compile } + +struct A +{ + static int i; +}; + +template struct B +{ + int x[A::i]; // { dg-error "array bound is not an integer constant" } +}; diff --git a/gcc/testsuite/g++.dg/template/error42.C b/gcc/testsuite/g++.dg/template/error42.C new file mode 100644 index 00000000000..0d651e31620 --- /dev/null +++ b/gcc/testsuite/g++.dg/template/error42.C @@ -0,0 +1,20 @@ +// PR c++/40372 +// { dg-do compile } + +template 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" } + } +};