Wish: Variable Not Used Warning
Robert Fraser
fraserofthenight at gmail.com
Fri Jul 11 11:31:18 PDT 2008
Don Wrote:
> superdan wrote:
> > 4. warning - switch statement has no default
> >
> > another example of a motherfuck. just require total coverage. in closed-set cases i routinely write anyway:
> >
> > switch (crap)
> > {
> > case a: ...; break;
> > case b: ...; break;
> > default: assert(crap == c): ...; break;
> > }
> >
> > again: vast majority of code already has a default. the minority just has to add a little code. make it an error.
>
> Yup. Make it an error.
I agree with everything else, but this one I think shouldn't be an error or
warning (the implicit assert(0) is enough). This is because the vast
majority of switch statements I use (and many I see) are over enums, and
if every branch in the enumeration is covered, a pointless "default" will just
complicate code.
The "final switch" thing mentioned at the conference & now forgotten,
OTOH, is a great idea for statically checking switch statements.
More information about the Digitalmars-d
mailing list