This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: C PATCH to add -Wswitch-unreachable (PR c/49859)
- From: Sandra Loosemore <sandra at codesourcery dot com>
- To: Marek Polacek <polacek at redhat dot com>, Jason Merrill <jason at redhat dot com>
- Cc: GCC Patches <gcc-patches at gcc dot gnu dot org>, Joseph Myers <joseph at codesourcery dot com>
- Date: Fri, 20 May 2016 20:17:50 -0600
- Subject: Re: C PATCH to add -Wswitch-unreachable (PR c/49859)
- Authentication-results: sourceware.org; auth=none
- References: <20160510181929 dot GE20450 at redhat dot com> <CADzB+2=5o2z4ztTa2e8WHwiNiKbeBj4Bue9a5LD-c=n72vVrtQ at mail dot gmail dot com> <20160520163634 dot GN1611 at redhat dot com>
On 05/20/2016 10:36 AM, Marek Polacek wrote:
diff --git gcc/doc/invoke.texi gcc/doc/invoke.texi
index f3d087f..5909b9d 100644
--- gcc/doc/invoke.texi
+++ gcc/doc/invoke.texi
@@ -297,7 +297,8 @@ Objective-C and Objective-C++ Dialects}.
-Wsuggest-attribute=@r{[}pure@r{|}const@r{|}noreturn@r{|}format@r{]} @gol
-Wsuggest-final-types @gol -Wsuggest-final-methods -Wsuggest-override @gol
-Wmissing-format-attribute -Wsubobject-linkage @gol
--Wswitch -Wswitch-default -Wswitch-enum -Wswitch-bool -Wsync-nand @gol
+-Wswitch -Wswitch-default -Wswitch-enum -Wswitch-bool @gol
+-Wswitch-unreachable -Wsync-nand @gol
-Wsystem-headers -Wtautological-compare -Wtrampolines -Wtrigraphs @gol
-Wtype-limits -Wundef @gol
-Wuninitialized -Wunknown-pragmas -Wunsafe-loop-optimizations @gol
I think this list is supposed to be alphabetized except with respect to
-Wno-foo being sorted as if it were -Wfoo. I realize there are other
inconsistencies, but can you at least keep the -Wswitch* entries in
proper order?
@@ -4144,6 +4145,39 @@ switch ((int) (a == 4))
@end smallexample
This warning is enabled by default for C and C++ programs.
+@item -Wswitch-unreachable
+@opindex Wswitch-unreachable
+@opindex Wno-switch-unreachable
+Warn whenever a @code{switch} statement contains statements between the
+controlling expression and the first case label, which will never be
+executed. For example:
+@smallexample
+@group
+switch (cond)
+ @{
+ i = 15;
+ @dots{}
+ case 5:
+ @dots{}
+ @}
+@end group
+@end smallexample
+@option{-Wswitch-unreachable} will not warn if the statement between the
s/will/does/
+controlling expression and the first case label is just a declaration:
+@smallexample
+@group
+switch (cond)
+ @{
+ int i;
+ @dots{}
+ case 5:
+ i = 5;
+ @dots{}
+ @}
+@end group
+@end smallexample
+This warning is enabled by default for C and C++ programs.
+
@item -Wsync-nand @r{(C and C++ only)}
@opindex Wsync-nand
@opindex Wno-sync-nand
The doc part of the patch is OK with those things fixed.
-Sandra