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

[EMAIL PROTECTED]:~$ 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;
}
[EMAIL PROTECTED]:~$ g++ -pedantic test.cc -o test
[EMAIL PROTECTED]:~$ ./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

Reply via email to