#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);
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)
{
&& 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);
result = chainon (result, void_list_node);
*parms = decls;
+ pointer_set_destroy (unique_decls);
return result;
}
--- /dev/null
+// 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'" }
+};