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++/53745] New: Bitshifted value (1 << 31) within enumerator class is calculated incorrectly during compilation.


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 ***


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