re PR c++/20637 (Confusing message with different using declarations)

cp:
PR c++/20637
	* cp-tree.h (add_method): Add using_decl parameter.
	* class.c (add_method): Add using_decl parameter.  Adjust error
	messages.
	(handle_using_decl): Pass the using decl to add_method.
	(clone_function_decl): Adjust add_member calls.
	* decl2.c (check_classfn): Likewise.
	* method.c (lazily_declare_fn): Likewise.
	* semantics.c (finish_member_declaration): Likewise.

	* method.c (synthesize_method): Use inform, not warning.
testsuite:
	PR c++/20637
	* g++.dg/inherit/using4.C: New.
	* g++.dg/overload/error1.C: Adjust expected errors.
	* g++.old-deja/g++.benjamin/warn02.C: Likewise.
	* g++.old-deja/g++.brendan/arm2.C: Likewise.
	* g++.old-deja/g++.other/redecl2.C: Likewise.
	* g++.old-deja/g++.other/redecl4.C: Likewise.
	* g++.old-deja/g++.pt/memtemp78.C: Likewise.

From-SVN: r100664
This commit is contained in:
Nathan Sidwell 2005-06-06 14:18:22 +00:00 committed by Nathan Sidwell
parent 3d7b7acc42
commit b2a9b2086a
14 changed files with 95 additions and 50 deletions

View File

@ -1,3 +1,17 @@
2005-06-06 Nathan Sidwell <nathan@codesourcery.com>
PR c++/20637
* cp-tree.h (add_method): Add using_decl parameter.
* class.c (add_method): Add using_decl parameter. Adjust error
messages.
(handle_using_decl): Pass the using decl to add_method.
(clone_function_decl): Adjust add_member calls.
* decl2.c (check_classfn): Likewise.
* method.c (lazily_declare_fn): Likewise.
* semantics.c (finish_member_declaration): Likewise.
* method.c (synthesize_method): Use inform, not warning.
2005-06-06 Hans-Peter Nilsson <hp@axis.se>
* config-lang.in (target_libs): Remove target-gperf.

View File

@ -878,12 +878,12 @@ modify_vtable_entry (tree t,
}
/* Add method METHOD to class TYPE. */
/* Add method METHOD to class TYPE. If USING_DECL is non-null, it is
the USING_DECL naming METHOD. */
void
add_method (tree type, tree method)
add_method (tree type, tree method, tree using_decl)
{
int using;
unsigned slot;
tree overload;
bool template_conv_p = false;
@ -897,7 +897,6 @@ add_method (tree type, tree method)
return;
complete_p = COMPLETE_TYPE_P (type);
using = (DECL_CONTEXT (method) != type);
conv_p = DECL_CONV_FN_P (method);
if (conv_p)
template_conv_p = (TREE_CODE (method) == TEMPLATE_DECL
@ -1024,21 +1023,28 @@ add_method (tree type, tree method)
|| same_type_p (TREE_TYPE (TREE_TYPE (fn)),
TREE_TYPE (TREE_TYPE (method)))))
{
if (using && DECL_CONTEXT (fn) == type)
/* Defer to the local function. */
return;
if (using_decl)
{
if (DECL_CONTEXT (fn) == type)
/* Defer to the local function. */
return;
if (DECL_CONTEXT (fn) == DECL_CONTEXT (method))
cp_error_at ("repeated using declaration %qD", using_decl);
else
cp_error_at ("using declaration %qD conflicts with a previous using declaration",
using_decl);
}
else
{
cp_error_at ("%q#D and %q#D cannot be overloaded",
method, fn);
/* We don't call duplicate_decls here to merge
the declarations because that will confuse
things if the methods have inline
definitions. In particular, we will crash
while processing the definitions. */
return;
cp_error_at ("%q#D cannot be overloaded", method);
cp_error_at ("with %q#D", fn);
}
/* We don't call duplicate_decls here to merge the
declarations because that will confuse things if the
methods have inline definitions. In particular, we
will crash while processing the definitions. */
return;
}
}
}
@ -1201,7 +1207,7 @@ handle_using_decl (tree using_decl, tree t)
if (flist)
for (; flist; flist = OVL_NEXT (flist))
{
add_method (t, OVL_CURRENT (flist));
add_method (t, OVL_CURRENT (flist), using_decl);
alter_access (t, OVL_CURRENT (flist), access);
}
else
@ -3829,10 +3835,10 @@ clone_function_decl (tree fn, int update_method_vec_p)
and a not-in-charge version. */
clone = build_clone (fn, complete_ctor_identifier);
if (update_method_vec_p)
add_method (DECL_CONTEXT (clone), clone);
add_method (DECL_CONTEXT (clone), clone, NULL_TREE);
clone = build_clone (fn, base_ctor_identifier);
if (update_method_vec_p)
add_method (DECL_CONTEXT (clone), clone);
add_method (DECL_CONTEXT (clone), clone, NULL_TREE);
}
else
{
@ -3851,14 +3857,14 @@ clone_function_decl (tree fn, int update_method_vec_p)
{
clone = build_clone (fn, deleting_dtor_identifier);
if (update_method_vec_p)
add_method (DECL_CONTEXT (clone), clone);
add_method (DECL_CONTEXT (clone), clone, NULL_TREE);
}
clone = build_clone (fn, complete_dtor_identifier);
if (update_method_vec_p)
add_method (DECL_CONTEXT (clone), clone);
add_method (DECL_CONTEXT (clone), clone, NULL_TREE);
clone = build_clone (fn, base_dtor_identifier);
if (update_method_vec_p)
add_method (DECL_CONTEXT (clone), clone);
add_method (DECL_CONTEXT (clone), clone, NULL_TREE);
}
/* Note that this is an abstract function that is never emitted. */

View File

@ -3667,7 +3667,7 @@ extern tree build_vfn_ref (tree, tree);
extern tree get_vtable_decl (tree, int);
extern void resort_type_method_vec
(void *, void *, gt_pointer_operator, void *);
extern void add_method (tree, tree);
extern void add_method (tree, tree, tree);
extern int currently_open_class (tree);
extern tree currently_open_derived_class (tree);
extern tree finish_struct (tree, tree);

View File

@ -709,7 +709,7 @@ check_classfn (tree ctype, tree function, tree template_parms)
case we'll only confuse ourselves when the function is declared
properly within the class. */
if (COMPLETE_TYPE_P (ctype))
add_method (ctype, function);
add_method (ctype, function, NULL_TREE);
return NULL_TREE;
}

View File

@ -806,8 +806,8 @@ synthesize_method (tree fndecl)
pop_deferring_access_checks ();
if (error_count != errorcount || warning_count != warningcount)
warning (0, "%Hsynthesized method %qD first required here ",
&input_location, fndecl);
inform ("%Hsynthesized method %qD first required here ",
&input_location, fndecl);
}
/* Use EXTRACTOR to locate the relevant function called for each base &
@ -1119,7 +1119,7 @@ lazily_declare_fn (special_function_kind sfk, tree type)
if (sfk == sfk_destructor)
check_for_override (fn, type);
/* Add it to CLASSTYPE_METHOD_VEC. */
add_method (type, fn);
add_method (type, fn, NULL_TREE);
/* Add it to TYPE_METHODS. */
if (sfk == sfk_destructor
&& DECL_VIRTUAL_P (fn)

View File

@ -2250,7 +2250,7 @@ finish_member_declaration (tree decl)
{
/* We also need to add this function to the
CLASSTYPE_METHOD_VEC. */
add_method (current_class_type, decl);
add_method (current_class_type, decl, NULL_TREE);
TREE_CHAIN (decl) = TYPE_METHODS (current_class_type);
TYPE_METHODS (current_class_type) = decl;

View File

@ -1,3 +1,14 @@
2005-06-06 Nathan Sidwell <nathan@codesourcery.com>
PR c++/20637
* g++.dg/inherit/using4.C: New.
* g++.dg/overload/error1.C: Adjust expected errors.
* g++.old-deja/g++.benjamin/warn02.C: Likewise.
* g++.old-deja/g++.brendan/arm2.C: Likewise.
* g++.old-deja/g++.other/redecl2.C: Likewise.
* g++.old-deja/g++.other/redecl4.C: Likewise.
* g++.old-deja/g++.pt/memtemp78.C: Likewise.
2005-06-05 David Billinghurst <David.Billinghurst@riotinto.com>
* gfortran.dg/f2c_5.f90: Add -w to dg-options

View File

@ -0,0 +1,14 @@
// Copyright (C) 2005 Free Software Foundation, Inc.
// Contributed by Nathan Sidwell 6 Jun 2005 <nathan@codesourcery.com>
// PR 20613:uninformative diagnostic
// Origin: Wolfgang Bangerth <bangerth@dealii.org>
struct B {
void f();
};
struct D : B {
using B::f;
using B::f; // { dg-error "repeated" }
};

View File

@ -2,6 +2,6 @@
struct S
{
void f () {}
int f () { return 0; } // { dg-error "" "" }
void f () {} // { dg-error "with" "" }
int f () { return 0; } // { dg-error "overloaded" "" }
};

View File

@ -31,16 +31,16 @@ class C
class D
{
public:
int foo2() {return b;}
int foo2() {return b;} // { dg-error "" }
int foo2() {return b;} // { dg-error "with" }
int foo2() {return b;} // { dg-error "overloaded" }
int b;
};
class E
{
public:
int foo2();
int foo2(); // { dg-error "" }
int foo2(); // { dg-error "with" }
int foo2(); // { dg-error "overloaded" }
int b;
};

View File

@ -8,12 +8,12 @@
class X {
public:
int foo();
static int foo(); // error: redeclaration// { dg-error "" } .*
int foo(); // { dg-error "with" }
static int foo(); // error: redeclaration// { dg-error "overloaded" } .*
};
class Y {
public:
static int foo();
int foo(); // error: redeclaration// { dg-error "" } .*
static int foo(); // { dg-error "with" }
int foo(); // error: redeclaration// { dg-error "overloaded" } .*
};

View File

@ -1,9 +1,9 @@
// { dg-do assemble }
struct S {
S(int);
S(int); // { dg-error "" } already declared
S(int); // { dg-error "with" }
S(int); // { dg-error "overloaded" } already declared
~S();
~S(); // { dg-error "" } already declared
~S();// { dg-error "with" }
~S(); // { dg-error "overloaded" } already declared
};

View File

@ -1,7 +1,7 @@
// { dg-do assemble }
int main() {
struct A {
void f();
void f(); // { dg-error "" } already declared
void f(); // { dg-error "with" } already declared
void f(); // { dg-error "overloaded" } already declared
};
}

View File

@ -23,10 +23,10 @@ template struct B<int>;
struct C
{
template <class U>
void f() {}
void f() {} // { dg-error "with" } redeclaration
template <class U>
void f() {} // { dg-error "" } redeclaration
void f() {} // { dg-error "overloaded" } redeclaration
};
@ -42,15 +42,15 @@ template struct D<int, double>;
template <class T, class U>
struct D2
{
void f(T);
void f(U); // { dg-error "" } redeclaration
void f(T); // { dg-error "with" } redeclaration
void f(U); // { dg-error "overloaded" } redeclaration
};
template struct D2<int, int>;
struct E
{
void f();
void f(); // { dg-error "" } redeclaration
void f(); // { dg-error "with" } redeclaration
void f(); // { dg-error "overloaded" } redeclaration
};