From 55de1b6662d54cde8f407bd4d1f3e10de3a6fa9f Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Sat, 3 Feb 2001 01:27:28 +0100 Subject: [PATCH] decl.c (push_class_binding): Use context_for_name_lookup instead of CP_DECL_CONTEXT. * decl.c (push_class_binding): Use context_for_name_lookup instead of CP_DECL_CONTEXT. * search.c (context_for_name_lookup): Remove static. Check for NULL context in the loop. * cp-tree.h (context_for_name_lookup): Add prototype. * g++.old-deja/g++.other/anon6.C: New test. * g++.old-deja/g++.other/anon7.C: New test. From-SVN: r39417 --- gcc/cp/ChangeLog | 8 +++++ gcc/cp/cp-tree.h | 1 + gcc/cp/decl.c | 2 +- gcc/cp/search.c | 7 ++-- gcc/testsuite/ChangeLog | 5 +++ gcc/testsuite/g++.old-deja/g++.other/anon6.C | 36 ++++++++++++++++++++ gcc/testsuite/g++.old-deja/g++.other/anon7.C | 24 +++++++++++++ 7 files changed, 78 insertions(+), 5 deletions(-) create mode 100644 gcc/testsuite/g++.old-deja/g++.other/anon6.C create mode 100644 gcc/testsuite/g++.old-deja/g++.other/anon7.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index edb2039938a..b9d81e1daa5 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,11 @@ +2001-02-03 Jakub Jelinek + + * decl.c (push_class_binding): Use context_for_name_lookup instead + of CP_DECL_CONTEXT. + * search.c (context_for_name_lookup): Remove static. Check for NULL + context in the loop. + * cp-tree.h (context_for_name_lookup): Add prototype. + 2001-02-02 Jakub Jelinek * cp-tree.h (build_expr_ptr_wrapper, can_free): Remove. diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index 3ec2778f08c..60421a391b6 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -4211,6 +4211,7 @@ extern void init_search_processing PARAMS ((void)); extern void reinit_search_statistics PARAMS ((void)); extern tree current_scope PARAMS ((void)); extern int at_function_scope_p PARAMS ((void)); +extern tree context_for_name_lookup PARAMS ((tree)); extern tree lookup_conversions PARAMS ((tree)); extern tree binfo_for_vtable PARAMS ((tree)); extern tree binfo_from_vbase PARAMS ((tree)); diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 080853e37c1..44a3b3b947d 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -1124,7 +1124,7 @@ push_class_binding (id, decl) else { my_friendly_assert (DECL_P (decl), 0); - context = CP_DECL_CONTEXT (decl); + context = context_for_name_lookup (decl); } if (is_properly_derived_from (current_class_type, context)) diff --git a/gcc/cp/search.c b/gcc/cp/search.c index 0bb309fa5bd..c8cf526035f 100644 --- a/gcc/cp/search.c +++ b/gcc/cp/search.c @@ -120,7 +120,6 @@ static tree bfs_walk void *)); static tree lookup_field_queue_p PARAMS ((tree, void *)); static tree lookup_field_r PARAMS ((tree, void *)); -static tree context_for_name_lookup PARAMS ((tree)); static tree canonical_binfo PARAMS ((tree)); static tree shared_marked_p PARAMS ((tree, void *)); static tree shared_unmarked_p PARAMS ((tree, void *)); @@ -714,7 +713,7 @@ at_function_scope_p () /* Return the scope of DECL, as appropriate when doing name-lookup. */ -static tree +tree context_for_name_lookup (decl) tree decl; { @@ -724,9 +723,9 @@ context_for_name_lookup (decl) definition, the members of the anonymous union are considered to have been defined in the scope in which the anonymous union is declared. */ - tree context = CP_DECL_CONTEXT (decl); + tree context = DECL_CONTEXT (decl); - while (TYPE_P (context) && ANON_AGGR_TYPE_P (context)) + while (context && TYPE_P (context) && ANON_AGGR_TYPE_P (context)) context = TYPE_CONTEXT (context); if (!context) context = global_namespace; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index c00497e1588..60daf568946 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2001-02-03 Jakub Jelinek + + * g++.old-deja/g++.other/anon6.C: New test. + * g++.old-deja/g++.other/anon7.C: New test. + 2001-02-01 Neil Booth * gcc.dg/cpp/avoidpaste2.c: New tests. diff --git a/gcc/testsuite/g++.old-deja/g++.other/anon6.C b/gcc/testsuite/g++.old-deja/g++.other/anon6.C new file mode 100644 index 00000000000..4fd9e7d52fc --- /dev/null +++ b/gcc/testsuite/g++.old-deja/g++.other/anon6.C @@ -0,0 +1,36 @@ +extern "C" void abort (); + +struct A { + union { + int a; + double b; + int d; + }; + int c; +}; + +struct B : public A { + union { + double a; + void *c; + }; + float b; + int e; +}; + +int main () +{ + struct B b; + + b.a = 1.5; + b.b = 2.5; + b.d = 1; + b.e = 2; + if (b.a != 1.5 || b.b != 2.5 || b.d != 1 || b.e != 2) + abort (); + b.c = &b.a; + b.d = b.e; + if (b.c != &b.a || b.d != 2) + abort (); + return 0; +} diff --git a/gcc/testsuite/g++.old-deja/g++.other/anon7.C b/gcc/testsuite/g++.old-deja/g++.other/anon7.C new file mode 100644 index 00000000000..ba624a059b5 --- /dev/null +++ b/gcc/testsuite/g++.old-deja/g++.other/anon7.C @@ -0,0 +1,24 @@ +// Build don't link: + +struct A { + union { + int a; // ERROR - conflicts with previous declaration + }; + int a; // ERROR - +}; + +struct B { + int b; // ERROR - conflicts with previous declaration + union { + int b; // ERROR - duplicate member + }; // ERROR - declaration of +}; + +struct C { + union { + int c; // ERROR - conflicts with previous declaration + }; + union { + int c; // ERROR - duplicate member + }; // ERROR - declaration of +}; -- 2.30.2