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

Ryuta Suzuki ryuuta at gmail.com
Tue Jul 26 14:23:58 PDT 2011


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?

Thanks,

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


More information about the cfe-dev mailing list