decl.c (grokparms): Added new error for duplicate function parameters names in functi...
authorSimon Baldwin <simonb@google.com>
Mon, 23 Apr 2007 21:48:37 +0000 (21:48 +0000)
committerSimon Baldwin <simonb@gcc.gnu.org>
Mon, 23 Apr 2007 21:48:37 +0000 (21:48 +0000)
* cp/decl.c (grokparms): Added new error for duplicate function
parameters names in function prototypes, to match gcc behavior.

* testsuite/g++.dg/other/error15.C: New.
* testsuite/g++.dg/cpp0x/variadic-ex9.C: Renamed function parameter to
avoid triggering a "multiple parameters named" error.

From-SVN: r124083

gcc/cp/ChangeLog
gcc/cp/decl.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp0x/variadic-ex9.C
gcc/testsuite/g++.dg/other/error15.C [new file with mode: 0644]

index 1b19ffca397fdda8731e73f37feb93c4ec58e855..f3eb5debfd4695f1bbf149cd0d2f17d64849ff56 100644 (file)
@@ -1,3 +1,8 @@
+2007-04-23  Simon Baldwin  <simonb@google.com>
+
+       * decl.c (grokparms): Added new error for duplicate function
+       parameters names in function prototypes, to match gcc behavior.
+
 2007-04-23  Jan Hubicka  <jh@suse.cz>
 
        * cp/decl2.c (finish_objects): Do not call target constructor/destructor
index 76be0558faacb3d15665bcbf8a786a97cfba4079..de5338bbc1641ecd48613a1bc3d3e6270a59ee15 100644 (file)
@@ -52,6 +52,7 @@ Boston, MA 02110-1301, USA.  */
 #include "debug.h"
 #include "timevar.h"
 #include "tree-flow.h"
+#include "pointer-set.h"
 
 static tree grokparms (cp_parameter_declarator *, tree *);
 static const char *redeclaration_error_message (tree, tree);
@@ -8898,6 +8899,7 @@ grokparms (cp_parameter_declarator *first_parm, tree *parms)
   int ellipsis = !first_parm || first_parm->ellipsis_p;
   cp_parameter_declarator *parm;
   int any_error = 0;
+  struct pointer_set_t *unique_decls = pointer_set_create ();
 
   for (parm = first_parm; parm != NULL; parm = parm->next)
     {
@@ -8982,6 +8984,14 @@ grokparms (cp_parameter_declarator *first_parm, tree *parms)
           && parm->next)
         error ("parameter packs must be at the end of the parameter list");
 
+      if (DECL_NAME (decl))
+        {
+          if (pointer_set_contains (unique_decls, DECL_NAME (decl)))
+            error ("multiple parameters named %qD", DECL_NAME (decl));
+          else
+            pointer_set_insert (unique_decls, DECL_NAME (decl));
+        }
+
       TREE_CHAIN (decl) = decls;
       decls = decl;
       result = tree_cons (init, type, result);
@@ -8992,6 +9002,7 @@ grokparms (cp_parameter_declarator *first_parm, tree *parms)
     result = chainon (result, void_list_node);
   *parms = decls;
 
+  pointer_set_destroy (unique_decls);
   return result;
 }
 
index 1358818206e6c1c37f3fb3e529f3cbbea27db124..5c9223922bba5c0a3e2e59d1c0fa8d5581d4e373 100644 (file)
@@ -1,3 +1,9 @@
+2007-04-23  Simon Baldwin  <simonb@google.com>
+
+       * g++.dg/other/error15.C: New.
+       * g++.dg/cpp0x/variadic-ex9.C: Renamed function parameter to avoid
+       triggering a "multiple parameters named" error.
+
 2007-04-23  Thomas Koenig  <tkoenig@gcc.gnu.org>
 
        PR fortran/31618
index ec78a7a8e25a7e78787fb64e623560bf00c625ab..74215c99727c1e55a6638d73c29002438e6bbf23 100644 (file)
@@ -1,7 +1,7 @@
 // { dg-options "-std=gnu++0x" }
 template<typename... Args>              char& f(Args... args);         // #1
 template<typename T1, typename... Args> short& f(T1 a1, Args... args); // #2
-template<typename T1, typename T2>      int& f(T1 a2, T2 a2);          // #3
+template<typename T1, typename T2>      int& f(T1 a2, T2 a3);          // #3
 
 void g() {
   char& x = f();                      // calls #1
diff --git a/gcc/testsuite/g++.dg/other/error15.C b/gcc/testsuite/g++.dg/other/error15.C
new file mode 100644 (file)
index 0000000..0a5bae1
--- /dev/null
@@ -0,0 +1,60 @@
+// Test that duplicate function parameters are found in declarations.
+
+extern void g0 (int a, int b);
+extern void g1 (int a, float b);
+
+extern void f0 (int a,
+                int a);  // { dg-error "multiple parameters named 'a'" }
+extern void f1 (int a,
+                float a);  // { dg-error "multiple parameters named 'a'" }
+extern void f3 (int a, int b, int c,
+                int a);  // { dg-error "multiple parameters named 'a'" }
+extern void f4 (int a, int b, int c,
+                int a,
+                int a);  // { dg-error "multiple parameters named 'a'" }
+extern void f5 (int a, int b, int c, int d, int e, int f, int g, int h,
+                int a,
+                int i, int j, int k, int l, int m, int n, int o, int p,
+                int q, int r, int s, int t, int u, int v, int w, int x, int y,
+                int z);  // { dg-error "multiple parameters named 'a'" }
+
+extern void f6 (int a, int, int, int, int, int, int, int, int, int, int,
+                int a,
+                int, int, int, int, int, int, int, int, int, int, int,
+                float, float, float, float, float, float, float, float,
+                int);  // { dg-error "multiple parameters named 'a'" }
+
+extern void f7 (void (*a)(int),
+                void (*a)(int));  // { dg-error "multiple parameters named 'a'" }
+extern void f8 (float (*a)(int),
+                int (*a)(float));  // { dg-error "multiple parameters named 'a'" }
+
+extern void f9 (int a,
+                int a,
+                int a);
+// { dg-error "multiple parameters named 'a'" "" { target *-*-* } 34 }
+
+extern void f10 (int a,
+                 int b,
+                 int c,
+                 int c,
+                 int b,
+                 int a);
+// { dg-error "multiple parameters named 'a'" "" { target *-*-* } 42 }
+// { dg-error "multiple parameters named 'b'" "" { target *-*-* } 42 }
+// { dg-error "multiple parameters named 'c'" "" { target *-*-* } 42 }
+
+class C1 {
+ public:
+  void C1_g0 (int a, int b);
+  void C1_f0 (int a,
+              int a);  // { dg-error "multiple parameters named 'a'" }
+};
+
+template <class T>
+class C2 {
+ public:
+  void C2_g0 (T a, T b);
+  void C2_f0 (T a,
+              T a);  // { dg-error "multiple parameters named 'a'" }
+};