diff options
author | Le-Chun Wu <lcwu@google.com> | 2016-10-31 13:21:59 +0000 |
---|---|---|
committer | Mark Wielaard <mark@gcc.gnu.org> | 2016-10-31 13:21:59 +0000 |
commit | 84ff4775d41b716c1b862d4d91ff69127686b668 (patch) | |
tree | 37de03a0d419a258e63aa73193cee37e6d221b31 /gcc/common.opt | |
parent | 651795857809d5e504aa577c3912b98f4feaf397 (diff) | |
download | gcc-84ff4775d41b716c1b862d4d91ff69127686b668.tar.gz |
Add -Wshadow=global -Wshadow=local and -Wshadow=compatible-local.
This patch from Le-Chun Wu adds two new shadow warning flags for
C and C++:
-Wshadow=local which warns if a local variable shadows another local
variable or parameter,
-Wshadow=compatible-local which warns if a local variable shadows
another local variable or parameter whose type is compatible with
that of the shadowing variable.
It is already on the google/main branch (Google ref 39127) and was
previously submitted by Diego Novillo and reviewed on
http://codereview.appspot.com/4452058
I addressed the review comments and made the following changes:
- Add -Wshadow=global (the default alias for -Wshadow).
- Make the documented options -Wshadow=global, -Wshadow=local
and -Wshadow=compatible-local (with hidden undocumented aliases
-Wshadow-local and -Wshadow-compatible-local for compatibility).
- The -Wshadow=global, -Wshadow=local and -Wshadow=compatible-local
relationships are expressed in common.opt instead of in opts.c
and documented in invoke.texi.
- The "previous declaration" warnings were turned into notes and use
the (now) existing infrastructure instead of duplicating the warnings.
The testcases have been adjusted to expect the notes.
- The conditional change in name-lookup.c for non-locals (where we
don't want to change the warnings, but just check the global ones)
has been dropped.
- Use warning_at in c-decl.c (warn_if_shadowing).
gcc/ChangeLog:
2016-10-30 Le-Chun Wu <lcwu@google.com>
Mark Wielaard <mjw@redhat.com>
* doc/invoke.texi: Document Wshadow-local and Wshadow-compatible-local.
* common.opt (Wshadow=global): New option. Default for -Wshadow.
(Wshadow=local): New option.
(Wshadow-local): Hidden alias for -Wshadow=local.
(Wshadow=compatible-local): New option.
(Wshadow-compatible-local): Hidden alias for
-Wshadow=compatible-local.
* doc/invoke.texi: Document Wshadow=global, Wshadow=local and
Wshadow=compatible-local.
gcc/c/ChangeLog:
2016-10-30 Le-Chun Wu <lcwu@google.com>
Mark Wielaard <mjw@redhat.com>
* c-decl.c (warn_if_shadowing): Use the warning code corresponding
to the given -Wshadow= variant. Use warning_at.
gcc/cp/ChangeLog:
2016-10-30 Le-Chun Wu <lcwu@google.com>
Mark Wielaard <mjw@redhat.com>
* name-lookup.c (pushdecl_maybe_friend): When emitting a
shadowing warning, use the code corresponding to the
given -Wshadow= variant.
gcc/testsuite/ChangeLog
2016-10-30 Le-Chun Wu <lcwu@google.com>
Mark Wielaard <mjw@redhat.com>
* gcc.dg/Wshadow-compatible-local-1.c: New test.
* gcc.dg/Wshadow-local-1.c: Likewise.
* gcc.dg/Wshadow-local-2.c: Likewise.
* g++.dg/warn/Wshadow-compatible-local-1.C: Likewise.
* g++.dg/warn/Wshadow-local-1.C: Likewise.
* g++.dg/warn/Wshadow-local-2.C: Likewise.
Co-Authored-By: Mark Wielaard <mjw@redhat.com>
From-SVN: r241699
Diffstat (limited to 'gcc/common.opt')
-rw-r--r-- | gcc/common.opt | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/gcc/common.opt b/gcc/common.opt index 20dbfc1d6a1..2c2f7ad7aa9 100644 --- a/gcc/common.opt +++ b/gcc/common.opt @@ -668,7 +668,25 @@ Warn about returning a pointer/reference to a local or temporary variable. Wshadow Common Var(warn_shadow) Warning -Warn when one local variable shadows another. +Warn when one variable shadows another. Same as -Wshadow=global. + +Wshadow=global +Common Warning Alias(Wshadow) +Warn when one variable shadows another (globally). + +Wshadow=local +Common Var(warn_shadow_local) Warning EnabledBy(Wshadow) +Warn when one local variable shadows another local variable or parameter. + +Wshadow-local +Common Warning Undocumented Alias(Wshadow=local) + +Wshadow=compatible-local +Common Var(warn_shadow_compatible_local) Warning EnabledBy(Wshadow=local) +Warn when one local variable shadows another local variable or parameter of compatible type. + +Wshadow-compatible-local +Common Warning Undocumented Alias(Wshadow=compatible-local) Wstack-protector Common Var(warn_stack_protect) Warning |