aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp/name-lookup.cc
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2022-02-08 20:17:55 +0100
committerJakub Jelinek <jakub@redhat.com>2022-02-08 20:17:55 +0100
commit71e6353e1b03021bc8bbcf4bd67a5f14d09b5fb1 (patch)
tree61a6e031d2366ecaca9bd0493fb53ecea0e40ebf /gcc/cp/name-lookup.cc
parent1755141a9ea0dddabb52776cddc4c9325eed27c6 (diff)
downloadgcc-71e6353e1b03021bc8bbcf4bd67a5f14d09b5fb1.zip
gcc-71e6353e1b03021bc8bbcf4bd67a5f14d09b5fb1.tar.gz
gcc-71e6353e1b03021bc8bbcf4bd67a5f14d09b5fb1.tar.bz2
c++: Don't emit repeated -Wshadow warnings for templates/ctors [PR104379]
The following patch suppresses extraneous -Wshadow warnings. On the testcase without the patch we emit 14 -Wshadow warnings, with the patch just 4. It is enough to warn once e.g. during parsing of the template or the abstract ctor, while previously we'd warn also on the clones of the ctors and on instantiation. In GCC 8 and earlier we didn't warn because check_local_shadow did /* Inline decls shadow nothing. */ if (DECL_FROM_INLINE (decl)) return; 2022-02-08 Jakub Jelinek <jakub@redhat.com> PR c++/104379 * name-lookup.cc (check_local_shadow): When diagnosing shadowing of a member or global declaration, add warning suppression for the decl and don't warn again on it. * g++.dg/warn/Wshadow-18.C: New test.
Diffstat (limited to 'gcc/cp/name-lookup.cc')
-rw-r--r--gcc/cp/name-lookup.cc24
1 files changed, 16 insertions, 8 deletions
diff --git a/gcc/cp/name-lookup.cc b/gcc/cp/name-lookup.cc
index 29b7f2e..93c4eb7 100644
--- a/gcc/cp/name-lookup.cc
+++ b/gcc/cp/name-lookup.cc
@@ -3296,18 +3296,22 @@ check_local_shadow (tree decl)
/* Warn if a variable shadows a non-function, or the variable
is a function or a pointer-to-function. */
- if (!OVL_P (member)
- || TREE_CODE (decl) == FUNCTION_DECL
- || (TREE_TYPE (decl)
- && (TYPE_PTRFN_P (TREE_TYPE (decl))
- || TYPE_PTRMEMFUNC_P (TREE_TYPE (decl)))))
+ if ((!OVL_P (member)
+ || TREE_CODE (decl) == FUNCTION_DECL
+ || (TREE_TYPE (decl)
+ && (TYPE_PTRFN_P (TREE_TYPE (decl))
+ || TYPE_PTRMEMFUNC_P (TREE_TYPE (decl)))))
+ && !warning_suppressed_p (decl, OPT_Wshadow))
{
auto_diagnostic_group d;
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))
- inform_shadowed (member);
+ {
+ inform_shadowed (member);
+ suppress_warning (decl, OPT_Wshadow);
+ }
}
return;
}
@@ -3319,14 +3323,18 @@ check_local_shadow (tree decl)
|| (TREE_CODE (old) == TYPE_DECL
&& (!DECL_ARTIFICIAL (old)
|| TREE_CODE (decl) == TYPE_DECL)))
- && !instantiating_current_function_p ())
+ && !instantiating_current_function_p ()
+ && !warning_suppressed_p (decl, OPT_Wshadow))
/* XXX shadow warnings in outer-more namespaces */
{
auto_diagnostic_group d;
if (warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wshadow,
"declaration of %qD shadows a global declaration",
decl))
- inform_shadowed (old);
+ {
+ inform_shadowed (old);
+ suppress_warning (decl, OPT_Wshadow);
+ }
return;
}