[cfe-dev] Implicit conversion of enum to int within an initializer list

Douglas Gregor dgregor at apple.com
Tue Jul 26 14:26:36 PDT 2011


On Jul 26, 2011, at 2:23 PM, Ryuta Suzuki wrote:

> Hi,
> 
> I'm curious if the enum values can be put in initializer list of st::vector<int>,
> 
> #include <vector>
> 
> int main()
> {
>   enum Type
>   {
>     None = 0x0,
>     A    = 0x1,
>     B    = 0x2,
>     C    = 0x4
>   };
> 
>   typedef std::vector<int> 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<int>') cannot be initialized with an initializer list
>   TypeVector types = { Type::A, Type::B, Type::C };
>              ^       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> 1 error generated.
> 
> Could this be clang bug?

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

	- Doug

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20110726/e635cd3e/attachment.html>


More information about the cfe-dev mailing list