Re: C enum type warning

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Federico Ruiz <memeruiz@xxxxxxxxx> writes:

> I have been looking for a way to detect a programming error like the
> following with gcc:
>
> enum foo_e {
>  ZERO,
>  ONE,
>   TWO
> };
>
> int main(void) {
>   enum foo_e bar;
>   bar=ZERO; // correct use of bar
>   bar=50; //possible incorrect use of bar
>   ....
> }
>
> I couldn't find a way to get a warning message from gcc for the second
> use of bar (I tried -Wall and -Wswith-enum). Is there a way to get
> warning out of this? I played around with splint and it can detect
> this type of programming error, the problem with splint is that only
> parses C89 code and it gives for example parse errors for variable
> declarations inside of for expresions. Also splint seems to be
> unmaintained nowadays.

In current mainline gcc you will get warnings here if you use the
-Wc++-compat option.  There is no way to get these warnings in released
versions of gcc.

(I would not be opposed to breaking these out into separate warnings, in
case you want to check for them separately from other C++ compatibility
issues.  However, this is not work I plan to do myself.)

Ian

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux