Boost logo

Boost :

From: Vladimir Prus (ghost_at_[hidden])
Date: 2004-11-23 07:24:45

Jody Hagins wrote:

> 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?"

I mean that switch handles all enumerators, except 'ed_success'. This one
indicates no error, so should not be handled in a switch which returns
error code. This value is handled with

 if (e == e_success)

before the switch

> 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.

The best approach would be to add "ed_success" to the switch...

> 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.

...... but gcc still complains about use of uninitialized var.

The only solution I have is:
- initialize 'res' to some value
- add 'ed_success' to switch
- remove 'default'

This way, if I add a new enumerator compiler will remind to add it to
switch. Anyway, I suspect that code will get rewritten some day.

- Volodya

Boost list run by bdawes at, gregod at, cpdaniel at, john at