diff options
author | Marek Polacek <polacek@redhat.com> | 2019-09-24 14:40:24 +0000 |
---|---|---|
committer | Marek Polacek <mpolacek@gcc.gnu.org> | 2019-09-24 14:40:24 +0000 |
commit | a0aedc7a41c6756a30669632d3df22e05b174401 (patch) | |
tree | 97fccfffc60fafc496fb4cfb99831577a41d8df6 /gcc | |
parent | fea3397e56a3662a9b2361c14e427c9786042ebf (diff) | |
download | gcc-a0aedc7a41c6756a30669632d3df22e05b174401.zip gcc-a0aedc7a41c6756a30669632d3df22e05b174401.tar.gz gcc-a0aedc7a41c6756a30669632d3df22e05b174401.tar.bz2 |
PR c++/91868 - improve -Wshadow location.
* name-lookup.c (check_local_shadow): Use DECL_SOURCE_LOCATION
instead of input_location.
* g++.dg/warn/Wshadow-16.C: New test.
From-SVN: r276103
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/cp/ChangeLog | 4 | ||||
-rw-r--r-- | gcc/cp/name-lookup.c | 6 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 3 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/warn/Wshadow-16.C | 24 |
4 files changed, 34 insertions, 3 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 1cd2a63..f4c87c5 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,9 @@ 2019-09-24 Marek Polacek <polacek@redhat.com> + PR c++/91868 - improve -Wshadow location. + * name-lookup.c (check_local_shadow): Use DECL_SOURCE_LOCATION + instead of input_location. + PR c++/91845 - ICE with invalid pointer-to-member. * expr.c (mark_use): Use error_operand_p. * typeck2.c (build_m_component_ref): Check error_operand_p after diff --git a/gcc/cp/name-lookup.c b/gcc/cp/name-lookup.c index 8bbb92d..74f1072 100644 --- a/gcc/cp/name-lookup.c +++ b/gcc/cp/name-lookup.c @@ -2771,7 +2771,7 @@ check_local_shadow (tree decl) msg = "declaration of %qD shadows a previous local"; auto_diagnostic_group d; - if (warning_at (input_location, warning_code, msg, decl)) + if (warning_at (DECL_SOURCE_LOCATION (decl), warning_code, msg, decl)) inform_shadowed (old); return; } @@ -2798,7 +2798,7 @@ check_local_shadow (tree decl) || TYPE_PTRMEMFUNC_P (TREE_TYPE (decl))) { auto_diagnostic_group d; - if (warning_at (input_location, OPT_Wshadow, + if (warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wshadow, "declaration of %qD shadows a member of %qT", decl, current_nonlambda_class_type ()) && DECL_P (member)) @@ -2818,7 +2818,7 @@ check_local_shadow (tree decl) /* XXX shadow warnings in outer-more namespaces */ { auto_diagnostic_group d; - if (warning_at (input_location, OPT_Wshadow, + if (warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wshadow, "declaration of %qD shadows a global declaration", decl)) inform_shadowed (old); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index a38a057..b90eb6d 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,8 @@ 2019-09-24 Marek Polacek <polacek@redhat.com> + PR c++/91868 - improve -Wshadow location. + * g++.dg/warn/Wshadow-16.C: New test. + PR c++/91845 - ICE with invalid pointer-to-member. * g++.dg/cpp1y/pr91845.C: New test. diff --git a/gcc/testsuite/g++.dg/warn/Wshadow-16.C b/gcc/testsuite/g++.dg/warn/Wshadow-16.C new file mode 100644 index 0000000..bbf3a46 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wshadow-16.C @@ -0,0 +1,24 @@ +// PR c++/91868 - improve -Wshadow location. +// { dg-options "-Wshadow" } + +int global; // { dg-message "shadowed declaration" } + +struct S +{ + static int bar; // { dg-message "shadowed declaration" } + S (int i) { int bar // { dg-warning "19:declaration of .bar. shadows a member" } + (1); + int global // { dg-warning "9:declaration of .global. shadows a global declaration" } + (42); + } +}; + +void +foo () +{ + int xx; // { dg-message "shadowed declaration" } + { + S xx // { dg-warning "7:declaration of .xx. shadows a previous local" } + (42); + } +} |