diff options
author | Jakub Jelinek <jakub@redhat.com> | 2001-04-20 10:13:59 +0200 |
---|---|---|
committer | Jakub Jelinek <jakub@gcc.gnu.org> | 2001-04-20 10:13:59 +0200 |
commit | 881cae050a16f36533d1ba5ceabed73292f1c855 (patch) | |
tree | d57d5f1aacfeb0ad8644c9384777249992ec4aeb | |
parent | d40cd80a97bc42595464cce6b13835a7451c1129 (diff) | |
download | gcc-881cae050a16f36533d1ba5ceabed73292f1c855.zip gcc-881cae050a16f36533d1ba5ceabed73292f1c855.tar.gz gcc-881cae050a16f36533d1ba5ceabed73292f1c855.tar.bz2 |
search.c (lookup_field_r): If looking for type and non-TYPE_DECL is found...
* search.c (lookup_field_r): If looking for type and non-TYPE_DECL
is found, look first if name does not match the structure name.
* g++.old-deja/g++.other/lookup23.C: New test.
From-SVN: r41447
-rw-r--r-- | gcc/cp/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/cp/search.c | 26 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 4 | ||||
-rw-r--r-- | gcc/testsuite/g++.old-deja/g++.other/lookup23.C | 13 |
4 files changed, 43 insertions, 5 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 8d84a8b..24af2b4 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2001-04-20 Jakub Jelinek <jakub@redhat.com> + + * search.c (lookup_field_r): If looking for type and non-TYPE_DECL + is found, look first if name does not match the structure name. + 2001-04-19 Mark Mitchell <mark@codesourcery.com> * cp-tree.h (DECL_LANGUAGE): Don't assume DECL_LANG_SPECIFIC is diff --git a/gcc/cp/search.c b/gcc/cp/search.c index 1c0a50d..6256f14 100644 --- a/gcc/cp/search.c +++ b/gcc/cp/search.c @@ -1384,11 +1384,27 @@ lookup_field_r (binfo, data) we ignore all non-types we find. */ if (lfi->want_type && TREE_CODE (nval) != TYPE_DECL) { - nval = purpose_member (lfi->name, CLASSTYPE_TAGS (type)); - if (nval) - nval = TYPE_MAIN_DECL (TREE_VALUE (nval)); - else - return NULL_TREE; + if (lfi->name == TYPE_IDENTIFIER (type)) + { + /* If the aggregate has no user defined constructors, we allow + it to have fields with the same name as the enclosing type. + If we are looking for that name, find the corresponding + TYPE_DECL. */ + for (nval = TREE_CHAIN (nval); nval; nval = TREE_CHAIN (nval)) + if (DECL_NAME (nval) == lfi->name + && TREE_CODE (nval) == TYPE_DECL) + break; + } + else + nval = NULL_TREE; + if (!nval) + { + nval = purpose_member (lfi->name, CLASSTYPE_TAGS (type)); + if (nval) + nval = TYPE_MAIN_DECL (TREE_VALUE (nval)); + else + return NULL_TREE; + } } /* You must name a template base class with a template-id. */ diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 78f191f..1ceeb40 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,9 @@ 2001-04-20 Jakub Jelinek <jakub@redhat.com> + * g++.old-deja/g++.other/lookup23.C: New test. + +2001-04-20 Jakub Jelinek <jakub@redhat.com> + * gcc.c-torture/execute/20010403-1.c: New test. 2001-04-19 David Billinghurst <David.Billinghurst@riotinto.com> diff --git a/gcc/testsuite/g++.old-deja/g++.other/lookup23.C b/gcc/testsuite/g++.old-deja/g++.other/lookup23.C new file mode 100644 index 0000000..9deee9e --- /dev/null +++ b/gcc/testsuite/g++.old-deja/g++.other/lookup23.C @@ -0,0 +1,13 @@ +// Test for proper handling of type lookup if base class has field with the +// same name as the containing class. +// Build don't link: + +struct a { int a; }; +struct b : a {}; + +b x; + +void foo () +{ + x.a = 22; +} |