This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: -Wswitch vs -Wuninitialized
Richard Henderson wrote:
>
> On Mon, Nov 20, 2000 at 03:08:32PM +1100, Andrew Cagney wrote:
> > Adding the missing enum vis:
> > still gives the warning:
> >
> > `i' might be used uninitialized in this function
>
> The problem being that "ev" might have a value outside the enumeration.
Yes.
> So -Wswitch is trying to ensure that you havn't forgotten something,
> but -Wuninitialized is traversing the CFG and determining that there
> is a path that results in an uninitialized use.
>
> > Alternativly, is there a suggested coding pratice that addreses this?
>
> GCC typically adds "default: abort()" to most switches like that.
Which means that compiling GCC with -Wswitch is of little benefit. A
tradeoff was made and it was decided that detecting a bad switch (and
-Wuninitialized) was more important than a forgotten enum val. I can
understand the rationale.
Regading the more general question. I take it that no one has looked at
a way of allowing -Wswitch to still report a forgotten enum when
something like ``default: abort()'' (or even ``default:
ATTRIB_THIS_ISN_HERE()'' :-) is present.
thanks,
Andrew