PR c++ 9483
authorNathan Sidwell <nathan@codesourcery.com>
Thu, 10 Jul 2003 09:02:06 +0000 (09:02 +0000)
committerNathan Sidwell <nathan@gcc.gnu.org>
Thu, 10 Jul 2003 09:02:06 +0000 (09:02 +0000)
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

gcc/cp/ChangeLog
gcc/cp/class.c
gcc/cp/decl.c
gcc/cp/decl2.c
gcc/testsuite/g++.dg/other/field1.C [new file with mode: 0644]

index 7e7099850a0f975e6f20c07456d2a38b2405020b..0f91172fcccc97c5ba0f93682c9d51cfdfded804 100644 (file)
@@ -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
index 5c276a4a3d03feadc2678a08798296f9d7588af4..bac2e0974a2112f30c60b34e0494280cd992b31c 100644 (file)
@@ -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.
index 4534a7622b967257ff476ce4dd1bc4307633ee14..8ed521341d4ab43c0ff9d72aff0fe20ca1987fa9 100644 (file)
@@ -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;
index c77e5039fb9a9d5a709907cbc3198b9c743266d8..9a0185bd75e85723e04ead8adffff6bab6ff22ba 100644 (file)
@@ -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;
 }
 
 \f
diff --git a/gcc/testsuite/g++.dg/other/field1.C b/gcc/testsuite/g++.dg/other/field1.C
new file mode 100644 (file)
index 0000000..3afe3d9
--- /dev/null
@@ -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" "" }