[Bug c++/53745] New: Bitshifted value (1 << 31) within enumerator class is calculated incorrectly during compilation.

sbgccbug at yahoo dot co.uk gcc-bugzilla@gcc.gnu.org
Thu Jun 21 13:04:00 GMT 2012


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

             Bug #: 53745
           Summary: Bitshifted value (1 << 31) within enumerator class is
                    calculated incorrectly during compilation.
    Classification: Unclassified
           Product: gcc
           Version: 4.6.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: sbgccbug@yahoo.co.uk


When compiling an 'enum class' (-std=c++0x) that uses bit-shifted values, the
result of "1 << 31" is calculated incorrectly, resulting in -0x80000000
(*negative* 2^31) rather than the correct result of 0x80000000:

// *** BEGIN EXAMPLE CODE (main.cpp) ***

enum class EnumTest : unsigned long int
{
   A = 1 << 30,
   B = 1 << 31
};

int main()
{
   return 0;
}

// *** END EXAMPLE CODE ***

// *** BEGIN gcc-4.6.1 OUTPUT ***

main.cpp|4|error: enumerator value -0x00000000080000000 is too large for
underlying type ‘long unsigned int’|

// *** END gcc-4.6.1 OUTPUT ***



More information about the Gcc-bugs mailing list