[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [lmi] sequence input editor -- how to get accepted keywords
From: |
Greg Chicares |
Subject: |
Re: [lmi] sequence input editor -- how to get accepted keywords |
Date: |
Sat, 26 Jun 2010 19:51:46 +0000 |
User-agent: |
Thunderbird 2.0.0.24 (Windows/20100228) |
On 2010-06-26 18:41Z, Vaclav Slavik wrote:
>
> What is the problem with gcc 3.4.5 exactly?
It is
warning: control reaches end of non-void function
as in the following simple testcase:
enum N {one, two};
int test_main()
{
volatile N n = one;
switch(n)
{
case one: return 1;
case two: return 2;
}
}
Adding 'default:' resolves that, but effectively inhibits '-Wswitch'.
> That it interprets -Wswitch
> differently from what
> http://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html says, namely that
>
> -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 (even if there is a default label).
> This warning is enabled by -Wall.
>
> ?
It does what the manual says, AFAICT.
> As far as I can tell, -Wall shouldn't cause any warning if there's a
> 'default:' label, should it?
Correct. To summarize (assuming '-Wswitch'), if 'default:' is present:
No: warning about missing switch cases
Yes: warning about returning without a value
And if it's not present:
Yes: warning about missing switch cases
No: warning about returning without a value
If I add 'default:', then I don't get the (bogus) return-without-value
warning, and I do get the switch warning when an enum case is absent.
> I have trouble imagining any situation when this -- or -Wswitch-default
> for that matter -- would be a good idea. The whole point of using
> 'default:' is to express "all other values should be handled the same".
> Likewise, the whole point of not including it is to express "there's no
> default, this switch should special-case all possibilities". Per the
> documentation, -Wswitch helps with exactly that: it warns about missing
> labels, unless there's an all-catching 'default:' label.
I like that convention. But MinGW gcc-3.4.5 and prior don't let me rely
on it with '-Werror', and that's why I've generally followed a different
convention, striving to put this in every switch:
default: throw [something];
Really, though, that means I'm trying to do the compiler's job for it
(and, sadly, only at run time) so I don't mind abandoning that practice.
Here's an alternative that detects missing enum cases with '-Wswitch'
and doesn't produce
warning: control reaches end of non-void function
with the compiler I'm using:
int test_main()
{
volatile N n = one;
switch(n)
{
case one: return 1;
case two: return 2;
}
throw "Unreachable";
}
What do you think?
- Re: Re[2]: [lmi] sequence input editor -- how to get accepted keywords, (continued)
- Re: Re[2]: [lmi] sequence input editor -- how to get accepted keywords, Vaclav Slavik, 2010/06/26
- Re: [lmi] sequence input editor -- how to get accepted keywords, Greg Chicares, 2010/06/26
- Re: [lmi] sequence input editor -- how to get accepted keywords, Vaclav Slavik, 2010/06/27
- Re: [lmi] sequence input editor -- how to get accepted keywords, Greg Chicares, 2010/06/27
- Re: [lmi] sequence input editor -- how to get accepted keywords, Vaclav Slavik, 2010/06/27
Re: [lmi] sequence input editor -- how to get accepted keywords, Greg Chicares, 2010/06/26
- Re: [lmi] sequence input editor -- how to get accepted keywords, Greg Chicares, 2010/06/26
- Re: [lmi] sequence input editor -- how to get accepted keywords, Vaclav Slavik, 2010/06/26
- Re: [lmi] sequence input editor -- how to get accepted keywords, Greg Chicares, 2010/06/26
- Re: [lmi] sequence input editor -- how to get accepted keywords, Vaclav Slavik, 2010/06/26
- Re: [lmi] sequence input editor -- how to get accepted keywords,
Greg Chicares <=
- Re: [lmi] sequence input editor -- how to get accepted keywords, Vaclav Slavik, 2010/06/27
Re: [lmi] sequence input editor -- how to get accepted keywords, Greg Chicares, 2010/06/27
Re: [lmi] sequence input editor -- how to get accepted keywords, Greg Chicares, 2010/06/27
Re: [lmi] sequence input editor -- how to get accepted keywords, Vaclav Slavik, 2010/06/27
Re: [lmi] sequence input editor -- how to get accepted keywords, Greg Chicares, 2010/06/27
Re: [lmi] sequence input editor -- how to get accepted keywords, Greg Chicares, 2010/06/27
Re: [lmi] sequence input editor -- how to get accepted keywords, Vaclav Slavik, 2010/06/27