parameter, more than often they would use the variable
thinking (mistakenly) it's still the parameter. It would be
rare that users would use the variable in the place that
- expects the parameter but thinking it's a new decl. */
+ expects the parameter but thinking it's a new decl.
+ If either object is a TYPE_DECL, '-Wshadow=compatible-local'
+ warns regardless of whether one of the types involved
+ is a subclass of the other, since that is never okay. */
enum opt_code warning_code;
if (warn_shadow)
warning_code = OPT_Wshadow;
- else if (warn_shadow_local)
- warning_code = OPT_Wshadow_local;
- else if (warn_shadow_compatible_local
- && (same_type_p (TREE_TYPE (old), TREE_TYPE (decl))
- || (!dependent_type_p (TREE_TYPE (decl))
- && !dependent_type_p (TREE_TYPE (old))
- /* If the new decl uses auto, we don't yet know
- its type (the old type cannot be using auto
- at this point, without also being
- dependent). This is an indication we're
- (now) doing the shadow checking too
- early. */
- && !type_uses_auto (TREE_TYPE (decl))
- && can_convert (TREE_TYPE (old), TREE_TYPE (decl),
- tf_none))))
+ else if (same_type_p (TREE_TYPE (old), TREE_TYPE (decl))
+ || TREE_CODE (decl) == TYPE_DECL
+ || TREE_CODE (old) == TYPE_DECL
+ || (!dependent_type_p (TREE_TYPE (decl))
+ && !dependent_type_p (TREE_TYPE (old))
+ /* If the new decl uses auto, we don't yet know
+ its type (the old type cannot be using auto
+ at this point, without also being
+ dependent). This is an indication we're
+ (now) doing the shadow checking too
+ early. */
+ && !type_uses_auto (TREE_TYPE (decl))
+ && can_convert (TREE_TYPE (old), TREE_TYPE (decl),
+ tf_none)))
warning_code = OPT_Wshadow_compatible_local;
else
- return;
+ warning_code = OPT_Wshadow_local;
const char *msg;
if (TREE_CODE (old) == PARM_DECL)
-Wno-pragmas -Wno-prio-ctor-dtor -Wredundant-decls @gol
-Wrestrict -Wno-return-local-addr @gol
-Wreturn-type -Wsequence-point -Wshadow -Wno-shadow-ivar @gol
--Wshadow=global, -Wshadow=local, -Wshadow=compatible-local @gol
+-Wshadow=global -Wshadow=local -Wshadow=compatible-local @gol
-Wshift-overflow -Wshift-overflow=@var{n} @gol
-Wshift-count-negative -Wshift-count-overflow -Wshift-negative-value @gol
-Wsign-compare -Wsign-conversion -Wfloat-conversion @gol
@opindex Wno-discarded-array-qualifiers
@opindex Wdiscarded-array-qualifiers
Do not warn if type qualifiers on arrays which are pointer targets
-are being discarded. Typically, the compiler warns if a
+are being discarded. Typically, the compiler warns if a
@code{const int (*)[]} variable is passed to a function that
takes a @code{int (*)[]} parameter. This option can be used to
suppress such a warning.
@opindex Wno-shadow
Warn whenever a local variable or type declaration shadows another
variable, parameter, type, class member (in C++), or instance variable
-(in Objective-C) or whenever a built-in function is shadowed. Note
+(in Objective-C) or whenever a built-in function is shadowed. Note
that in C++, the compiler warns if a local variable shadows an
explicit typedef, but not if it shadows a struct/class/enum.
+If this warning is enabled, it includes also all instances of
+local shadowing. This means that @option{-Wno-shadow=local}
+and @option{-Wno-shadow=compatible-local} are ignored when
+@option{-Wshadow} is used.
Same as @option{-Wshadow=global}.
@item -Wno-shadow-ivar @r{(Objective-C only)}
@item -Wshadow=global
@opindex Wshadow=global
-The default for @option{-Wshadow}. Warns for any (global) shadowing.
-This warning is enabled by @option{-Wshadow=global}.
+Warn for any shadowing.
+Same as @option{-Wshadow}.
@item -Wshadow=local
@opindex Wshadow=local
Warn when a local variable shadows another local variable or parameter.
-This warning is enabled by @option{-Wshadow=local}.
@item -Wshadow=compatible-local
@opindex Wshadow=compatible-local
Warn when a local variable shadows another local variable or parameter
-whose type is compatible with that of the shadowing variable. In C++,
+whose type is compatible with that of the shadowing variable. In C++,
type compatibility here means the type of the shadowing variable can be
-converted to that of the shadowed variable. The creation of this flag
+converted to that of the shadowed variable. The creation of this flag
(in addition to @option{-Wshadow=local}) is based on the idea that when
a local variable shadows another one of incompatible type, it is most
likely intentional, not a bug or typo, as shown in the following example:
@end smallexample
Since the two variable @code{i} in the example above have incompatible types,
-enabling only @option{-Wshadow=compatible-local} will not emit a warning.
+enabling only @option{-Wshadow=compatible-local} does not emit a warning.
Because their types are incompatible, if a programmer accidentally uses one
-in place of the other, type checking will catch that and emit an error or
-warning. So not warning (about shadowing) in this case will not lead to
-undetected bugs. Use of this flag instead of @option{-Wshadow=local} can
+in place of the other, type checking is expected to catch that and emit an
+error or warning. Use of this flag instead of @option{-Wshadow=local} can
possibly reduce the number of warnings triggered by intentional shadowing.
-Note that this does also mean that shadowing @code{const char *i} by
-@code{char *i} will not emit a warning.
+Note that this also means that shadowing @code{const char *i} by
+@code{char *i} does not emit a warning.
-This warning is enabled by @option{-Wshadow=compatible-local}.
+This warning is also enabled by @option{-Wshadow=local}.
@item -Wlarger-than=@var{byte-size}
@opindex Wlarger-than=