From 93d302144297d18f61298c3e92ab72436fc82322 Mon Sep 17 00:00:00 2001 From: zack Date: Thu, 4 Mar 2004 05:49:06 +0000 Subject: [PATCH] PR 13728 * c-decl.c (diagnose_mismatched_decls): Issue an error for two parameters with the same name, unless one is a forward decl. Do not issue a redundant-redeclaration warning for forward decls of parameters. * gcc.dg/decl-4.c: New testcase. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@78888 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/ChangeLog | 38 ++++++++++++++++++------------ gcc/c-decl.c | 23 ++++++++++++++---- gcc/testsuite/ChangeLog | 55 +++++++++++++++++++++++-------------------- gcc/testsuite/gcc.dg/decl-4.c | 10 ++++++++ 4 files changed, 81 insertions(+), 45 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/decl-4.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 2b8701e..f1dd35f 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,11 @@ +2004-03-03 Zack Weinberg + + PR 13728 + * c-decl.c (diagnose_mismatched_decls): Issue an error for two + parameters with the same name, unless one is a forward decl. + Do not issue a redundant-redeclaration warning for forward + decls of parameters. + 2004-03-04 David Edelsohn * doc/install.texi (*-ibm-aix*): Document use of Bash to speed up @@ -94,7 +102,7 @@ 2004-03-03 Stuart Hastings * gcc/config.gcc: Arrange for Darwin/x86 to build libgcc_eh.a. - + 2004-03-03 Eric Botcazou * config/sparc/sparc.c (noov_compare64_op): Fix typo. @@ -389,10 +397,10 @@ 2004-03-02 Richard Henderson - PR middle-end/11767 - * coverage.c (coverage_counter_ref): Set MEM_NOTRAP_P. - * optabs.c (prepare_cmp_insn): Force trapping memories to registers - before the compare, if flag_non_call_exceptions. + PR middle-end/11767 + * coverage.c (coverage_counter_ref): Set MEM_NOTRAP_P. + * optabs.c (prepare_cmp_insn): Force trapping memories to registers + before the compare, if flag_non_call_exceptions. 2004-03-02 Richard Henderson @@ -873,7 +881,7 @@ enable_rtl_dump_file): Declare. 2004-02-27 Eric Botcazou - Roger Sayle + Roger Sayle * fold-const.c (fold): Revert 2004-02-25 change. Use the original operands to build a tree with swapped operands. @@ -1084,11 +1092,11 @@ 2004-02-24 Aldy Hernandez - * config/rs6000/spe.md (spe_fix_truncsfsi2): Delete. - (spe_fixuns_truncsfsi2): Delete. + * config/rs6000/spe.md (spe_fix_truncsfsi2): Delete. + (spe_fixuns_truncsfsi2): Delete. - * config/rs6000/rs6000.md (fix_truncsfsi2): Delete. - (fixuns_truncsfsi2): Delete. + * config/rs6000/rs6000.md (fix_truncsfsi2): Delete. + (fixuns_truncsfsi2): Delete. 2004-02-24 Josef Zlomek @@ -1578,7 +1586,7 @@ * config/i386/i386.c: Rename pni to sse3. * config/i386/i386.h: Likewise. - * config/i386/i386.md: Likewise. + * config/i386/i386.md: Likewise. * config/i386/pmmintrin.h: Likewise. * doc/extend.texi: Likewise. * doc/invoke.texi: Likewise. @@ -1628,7 +1636,7 @@ (movdf_softfloat64): Ditto. 2004-02-23 Fariborz Jahanian - * config/rs6000/rs6000.c (function_arg): call to + * config/rs6000/rs6000.c (function_arg): call to rs6000_mixed_function_arg for DFmode moved to allow normal DFmode incoming register assignment. @@ -1668,7 +1676,7 @@ TARGET_DEFAULT_SHORT_ENUMS. Update the description. 2004-02-23 Eric Botcazou - Falk Hueffner + Falk Hueffner PR c/14188 * builtins.c (expand_builtin_va_arg): Emit an informative message @@ -1810,7 +1818,7 @@ 2004-02-20 John David Anglin - PR c++/12007 + PR c++/12007 * dbxout.c (dbxout_parms): Check that DECL_RTL and DECL_INCOMING_RTL are set for parameters before outputing debugging information. @@ -1860,7 +1868,7 @@ 2004-02-20 Matt Kraai * doc/install.texi (Building the Ada compiler): Remove - example. + example. 2004-02-20 James E Wilson diff --git a/gcc/c-decl.c b/gcc/c-decl.c index 1145363..5a4a28f 100644 --- a/gcc/c-decl.c +++ b/gcc/c-decl.c @@ -1211,8 +1211,18 @@ diagnose_mismatched_decls (tree newdecl, tree olddecl, } } } - else /* VAR_DECL */ + else /* PARM_DECL, VAR_DECL */ { + /* Redeclaration of a PARM_DECL is invalid unless this is the + real position of a forward-declared parameter (GCC extension). */ + if (TREE_CODE (newdecl) == PARM_DECL + && (!TREE_ASM_WRITTEN (olddecl) || TREE_ASM_WRITTEN (newdecl))) + { + error ("%Jredefinition of parameter '%D'", newdecl, newdecl); + locate_old_decl (olddecl, error); + return false; + } + /* These bits are only type qualifiers when applied to objects. */ if (TREE_THIS_VOLATILE (newdecl) != TREE_THIS_VOLATILE (olddecl)) { @@ -1241,10 +1251,13 @@ diagnose_mismatched_decls (tree newdecl, tree olddecl, && warn_redundant_decls /* Don't warn about a function declaration followed by a definition. */ - && !(TREE_CODE (newdecl) == FUNCTION_DECL - && DECL_INITIAL (newdecl) && !DECL_INITIAL (olddecl)) - /* Don't warn about an extern followed by a definition. */ - && !(DECL_EXTERNAL (olddecl) && !DECL_EXTERNAL (newdecl))) + && !(TREE_CODE (newdecl) == FUNCTION_DECL + && DECL_INITIAL (newdecl) && !DECL_INITIAL (olddecl)) + /* Don't warn about an extern followed by a definition. */ + && !(DECL_EXTERNAL (olddecl) && !DECL_EXTERNAL (newdecl)) + /* Don't warn about forward parameter decls. */ + && !(TREE_CODE (newdecl) == PARM_DECL + && TREE_ASM_WRITTEN (olddecl) && !TREE_ASM_WRITTEN (newdecl))) { warning ("%Jredundant redeclaration of '%D'", newdecl, newdecl); warned = true; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 07317d5..b0edee4 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2004-03-03 Zack Weinberg + + PR 13728 + * gcc.dg/decl-4.c: New testcase. + 2004-03-03 Kazu Hirata * gcc.dg/torture/builtin-explog-1.c (PREC): Make it the same @@ -23,7 +28,7 @@ PR c++/14360 * g++.old-deja/g++.ns/koenig5.C: Remove some error markers. - + PR c++/14361 * g++.dg/parse/defarg7.C: New test. @@ -92,8 +97,8 @@ 2004-02-26 Richard Henderson - * g++.dg/ext/attrib10.C: Mark for warning. - * gcc.dg/attr-alias-1.c: New. + * g++.dg/ext/attrib10.C: Mark for warning. + * gcc.dg/attr-alias-1.c: New. 2004-02-26 Richard Henderson @@ -105,28 +110,28 @@ * lib/target-supports.exp (check-iconv-available): New function. * lib/gcc-dg.exp (dg-require-iconv): New function. Use above. - * gcc.dg/charset: New directory. - * gcc.dg/charset/charset.exp: New file. - * gcc.dg/charset/asm1.c: Ditto. - * gcc.dg/charset/asm2.c: Ditto. - * gcc.dg/charset/asm3.c: Ditto. - * gcc.dg/charset/asm4.c: Ditto. - * gcc.dg/charset/asm5.c: Ditto. - * gcc.dg/charset/attribute1.c: Ditto. - * gcc.dg/charset/attribute2.c: Ditto. - * gcc.dg/charset/string1.c: Ditto. - * g++.dg/charset: New directory. - * g++.dg/dg.exp: Add here. Special options. - * g++.dg/charset/charset.exp: New file. - * g++.dg/charset/asm1.c: Ditto. - * g++.dg/charset/asm2.c: Ditto. - * g++.dg/charset/asm3.c: Ditto. - * g++.dg/charset/asm4.c: Ditto. - * g++.dg/charset/attribute1.c: Ditto. - * g++.dg/charset/attribute2.c: Ditto. - * g++.dg/charset/extern1.cc: Ditto. - * g++.dg/charset/extern2.cc: Ditto. - * g++.dg/charset/string1.c: Ditto. + * gcc.dg/charset: New directory. + * gcc.dg/charset/charset.exp: New file. + * gcc.dg/charset/asm1.c: Ditto. + * gcc.dg/charset/asm2.c: Ditto. + * gcc.dg/charset/asm3.c: Ditto. + * gcc.dg/charset/asm4.c: Ditto. + * gcc.dg/charset/asm5.c: Ditto. + * gcc.dg/charset/attribute1.c: Ditto. + * gcc.dg/charset/attribute2.c: Ditto. + * gcc.dg/charset/string1.c: Ditto. + * g++.dg/charset: New directory. + * g++.dg/dg.exp: Add here. Special options. + * g++.dg/charset/charset.exp: New file. + * g++.dg/charset/asm1.c: Ditto. + * g++.dg/charset/asm2.c: Ditto. + * g++.dg/charset/asm3.c: Ditto. + * g++.dg/charset/asm4.c: Ditto. + * g++.dg/charset/attribute1.c: Ditto. + * g++.dg/charset/attribute2.c: Ditto. + * g++.dg/charset/extern1.cc: Ditto. + * g++.dg/charset/extern2.cc: Ditto. + * g++.dg/charset/string1.c: Ditto. 2004-02-26 Mark Mitchell diff --git a/gcc/testsuite/gcc.dg/decl-4.c b/gcc/testsuite/gcc.dg/decl-4.c new file mode 100644 index 0000000..acc7e77 --- /dev/null +++ b/gcc/testsuite/gcc.dg/decl-4.c @@ -0,0 +1,10 @@ +/* Redeclaration of parameters is an error. PR 13728. */ +/* { dg-do compile } */ + +void f (int fred, /* { dg-error "previous definition" "" } */ + int fred); /* { dg-error "redefinition of parameter" "" } */ + +void f2 (int fred, /* { dg-error "previous definition" "" } */ + int fred) /* { dg-error "redefinition of parameter" "" } */ +{ +} -- 2.7.4