diff options
author | Marek Polacek <polacek@redhat.com> | 2020-04-13 19:06:39 -0400 |
---|---|---|
committer | Marek Polacek <polacek@redhat.com> | 2020-04-13 23:12:31 -0400 |
commit | 7eee265e6bd58bf48da70fef97f2ac7179a9f41c (patch) | |
tree | 8ebe35cd57de1d1b3b53a466bd5d453ddce37bff /gcc | |
parent | e020d2bbe80dd07cbd147ff4eaf5896a60c13575 (diff) | |
download | gcc-7eee265e6bd58bf48da70fef97f2ac7179a9f41c.zip gcc-7eee265e6bd58bf48da70fef97f2ac7179a9f41c.tar.gz gcc-7eee265e6bd58bf48da70fef97f2ac7179a9f41c.tar.bz2 |
c++: Improve redeclared parameter name diagnostic [PR94588]
While reviewing [basic.scope.param] I noticed we don't show the location
of the previous declaration when giving an error about "A parameter name
shall not be redeclared in the outermost block of the function definition".
PR c++/94588
* name-lookup.c (check_local_shadow): Add an inform call.
* g++.dg/diagnostic/redeclaration-1.C: Add dg-message.
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/cp/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/cp/name-lookup.c | 9 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/diagnostic/redeclaration-1.C | 2 |
4 files changed, 17 insertions, 4 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 65b648a..7d742c1 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2020-04-13 Marek Polacek <polacek@redhat.com> + + PR c++/94588 + * name-lookup.c (check_local_shadow): Add an inform call. + 2020-04-13 Patrick Palka <ppalka@redhat.com> PR c++/94521 diff --git a/gcc/cp/name-lookup.c b/gcc/cp/name-lookup.c index 8dd0b0d..9b68b15 100644 --- a/gcc/cp/name-lookup.c +++ b/gcc/cp/name-lookup.c @@ -2670,8 +2670,8 @@ check_local_shadow (tree decl) } /* Don't complain if it's from an enclosing function. */ else if (DECL_CONTEXT (old) == current_function_decl - && TREE_CODE (decl) != PARM_DECL - && TREE_CODE (old) == PARM_DECL) + && TREE_CODE (decl) != PARM_DECL + && TREE_CODE (old) == PARM_DECL) { /* Go to where the parms should be and see if we find them there. */ @@ -2681,11 +2681,14 @@ check_local_shadow (tree decl) /* Skip the ctor/dtor cleanup level. */ b = b->level_chain; - /* ARM $8.3 */ + /* [basic.scope.param] A parameter name shall not be redeclared + in the outermost block of the function definition. */ if (b->kind == sk_function_parms) { error_at (DECL_SOURCE_LOCATION (decl), "declaration of %q#D shadows a parameter", decl); + inform (DECL_SOURCE_LOCATION (old), + "%q#D previously declared here", old); return; } } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 723d484..2035cf6 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2020-04-13 Marek Polacek <polacek@redhat.com> + + PR c++/94588 + * g++.dg/diagnostic/redeclaration-1.C: Add dg-message. + 2020-04-13 Martin Sebor <msebor@redhat.com> PR c/92326 diff --git a/gcc/testsuite/g++.dg/diagnostic/redeclaration-1.C b/gcc/testsuite/g++.dg/diagnostic/redeclaration-1.C index a41a2b8..f0e43d4 100644 --- a/gcc/testsuite/g++.dg/diagnostic/redeclaration-1.C +++ b/gcc/testsuite/g++.dg/diagnostic/redeclaration-1.C @@ -1,5 +1,5 @@ void -foo (int i) +foo (int i) // { dg-message "10:.int i. previously declared here" } { int i // { dg-error "7:declaration of .int i. shadows a parameter" } (0); |