From 44370687a54bf3d2cce7a719540d15dc47af84d4 Mon Sep 17 00:00:00 2001 From: Mark Mitchell Date: Fri, 12 Nov 2004 21:47:13 +0000 Subject: [PATCH] re PR c++/18389 (ICE on struct declaration in for statement) PR c++/18389 * decl.c (start_decl): Make sure to set *pop_scope_p. Return error_mark_node to indicate errors. PR c++/18429 * parser.c (cp_parser_direct_declarator): Disallow non-constant array bounds when not inside a function. PR c++/18436 * pt.c (tsubst_copy_and_build): Do not do Koenig lookup when an unqualified name resolves to a member function. PR c++/18407 * pt.c (tsubst_copy_and_build): Handle qualified names used from a derived class correctly. * decl2.c (import_export_decl): Fix typo in comment. * tree.c (pod_type_p): Likewise. PR c++/18389 * g++.dg/parse/cond1.C: New test. PR c++/18429 * g++.dg/template/array9.C: New test. * g++.dg/ext/vla1.C: Adjust error messages. * g++.dg/ext/vlm1.C: Likewise. * g++.dg/template/crash2.C: Likewise. PR c++/18436 * g++.dg/template/call3.C: New test. PR c++/18407 * g++.dg/template/ptrmem11.C: New test. From-SVN: r90545 --- gcc/cp/ChangeLog | 21 +++++++++++++++++++++ gcc/cp/decl.c | 8 ++++---- gcc/cp/decl2.c | 2 +- gcc/cp/parser.c | 5 +++++ gcc/cp/pt.c | 17 +++++++++++++---- gcc/cp/tree.c | 2 +- gcc/testsuite/ChangeLog | 17 +++++++++++++++++ gcc/testsuite/g++.dg/ext/vla1.C | 2 +- gcc/testsuite/g++.dg/ext/vlm1.C | 2 +- gcc/testsuite/g++.dg/parse/cond1.C | 6 ++++++ gcc/testsuite/g++.dg/template/array9.C | 18 ++++++++++++++++++ gcc/testsuite/g++.dg/template/call3.C | 15 +++++++++++++++ gcc/testsuite/g++.dg/template/crash2.C | 2 +- gcc/testsuite/g++.dg/template/ptrmem11.C | 19 +++++++++++++++++++ 14 files changed, 123 insertions(+), 13 deletions(-) create mode 100644 gcc/testsuite/g++.dg/parse/cond1.C create mode 100644 gcc/testsuite/g++.dg/template/array9.C create mode 100644 gcc/testsuite/g++.dg/template/call3.C create mode 100644 gcc/testsuite/g++.dg/template/ptrmem11.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 1b34b951994..fe51d5b5b5e 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,24 @@ +2004-11-12 Mark Mitchell + + PR c++/18389 + * decl.c (start_decl): Make sure to set *pop_scope_p. Return + error_mark_node to indicate errors. + + PR c++/18429 + * parser.c (cp_parser_direct_declarator): Disallow non-constant + array bounds when not inside a function. + + PR c++/18436 + * pt.c (tsubst_copy_and_build): Do not do Koenig lookup when an + unqualified name resolves to a member function. + + PR c++/18407 + * pt.c (tsubst_copy_and_build): Handle qualified names used from a + derived class correctly. + + * decl2.c (import_export_decl): Fix typo in comment. + * tree.c (pod_type_p): Likewise. + 2004-11-10 Andrew Pinski * typeck.c (cxx_mark_addressable): Add braces around the first if. diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index a6961215396..472b1f92e87 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -3670,6 +3670,8 @@ start_decl (const cp_declarator *declarator, tree type, tem; tree context; + *pop_scope_p = false; + /* This should only be done once on the top most decl. */ if (have_extern_spec) { @@ -3690,19 +3692,17 @@ start_decl (const cp_declarator *declarator, deprecated_state = DEPRECATED_NORMAL; if (decl == NULL_TREE || TREE_CODE (decl) == VOID_TYPE) - return NULL_TREE; + return error_mark_node; type = TREE_TYPE (decl); if (type == error_mark_node) - return NULL_TREE; + return error_mark_node; context = DECL_CONTEXT (decl); if (context) *pop_scope_p = push_scope (context); - else - *pop_scope_p = false; /* We are only interested in class contexts, later. */ if (context && TREE_CODE (context) == NAMESPACE_DECL) diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c index 03c51e77907..d8987e27be0 100644 --- a/gcc/cp/decl2.c +++ b/gcc/cp/decl2.c @@ -1743,7 +1743,7 @@ import_export_decl (tree decl) vague linkage, maybe_commonize_var is used. Therefore, the only declarations that should be provided to this - function are those with external linkage that: + function are those with external linkage that are: * implicit instantiations of function templates diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index ef02ba9f514..265abdb81e4 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -10960,6 +10960,11 @@ cp_parser_direct_declarator (cp_parser* parser, &non_constant_p); if (!non_constant_p) bounds = fold_non_dependent_expr (bounds); + else if (!at_function_scope_p ()) + { + error ("array bound is not an integer constant"); + bounds = error_mark_node; + } } else bounds = NULL_TREE; diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 28ae8f375b3..54c997951ed 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -8543,7 +8543,11 @@ tsubst_copy_and_build (tree t, lookup finds a non-function, in accordance with the expected resolution of DR 218. */ if (koenig_p - && (is_overloaded_fn (function) + && ((is_overloaded_fn (function) + /* If lookup found a member function, the Koenig lookup is + not appropriate, even if an unqualified-name was used + to denote the function. */ + && !DECL_FUNCTION_MEMBER_P (get_first_fn (function))) || TREE_CODE (function) == IDENTIFIER_NODE)) function = perform_koenig_lookup (function, call_args); @@ -8659,9 +8663,14 @@ tsubst_copy_and_build (tree t, /*is_type_p=*/false, /*complain=*/false); if (BASELINK_P (member)) - BASELINK_FUNCTIONS (member) - = build_nt (TEMPLATE_ID_EXPR, BASELINK_FUNCTIONS (member), - args); + { + BASELINK_FUNCTIONS (member) + = build_nt (TEMPLATE_ID_EXPR, BASELINK_FUNCTIONS (member), + args); + member = (adjust_result_of_qualified_name_lookup + (member, BINFO_TYPE (BASELINK_BINFO (member)), + TREE_TYPE (object))); + } else { qualified_name_lookup_error (TREE_TYPE (object), tmpl, diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c index afe42e23730..82aebe49550 100644 --- a/gcc/cp/tree.c +++ b/gcc/cp/tree.c @@ -1716,7 +1716,7 @@ pod_type_p (tree t) return 1; /* pointer to member */ if (TREE_CODE (t) == VECTOR_TYPE) - return 1; /* vectors are (small) arrays if scalars */ + return 1; /* vectors are (small) arrays of scalars */ if (! CLASS_TYPE_P (t)) return 0; /* other non-class type (reference or function) */ diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 853cd4a6a48..10bac622f80 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,20 @@ +2004-11-12 Mark Mitchell + + PR c++/18389 + * g++.dg/parse/cond1.C: New test. + + PR c++/18429 + * g++.dg/template/array9.C: New test. + * g++.dg/ext/vla1.C: Adjust error messages. + * g++.dg/ext/vlm1.C: Likewise. + * g++.dg/template/crash2.C: Likewise. + + PR c++/18436 + * g++.dg/template/call3.C: New test. + + PR c++/18407 + * g++.dg/template/ptrmem11.C: New test. + 2004-11-12 Andrew Pinski PR other/14264 diff --git a/gcc/testsuite/g++.dg/ext/vla1.C b/gcc/testsuite/g++.dg/ext/vla1.C index bac5aaca1a5..f2238c2fdd4 100644 --- a/gcc/testsuite/g++.dg/ext/vla1.C +++ b/gcc/testsuite/g++.dg/ext/vla1.C @@ -19,7 +19,7 @@ class B { B (int); }; B::B (int i) { struct S { - int ar[1][i]; // { dg-error "variable-size|variably modified" } + int ar[1][i]; // { dg-error "array" } } s; s.ar[0][0] = 0; // { dg-error "no member" } diff --git a/gcc/testsuite/g++.dg/ext/vlm1.C b/gcc/testsuite/g++.dg/ext/vlm1.C index 13f67027710..9cb6c38be15 100644 --- a/gcc/testsuite/g++.dg/ext/vlm1.C +++ b/gcc/testsuite/g++.dg/ext/vlm1.C @@ -4,7 +4,7 @@ template struct A {}; struct B { static const int s; - A a; // { dg-error "variably modified|no type|trying to instantiate" } + A a; // { dg-error "array|template" } }; const int B::s=16; diff --git a/gcc/testsuite/g++.dg/parse/cond1.C b/gcc/testsuite/g++.dg/parse/cond1.C new file mode 100644 index 00000000000..69947730525 --- /dev/null +++ b/gcc/testsuite/g++.dg/parse/cond1.C @@ -0,0 +1,6 @@ +// PR c++/18389 + +void foo() +{ + for (; struct A {}; ); // { dg-error "" } +} diff --git a/gcc/testsuite/g++.dg/template/array9.C b/gcc/testsuite/g++.dg/template/array9.C new file mode 100644 index 00000000000..f3e8335c943 --- /dev/null +++ b/gcc/testsuite/g++.dg/template/array9.C @@ -0,0 +1,18 @@ +// PR c++/18429 + +int subtrees = 4; +template< class T > +struct Tree { + Tree* L[subtrees]; // { dg-error "" } + Tree* R[subtrees]; // { dg-error "" } + ~Tree() + { + delete [] L[0]; // { dg-error "" } + delete [] R[0]; // { dg-error "" } + } +}; + +void f() +{ + Tree t; +} diff --git a/gcc/testsuite/g++.dg/template/call3.C b/gcc/testsuite/g++.dg/template/call3.C new file mode 100644 index 00000000000..1dd2b51b3eb --- /dev/null +++ b/gcc/testsuite/g++.dg/template/call3.C @@ -0,0 +1,15 @@ +// PR c++/18436 + +void foo(int); + +struct A +{ + static void foo(A); +}; + +template struct B : T +{ + B() { foo(T()); } +}; + +B b; diff --git a/gcc/testsuite/g++.dg/template/crash2.C b/gcc/testsuite/g++.dg/template/crash2.C index a02787a46fa..8bf7b450df2 100644 --- a/gcc/testsuite/g++.dg/template/crash2.C +++ b/gcc/testsuite/g++.dg/template/crash2.C @@ -5,7 +5,7 @@ class A { public: static const EnumType size = max; // { dg-error "" } - int table[size]; + int table[size]; // { dg-error "" } }; template const EnumType A::size; diff --git a/gcc/testsuite/g++.dg/template/ptrmem11.C b/gcc/testsuite/g++.dg/template/ptrmem11.C new file mode 100644 index 00000000000..da2ce499fbe --- /dev/null +++ b/gcc/testsuite/g++.dg/template/ptrmem11.C @@ -0,0 +1,19 @@ +// PR c++/18407 + +template +struct the_base{ + template void foo() { } +}; + +template +struct derivedT: the_base > { + typedef the_base > parent; + void ice(){ + this->parent::template foo< &derivedT::ice>(); + } +}; + +int main() { + derivedT dT; + dT.ice(); +}