Implicit conversion of enum to int within an initializer list

Hi,

I’m curious if the enum values can be put in initializer list of st::vector,

#include

int main()
{
enum Type
{
None = 0x0,
A = 0x1,
B = 0x2,
C = 0x4
};

typedef std::vector TypeVector;
TypeVector types = { Type::A, Type::B, Type::C };

return 0;
}

g++ can compile it but clang++ can’t:

$ g++ -Wall -Wextra -std=c++0x ./classes_vector.cpp

$ clang++ -Wall -Wextra -std=c++0x -stdlib=libc++ ./classes_vector.cpp
./classes_vector.cpp:14:14: error: non-aggregate type ‘TypeVector’ (aka ‘vector’) cannot be initialized with an initializer list
TypeVector types = { Type::A, Type::B, Type::C };
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.

Could this be clang bug?

Thanks,

Ryuta

It’s not a bug; C++0x generalized initializer lists haven’t been implemented in Clang yet.

  • Doug

Oh, I thought it was implemented in clang already.
Thanks for the info, Doug.

Regards,

Ryuta