Commit 633221db by Nathan Sidwell Committed by Nathan Sidwell

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
parent 31c56a8b
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
......
......@@ -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.
......
......@@ -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;
......
......@@ -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;
}
......
// { 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" "" }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment