diff options
author | Jason Merrill <jason@redhat.com> | 2022-04-05 16:02:04 -0400 |
---|---|---|
committer | Jason Merrill <jason@redhat.com> | 2022-04-06 10:30:12 -0400 |
commit | fd0024e48e94008915a6b18112efbbd8abc81ed8 (patch) | |
tree | 8e261348e8d5b2a5beb45f0b8f19595ffd282a8d | |
parent | e1a5e7562d53a8d2256f754714b06595bea72196 (diff) | |
download | gcc-fd0024e48e94008915a6b18112efbbd8abc81ed8.zip gcc-fd0024e48e94008915a6b18112efbbd8abc81ed8.tar.gz gcc-fd0024e48e94008915a6b18112efbbd8abc81ed8.tar.bz2 |
c++: -Wshadow=compatible-local type vs var [PR100608]
The patch for PR92024 changed -Wshadow=compatible-local to warn if either
new or old decl was a type, but the rationale only talked about the case
where both are types. If only one is, they aren't compatible.
PR c++/100608
gcc/cp/ChangeLog:
* name-lookup.cc (check_local_shadow): Use -Wshadow=local
if exactly one of 'old' and 'decl' is a type.
gcc/testsuite/ChangeLog:
* g++.dg/warn/Wshadow-compatible-local-3.C: New test.
-rw-r--r-- | gcc/cp/name-lookup.cc | 4 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/warn/Wshadow-compatible-local-3.C | 10 |
2 files changed, 14 insertions, 0 deletions
diff --git a/gcc/cp/name-lookup.cc b/gcc/cp/name-lookup.cc index c833b84..d16c577 100644 --- a/gcc/cp/name-lookup.cc +++ b/gcc/cp/name-lookup.cc @@ -3249,6 +3249,10 @@ check_local_shadow (tree decl) enum opt_code warning_code; if (warn_shadow) warning_code = OPT_Wshadow; + else if ((TREE_CODE (decl) == TYPE_DECL) + ^ (TREE_CODE (old) == TYPE_DECL)) + /* If exactly one is a type, they aren't compatible. */ + warning_code = OPT_Wshadow_local; else if ((TREE_TYPE (old) && TREE_TYPE (decl) && same_type_p (TREE_TYPE (old), TREE_TYPE (decl))) diff --git a/gcc/testsuite/g++.dg/warn/Wshadow-compatible-local-3.C b/gcc/testsuite/g++.dg/warn/Wshadow-compatible-local-3.C new file mode 100644 index 0000000..0e5ece7 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wshadow-compatible-local-3.C @@ -0,0 +1,10 @@ +// PR c++/100608 +// { dg-do compile { target c++11 } } +// { dg-additional-options "-Wshadow=compatible-local" } + +template <typename> class X {}; + +void foo() +{ + auto a = X<class a>{}; // no warning, not compatible +} |