|
Boost : |
From: Jody Hagins (jody-boost-011304_at_[hidden])
Date: 2004-11-23 07:00:19
On Tue, 23 Nov 2004 10:34:33 +0300
Vladimir Prus <ghost_at_[hidden]> wrote:
>
> The problem is that gcc is too smart. Switch does not handle a single
> enumerator --- 'ed_success', very reasonable. It's handled before the
> switch. Even if I add 'ed_success' case, it still report the warning.
>
> So, I've worked this around by adding 'return' in default case. The
> change is committed.
Hmmm... What do you mean by "Switch does not handle a single enumerator
--- 'ed_success', very reasonable?"
Also, is a "return" what you really want here? If you have an error
condition that you do not recognize, then this should at least throw a
logic_error, if not some other.
Maybe adding something like "unknown" to
invalid_command_line_syntax::kind_t and then initializing "re" to
"unknown" would still allow you to fall out of the switch and still
throw the exception, with a kind_t of "unknown." Better than just
returning, IMO.
Also, I have found beneficial when "switching" on an enumeration, to
leave out the default case all together. Some compilers will then emit
a warning if you forgot to handle a case, or if the enumeration changes
and a "new" addition is not handled in the switch.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk