+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
/* 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.
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;
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
--- /dev/null
+// { 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" "" }