Index: gcc/doc/invoke.texi |
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi |
index cffc70d..fa247b6 100644 |
--- a/gcc/doc/invoke.texi |
+++ b/gcc/doc/invoke.texi |
@@ -259,6 +259,7 @@ Objective-C and Objective-C++ Dialects}. |
-Wpointer-arith -Wno-pointer-to-int-cast @gol |
-Wredundant-decls -Wreturn-type -Wripa-opt-mismatch @gol |
-Wself-assign -Wself-assign-non-pod -Wsequence-point -Wshadow @gol |
+-Wshadow-compatible-local -Wshadow-local @gol |
-Wsign-compare -Wsign-conversion -Wstack-protector @gol |
-Wstrict-aliasing -Wstrict-aliasing=n @gol |
-Wstrict-overflow -Wstrict-overflow=@var{n} @gol |
@@ -4052,6 +4053,43 @@ parameter, type, or class member (in C++), or whenever a built-in function |
is shadowed. Note that in C++, the compiler will not warn if a local variable |
shadows a struct/class/enum, but will warn if it shadows an explicit typedef. |
+@item -Wshadow-local |
+@opindex Wshadow-local |
+@opindex Wno-shadow-local |
+Warn when a local variable shadows another local variable or parameter. |
+ |
+@item -Wshadow-compatible-local |
+@opindex Wshadow-compatible-local |
+@opindex Wno-shadow-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++, |
+type compatibility here means the type of the shadowing variable can be |
+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: |
+ |
+@smallexample |
+@group |
+for (SomeIterator i = SomeObj.begin(); i != SomeObj.end(); ++i) |
+@{ |
+ for (int i = 0; i < N; ++i) |
+ @{ |
+ ... |
+ @} |
+ ... |
+@} |
+@end group |
+@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. |
+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 |
+possibly reduce the number of warnings triggered by intentional shadowing. |
+ |
@item -Wlarger-than=@var{len} |
@opindex Wlarger-than=@var{len} |
@opindex Wlarger-than-@var{len} |