OSDN Git Service

cp:
authornathan <nathan@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 6 Jun 2005 14:18:22 +0000 (14:18 +0000)
committernathan <nathan@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 6 Jun 2005 14:18:22 +0000 (14:18 +0000)
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

14 files changed:
gcc/cp/ChangeLog
gcc/cp/class.c
gcc/cp/cp-tree.h
gcc/cp/decl2.c
gcc/cp/method.c
gcc/cp/semantics.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/inherit/using4.C [new file with mode: 0644]
gcc/testsuite/g++.dg/overload/error1.C
gcc/testsuite/g++.old-deja/g++.benjamin/warn02.C
gcc/testsuite/g++.old-deja/g++.brendan/arm2.C
gcc/testsuite/g++.old-deja/g++.other/redecl2.C
gcc/testsuite/g++.old-deja/g++.other/redecl4.C
gcc/testsuite/g++.old-deja/g++.pt/memtemp78.C

index d965f8b..758451c 100644 (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.
index d982b39..8661931 100644 (file)
@@ -878,12 +878,12 @@ modify_vtable_entry (tree t,
 }
 
 \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;
@@ -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.  */
index bcc6b3f..6cf7fa0 100644 (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);
index 48febf7..0501b80 100644 (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;
 }
 
index ac85bf4..f5c7d2a 100644 (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)
index d969a24..76464ad 100644 (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;
index e9c45ce..9061d5f 100644 (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
diff --git a/gcc/testsuite/g++.dg/inherit/using4.C b/gcc/testsuite/g++.dg/inherit/using4.C
new file mode 100644 (file)
index 0000000..a0b3873
--- /dev/null
@@ -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" }
+}; 
index fcaa445..dd10d90 100644 (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" "" }
 };
index a2599aa..248e1ed 100644 (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;
 };
 
index 2cfa6b9..fb1ee42 100644 (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" } .*
 };
index 70f703b..0d6ccf6 100644 (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
 };
index 9b7f8c5..e3355da 100644 (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
   };
 }
index cd54f3a..7334835 100644 (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
 };