K
kraftcheck
I have the following code:
#include <iostream>
enum MyEnum { A = 0, B, LAST };
inline MyEnum & operator++(MyEnum &e)
{
return reinterpret_cast<MyEnum&>(++reinterpret_cast<int&>(e));
}
int main()
{
for (MyEnum i = A; i < LAST; ++i)
std::cout << i << std::endl;
return 0;
}
When compiling this with G++ 4.1, the output for a non-optimized build
is:
0
1
If I compile with -O2, I get
0
0
1
Is there something wrong with the way the ++ operator is defined?
#include <iostream>
enum MyEnum { A = 0, B, LAST };
inline MyEnum & operator++(MyEnum &e)
{
return reinterpret_cast<MyEnum&>(++reinterpret_cast<int&>(e));
}
int main()
{
for (MyEnum i = A; i < LAST; ++i)
std::cout << i << std::endl;
return 0;
}
When compiling this with G++ 4.1, the output for a non-optimized build
is:
0
1
If I compile with -O2, I get
0
0
1
Is there something wrong with the way the ++ operator is defined?