diff options
author | Nathan Sidwell <nathan@codesourcery.com> | 2003-07-10 09:02:06 +0000 |
---|---|---|
committer | Nathan Sidwell <nathan@gcc.gnu.org> | 2003-07-10 09:02:06 +0000 |
commit | 633221dbab4b06bae16c5cd3b6da0c91608fb5ff (patch) | |
tree | 76650e1120092ea70d8d68f3ac66639be6583a19 /gcc | |
parent | 31c56a8ba7c10ccacfa1f3566d8eb16dddadbfd2 (diff) | |
download | gcc-633221dbab4b06bae16c5cd3b6da0c91608fb5ff.zip gcc-633221dbab4b06bae16c5cd3b6da0c91608fb5ff.tar.gz gcc-633221dbab4b06bae16c5cd3b6da0c91608fb5ff.tar.bz2 |
PR c++ 9483
cp:
PR c++ 9483
* class.c (check_field_decls): Pass DECL_NAME to constructor_name_p.
* decl2.c (constructor_name_p): Avoid repeated constructor_name
calls.
* decl.c (grokdeclarator): Refactor ctor/dtor detection.
testsuite:
PR c++ 9483
* g++.dg/other/field1.C: New test.
From-SVN: r69180
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/cp/ChangeLog | 8 | ||||
-rw-r--r-- | gcc/cp/class.c | 2 | ||||
-rw-r--r-- | gcc/cp/decl.c | 15 | ||||
-rw-r--r-- | gcc/cp/decl2.c | 17 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/other/field1.C | 25 |
5 files changed, 58 insertions, 9 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 7e70998..0f91172 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,11 @@ +2003-07-09 Nathan Sidwell <nathan@codesourcery.com> + + PR c++ 9483 + * class.c (check_field_decls): Pass DECL_NAME to constructor_name_p. + * decl2.c (constructor_name_p): Avoid repeated constructor_name + calls. + * decl.c (grokdeclarator): Refactor ctor/dtor detection. + 2003-07-09 Mark Mitchell <mark@codesourcery.com> * typeck.c (build_x_unary_op): Take note of the fact that diff --git a/gcc/cp/class.c b/gcc/cp/class.c index 5c276a4..bac2e09 100644 --- a/gcc/cp/class.c +++ b/gcc/cp/class.c @@ -3177,7 +3177,7 @@ check_field_decls (tree t, tree *access_decls, /* Core issue 80: A nonstatic data member is required to have a different name from the class iff the class has a user-defined constructor. */ - if (constructor_name_p (x, t) && TYPE_HAS_CONSTRUCTOR (t)) + if (constructor_name_p (DECL_NAME (x), t) && TYPE_HAS_CONSTRUCTOR (t)) cp_pedwarn_at ("field `%#D' with same name as class", x); /* We set DECL_C_BIT_FIELD in grokbitfield. diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 4534a76..8ed5213 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -9911,16 +9911,19 @@ grokdeclarator (tree declarator, decl = *next; if (ctype) { - if (TREE_CODE (decl) == IDENTIFIER_NODE - && constructor_name_p (decl, ctype)) + tree name = decl; + + if (TREE_CODE (name) == BIT_NOT_EXPR) + name = TREE_OPERAND (name, 0); + + if (!constructor_name_p (decl, ctype)) + ; + else if (decl == name) { sfk = sfk_constructor; ctor_return_type = ctype; } - else if (TREE_CODE (decl) == BIT_NOT_EXPR - && TREE_CODE (TREE_OPERAND (decl, 0)) == IDENTIFIER_NODE - && constructor_name_p (TREE_OPERAND (decl, 0), - ctype)) + else { sfk = sfk_destructor; ctor_return_type = ctype; diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c index c77e503..9a0185b 100644 --- a/gcc/cp/decl2.c +++ b/gcc/cp/decl2.c @@ -1190,8 +1190,21 @@ constructor_name (tree type) bool constructor_name_p (tree name, tree type) { - return (name == constructor_name (type) - || name == constructor_name_full (type)); + tree ctor_name; + + if (!name) + return false; + + if (TREE_CODE (name) != IDENTIFIER_NODE) + return false; + + ctor_name = constructor_name_full (type); + if (name == ctor_name) + return true; + if (IDENTIFIER_TEMPLATE (ctor_name) + && name == IDENTIFIER_TEMPLATE (ctor_name)) + return true; + return false; } diff --git a/gcc/testsuite/g++.dg/other/field1.C b/gcc/testsuite/g++.dg/other/field1.C new file mode 100644 index 0000000..3afe3d90 --- /dev/null +++ b/gcc/testsuite/g++.dg/other/field1.C @@ -0,0 +1,25 @@ +// { dg-do compile } + +// Copyright (C) 2003 Free Software Foundation, Inc. +// Contributed by Nathan Sidwell 9 Jul 2003 <nathan@codesourcery.com> + +// PR c++ 9483. accepted fields with same name as class + +struct test +{ + char test; // { dg-error "with same name as class" "" } + test(); +}; + +template <typename T> struct X +{ + char X; // { dg-error "with same name as class" "" } + X (); +}; + +template <> struct X<int> { + char X; // { dg-error "with same name as class" "" } + X(); +}; + +X<float> i; // { dg-error "instantiated from" "" } |