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.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@100664
138bc75d-0d04-0410-961f-
82ee72b054a4
+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.
}
\f
-/* 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;
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
|| 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;
}
}
}
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
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
{
{
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. */
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);
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;
}
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 &
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)
{
/* 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;
+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
--- /dev/null
+// 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" }
+};
struct S
{
- void f () {}
- int f () { return 0; } // { dg-error "" "" }
+ void f () {} // { dg-error "with" "" }
+ int f () { return 0; } // { dg-error "overloaded" "" }
};
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;
};
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" } .*
};
// { 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
};
// { 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
};
}
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
};
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
};