This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [rfa] Add -Wswitch-default
> Andrew Cagney <ac131313@cygnus.com> writes:
>
>
>> As for a test case, I couldn't find anywhere to add one. Guess I
>> should file a bug report.
>
>
> The test goes in gcc/testsuite/gcc.dg, something like
Ah, thanks. See attached. BTW, does the 8.3 rule in
gcc/testsuite/gcc.dg/README still apply? Looking around I suspect it
doesn't.
>> Anyway, ok to commit?
>
>
> The patch is OK, with a suitable testcase, but GCC is presently
> feature-frozen before a release, see
> <http://gcc.gnu.org/develop.html>. It'll unfreeze after 15 Feb.
M'kay, add entry to diary. Is the OK also for doco?
Andrew
Index: ChangeLog
2002-02-02 Andrew Cagney <ac131313@redhat.com>
* gcc.dg/Wswitch-default.c: New test.
Index: gcc.dg/Wswitch-default.c
===================================================================
RCS file: Wswitch-default.c
diff -N Wswitch-default.c
*** /dev/null Tue May 5 13:32:27 1998
--- Wswitch-default.c Sat Feb 2 16:42:36 2002
***************
*** 0 ****
--- 1,49 ----
+ /* { dg-do compile } */
+ /* { dg-options "-Wswitch-default" } */
+
+ enum e { e1, e2 };
+
+ int
+ foo (int i, int j, enum e ei, enum e ej, enum e ek, enum e el,
+ enum e em, enum e en)
+ {
+ switch (i)
+ {
+ case 1: return 1;
+ case 2: return 2;
+ } /* { dg-warning "switch missing default case" } */
+ switch (j)
+ {
+ case 3: return 4;
+ case 4: return 3;
+ default: return 7;
+ }
+ switch (ei)
+ { /* { dg-warning "switch missing default case" } */
+ }
+ switch (ej)
+ {
+ default: break;
+ }
+ switch (ek)
+ {
+ case e1: return 1;
+ } /* { dg-warning "switch missing default case" } */
+ switch (el)
+ {
+ case e1: return 1;
+ default: break;
+ }
+ switch (em)
+ {
+ case e1: return 1;
+ case e2: return 2;
+ } /* { dg-warning "switch missing default case" } */
+ switch (en)
+ {
+ case e1: return 1;
+ case e2: return 2;
+ default: break;
+ }
+ return 0;
+ }