[cfe-commits] r148640 - in /cfe/trunk: include/clang/Basic/DiagnosticGroups.td include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaStmt.cpp test/Sema/switch.c test/Sema/warn-unreachable.c test/SemaCXX/gnu-case-ranges.cpp test/SemaCXX/return-noreturn.cpp

Fariborz Jahanian fjahanian at apple.com
Sat Jan 21 11:02:05 PST 2012


On Jan 21, 2012, at 10:12 AM, David Blaikie wrote:

> Author: dblaikie
> Date: Sat Jan 21 12:12:07 2012
> New Revision: 148640
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=148640&view=rev
> Log:
> Add -Wswitch-enum-redundant-default.
> 
> This warning acts as the complement to the main -Wswitch-enum warning (which
> warns whenever a switch over enum without a default doesn't cover all values of
> the enum) & has been an an-doc coding convention in LLVM and Clang in my
> experience. The purpose is to ensure there's never a "dead" default in a
> switch-over-enum because this would hide future -Wswitch-enum errors.

We have a related problem with -Wswitch-enum in clang. with this option a default should not turn
off the warning when default covers un-used case labels. Currently clang's behavior of --Wswitch and
-Wswitch-enum  are the same. I think fixing that will not make the new option necessary.

-Wswitch
           Warn whenever a "switch" statement has an index of enumerated type and lacks a "case" for one or
           more of the named codes of that enumeration.  (The presence of a "default" label prevents this
           warning.)  "case" labels outside the enumeration range also provoke warnings when this option is
           used.  This warning is enabled by -Wall.

-Wswitch-enum
           Warn whenever a "switch" statement has an index of enumerated type and lacks a "case" for one or
           more of the named codes of that enumeration.  "case" labels outside the enumeration range also
           provoke warnings when this option is used.


int test18() {
  enum { A, B } a;
  switch (a) {
  case A: return 0;
  default: return 2;  
}
}

- Fariborz





More information about the cfe-commits mailing list