[Bug c++/12597] New: bad retrun value for an enum variable cast as int

mgoncalves at jouve dot fr gcc-bugzilla@gcc.gnu.org
Mon Oct 13 13:32:00 GMT 2003


PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.

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

           Summary: bad retrun value for an enum variable cast as int
           Product: gcc
           Version: 3.3.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: mgoncalves at jouve dot fr
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: 3.3.1
  GCC host triplet: 3.3.1
GCC target triplet: 3.3.1

GCC 3.3.1 build 20030626 (Debian prerealease) DEBIAN Linux
GCC 3.3.1 MINGW build                         WIN2000

When a "enum" variable, cast to "int", is used in a function with an "int"
referenced argument the returned value was wrong.
The problem is not reproduced with GCC 2.95.3, 3.0 and 3.2.2, and not appear
when the cast is "(int&)".


-- To reproduce the problem

#include "stdlib.h"
#include "string.h"
#include "stdio.h"

typedef enum
{
  foo1 = 1,
  foo2,
  foo3
} testenum;

void testfunc(int & i)
{
  printf("i = %ld\n",i);
  i = 1;
  printf("i = %ld\n",i);
}

int main(int argc, char ** argv)
{
  testenum testvar = foo3;

  testfunc((int)testvar);
  printf("testvar = %ld\n",testvar);

  return 0;
}



More information about the Gcc-bugs mailing list