decl.c (grokparms): Added new error for duplicate function parameters names in function prototypes...
* 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
This commit is contained in:
parent
22099c59a2
commit
0d83bf5afb
5 changed files with 83 additions and 1 deletions
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
60
gcc/testsuite/g++.dg/other/error15.C
Normal file
60
gcc/testsuite/g++.dg/other/error15.C
Normal file
|
@ -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'" }
|
||||
};
|
Loading…
Add table
Reference in a new issue