From: Paolo Carlini Date: Wed, 2 May 2018 18:15:56 +0000 (+0000) Subject: re PR c++/68374 (G++ -Wshadow doesn't warn about static member shadowing) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=006fbbe9526698a7828023b6710acc478b845e18;p=gcc.git 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 --- 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" } + } +}