brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.2 KiB · f882e4f Raw
72 lines · cpp
1// RUN: %clang_cc1 -fexperimental-new-constant-interpreter -fms-extensions -std=c++20 -verify=expected,both %s2// RUN: %clang_cc1 -std=c++20 -fms-extensions -verify=ref,both %s3 4namespace std {5  typedef decltype(sizeof(int)) size_t;6  template <class _E>7  class initializer_list8  {9    const _E* __begin_;10    size_t    __size_;11 12    initializer_list(const _E* __b, size_t __s)13      : __begin_(__b),14        __size_(__s)15    {}16 17  public:18    typedef _E        value_type;19    typedef const _E& reference;20    typedef const _E& const_reference;21    typedef size_t    size_type;22 23    typedef const _E* iterator;24    typedef const _E* const_iterator;25 26    constexpr initializer_list() : __begin_(nullptr), __size_(0) {}27 28    constexpr size_t    size()  const {return __size_;}29    constexpr const _E* begin() const {return __begin_;}30    constexpr const _E* end()   const {return __begin_ + __size_;}31  };32}33 34class Thing {35public:36  int m = 12;37  constexpr Thing(int m) : m(m) {}38  constexpr bool operator==(const Thing& that) const {39    return this->m == that.m;40  }41};42 43constexpr bool is_contained(std::initializer_list<Thing> Set, const Thing &Element) {44   return (*Set.begin() == Element);45}46 47constexpr int foo() {48  const Thing a{12};49  const Thing b{14};50  return is_contained({a}, b);51}52 53static_assert(foo() == 0);54 55 56namespace rdar13395022 {57  struct MoveOnly { // both-note {{candidate}}58    MoveOnly(MoveOnly&&); // both-note 2{{copy constructor is implicitly deleted because}} both-note {{candidate}}59  };60 61  void test(MoveOnly mo) {62    auto &&list1 = {mo}; // both-error {{call to implicitly-deleted copy constructor}} both-note {{in initialization of temporary of type 'std::initializer_list}}63    MoveOnly (&&list2)[1] = {mo}; // both-error {{call to implicitly-deleted copy constructor}} both-note {{in initialization of temporary of type 'MoveOnly[1]'}}64    std::initializer_list<MoveOnly> &&list3 = {};65    MoveOnly (&&list4)[1] = {}; // both-error {{no matching constructor}}66    // both-note@-1 {{in implicit initialization of array element 0 with omitted initializer}}67    // both-note@-2 {{in initialization of temporary of type 'MoveOnly[1]' created to list-initialize this reference}}68  }69}70 71 72