From e0d91792eec490d1bddb4a095a3da2c5b4c270e2 Mon Sep 17 00:00:00 2001 From: Bernd Edlinger Date: Wed, 30 Oct 2019 20:29:21 +0000 Subject: re PR c++/92024 (crash in check_local_shadow) 2019-10-30 Bernd Edlinger * doc/invoke.texi (-Wshadow, -Wshadow=global -Wshadow=local, -Wshadow=compatible-local): Update documentation. cp: 2019-10-30 Bernd Edlinger PR c++/92024 * name-lookup.c (check_local_shadow): Shadowing TYPE_DECLs is always a -Wshadow=compatible-local warning, unless -Wshadow is used. testsuite: 2019-10-30 Bernd Edlinger PR c++/92024 * g++.dg/parse/crash70.C: New test. * c-c++-common/Wshadow-1.c: New test. From-SVN: r277643 --- gcc/doc/invoke.texi | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) (limited to 'gcc/doc') diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index 1407d01..d1eb317 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -342,7 +342,7 @@ Objective-C and Objective-C++ Dialects}. -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 @@ -6309,7 +6309,7 @@ can be used to suppress such a warning. @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. @@ -6508,9 +6508,13 @@ allowed in GCC@. It is not supported by ISO C90. @xref{Mixed Declarations}. @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)} @@ -6521,20 +6525,19 @@ Objective-C method. @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: @@ -6553,16 +6556,15 @@ for (SomeIterator i = SomeObj.begin(); i != SomeObj.end(); ++i) @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= -- cgit v1.1