g++ with c++11 bitwise OR on strongly typed enum

453 Views Asked by At

I have internal bitOr and bitAnd functions to handle bitwise operations. It normally works alright, tested on g++ 4.7 and VC++ 2012 but failing in g++ 4.4.6 with c++0x std.

template <typename T, typename Flag_T>
inline Flag_T bitOr(T e, Flag_T flag) {
    return static_cast<Flag_T>(e) | flag;
}

To use this I do

unsigned short flag = 0x0;
flag = bitOr<MyEnum, unsigned short>(MyEnum::Val1, flag);

And I get internal g++ error, does anyone has any other work around doing bitwise operation on enum types?

In file included from main.cc:1:
enum-test.h: In function ‘Flag_T bitOr(T, Flag_T) [with T = FormatFlags,     Flag_T = short unsigned int]’:
enum-test.h:1590:   instantiated from here
enum-test.h:603: internal compiler error: Segmentation fault
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://bugzilla.redhat.com/bugzilla> for instructions.
Preprocessed source stored into /tmp/ccKUWf68.out file, please attach this to your    bugreport.

I understand that this is compiler issue but if someone has a workaround doing bitwise operations on enums for g++ 4.4.6 (SL RHEL) it would be great as this works in other compilers. This is my own way of doing

0

There are 0 best solutions below