This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/28236] wrong "control reaches" warning with enums.



------- Comment #7 from manu at gcc dot gnu dot org  2007-01-23 15:55 -------
(In reply to comment #6)
> 
> an assignment of int to enum produces an error,
> so how ( in defined non-hax0r way ) enum can be any integer?
> if it can be, then what's difference between enum and int?

Undefined behaviour exists. It can happen. It will happen. Is casting a "hax0r
way"? 

manu@localhost:~$ cat test.cc
#include <stdio.h>

typedef enum { foo, bar } e;
int zoo( e __e )
{
        switch ( __e )
        {
                case foo: return -1;
                case bar: return +1;
        }
}

int main()
{
  printf("%d\n", zoo((e)10));
  return 0;
}
manu@localhost:~$ g++ -pedantic test.cc -o test
manu@localhost:~$ ./test
-1209364588


We have requests for warnings about out-of-range enum conversions in C++:

* PR 12242
* PR 27975
* PR 12242

Again, I am just trying to understand the issue here. You will get a more
expert opinion about the standard and whether this is an actual bug or you
should have a default: case in your switch statements in the gcc@gcc.gnu.org
mailing list.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28236


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]