This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/53745] New: Bitshifted value (1 << 31) within enumerator class is calculated incorrectly during compilation.
- From: "sbgccbug at yahoo dot co.uk" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Thu, 21 Jun 2012 13:04:12 +0000
- Subject: [Bug c++/53745] New: Bitshifted value (1 << 31) within enumerator class is calculated incorrectly during compilation.
- Auto-submitted: auto-generated
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 ***