From 006fbbe9526698a7828023b6710acc478b845e18 Mon Sep 17 00:00:00 2001 From: Paolo Carlini Date: Wed, 2 May 2018 18:15:56 +0000 Subject: [PATCH] re PR c++/68374 (G++ -Wshadow doesn't warn about static member shadowing) /cp 2018-05-02 Paolo Carlini Jason Merrill PR c++/68374 * name-lookup.c (check_local_shadow): Don't handle static old declarations in the block handling locals shadowing locals. /testsuite 2018-05-02 Paolo Carlini Jason Merrill PR c++/68374 * g++.dg/warn/Wshadow-13.C: New. * g++.dg/warn/Wshadow-14.C: Likewise. Co-Authored-By: Jason Merrill From-SVN: r259853 --- gcc/cp/ChangeLog | 7 +++++++ gcc/cp/name-lookup.c | 1 + gcc/testsuite/ChangeLog | 7 +++++++ gcc/testsuite/g++.dg/warn/Wshadow-13.C | 8 ++++++++ gcc/testsuite/g++.dg/warn/Wshadow-14.C | 10 ++++++++++ 5 files changed, 33 insertions(+) create mode 100644 gcc/testsuite/g++.dg/warn/Wshadow-13.C create mode 100644 gcc/testsuite/g++.dg/warn/Wshadow-14.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 604e704fb2c..fadcea80a94 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,10 @@ +2018-05-02 Paolo Carlini + Jason Merrill + + PR c++/68374 + * name-lookup.c (check_local_shadow): Don't handle static old + declarations in the block handling locals shadowing locals. + 2018-05-01 Jason Merrill PR c++/85587 - error with scoped enum in template. diff --git a/gcc/cp/name-lookup.c b/gcc/cp/name-lookup.c index 64c7b6f006e..08cabd68a84 100644 --- a/gcc/cp/name-lookup.c +++ b/gcc/cp/name-lookup.c @@ -2642,6 +2642,7 @@ check_local_shadow (tree decl) || (TREE_CODE (old) == TYPE_DECL && (!DECL_ARTIFICIAL (old) || TREE_CODE (decl) == TYPE_DECL))) + && DECL_FUNCTION_SCOPE_P (old) && (!DECL_ARTIFICIAL (decl) || DECL_IMPLICIT_TYPEDEF_P (decl) || (VAR_P (decl) && DECL_ANON_UNION_VAR_P (decl)))) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 9c290eb1e68..6ddb945c70e 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,10 @@ +2018-05-02 Paolo Carlini + Jason Merrill + + PR c++/68374 + * g++.dg/warn/Wshadow-13.C: New. + * g++.dg/warn/Wshadow-14.C: Likewise. + 2018-05-02 Tom de Vries PR libgomp/82428 diff --git a/gcc/testsuite/g++.dg/warn/Wshadow-13.C b/gcc/testsuite/g++.dg/warn/Wshadow-13.C new file mode 100644 index 00000000000..d75560c8e9e --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wshadow-13.C @@ -0,0 +1,8 @@ +// PR c++/68374 +// { dg-options "-Wshadow" } + +class f { + static int mVar; // { dg-message "shadowed declaration" } + int g(int x) { int mVar=3; return x+mVar; } // { dg-warning "shadows a member of 'f'" } +}; +int f::mVar = 1; diff --git a/gcc/testsuite/g++.dg/warn/Wshadow-14.C b/gcc/testsuite/g++.dg/warn/Wshadow-14.C new file mode 100644 index 00000000000..e0e3d029291 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wshadow-14.C @@ -0,0 +1,10 @@ +// PR c++/68374 +// { dg-options "-Wshadow" } + +void foo () +{ + static int i; // { dg-message "shadowed declaration" } + { + int i; // { dg-warning "shadows a previous local" } + } +} -- 2.30.2