diff --git a/include/llvm/ADT/ArrayRef.h b/include/llvm/ADT/ArrayRef.h index a0b6eff269f..61467e9b21c 100644 --- a/include/llvm/ADT/ArrayRef.h +++ b/include/llvm/ADT/ArrayRef.h @@ -83,6 +83,13 @@ namespace llvm { /*implicit*/ LLVM_CONSTEXPR ArrayRef(const T (&Arr)[N]) : Data(Arr), Length(N) {} +#if LLVM_HAS_INITIALIZER_LISTS + /// Construct an ArrayRef from a std::initializer_list. + /*implicit*/ ArrayRef(const std::initializer_list &Vec) + : Data(Vec.begin() == Vec.end() ? (T*)0 : Vec.begin()), + Length(Vec.size()) {} +#endif + /// @} /// @name Simple Operations /// @{ diff --git a/include/llvm/Support/Compiler.h b/include/llvm/Support/Compiler.h index 13920fcc5a8..5ce9abc49d4 100644 --- a/include/llvm/Support/Compiler.h +++ b/include/llvm/Support/Compiler.h @@ -403,4 +403,13 @@ # define LLVM_ENUM_INT_TYPE(intty) #endif +/// \brief Does the compiler support generalized initializers (using braced +/// lists and std::initializer_list). +#if (__has_feature(cxx_generalized_initializers) \ +|| defined(__GXX_EXPERIMENTAL_CXX0X__)) +#define LLVM_HAS_INITIALIZER_LISTS 1 +#else +#define LLVM_HAS_INITIALIZER_LISTS 0 +#endif + #endif