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 7e70998..0f91172 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 5c276a4..bac2e09 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 4534a76..8ed5213 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 c77e503..9a0185b 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" "" }