public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/53745] New: Bitshifted value (1 << 31) within enumerator class is calculated incorrectly during compilation.
@ 2012-06-21 13:04 sbgccbug at yahoo dot co.uk
  2012-06-21 13:35 ` [Bug c++/53745] " schwab@linux-m68k.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: sbgccbug at yahoo dot co.uk @ 2012-06-21 13:04 UTC (permalink / raw)
  To: gcc-bugs

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


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2013-05-05  0:29 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-06-21 13:04 [Bug c++/53745] New: Bitshifted value (1 << 31) within enumerator class is calculated incorrectly during compilation sbgccbug at yahoo dot co.uk
2012-06-21 13:35 ` [Bug c++/53745] " schwab@linux-m68k.org
2012-06-21 13:36 ` redi at gcc dot gnu.org
2012-06-21 17:52 ` [Bug c++/53745] [C++11] Poor diagnostic for ill-formed narrowing conversion in enumerator initializer redi at gcc dot gnu.org
2013-05-03 23:23 ` paolo.carlini at oracle dot com
2013-05-04 13:09 ` paolo.carlini at oracle dot com
2013-05-05  0:29 ` paolo.carlini at oracle dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).