brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.0 KiB · 33d986e Raw
83 lines · cpp
1// RUN: %clang_cc1 -std=c++17 -fsyntax-only -verify %s2 3// This is heavily affected by the speculative resolution applied to CWG23114// So behaviour shown here is subject to change.5 6// expected-no-diagnostics7 8namespace std {9  typedef decltype(sizeof(int)) size_t;10 11  // libc++'s implementation12  template <class _E>13  class initializer_list14  {15    const _E* __begin_;16    size_t    __size_;17 18    initializer_list(const _E* __b, size_t __s)19      : __begin_(__b),20        __size_(__s)21    {}22 23  public:24    typedef _E        value_type;25    typedef const _E& reference;26    typedef const _E& const_reference;27    typedef size_t    size_type;28 29    typedef const _E* iterator;30    typedef const _E* const_iterator;31 32    constexpr initializer_list() : __begin_(nullptr), __size_(0) {}33 34    constexpr size_t    size()  const {return __size_;}35    const _E* begin() const {return __begin_;}36    const _E* end()   const {return __begin_ + __size_;}37  };38 39  template<typename T>40  struct vector {41    size_t sz;42    constexpr vector() : sz(0) {}43    constexpr vector(initializer_list<T> ilist) : sz(ilist.size()) {}44    constexpr vector(const vector& other) : sz(other.sz) {}45    constexpr std::size_t size() const { return sz; }46  };47}48 49// https://github.com/llvm/llvm-project/pull/77768#issuecomment-190806247250namespace Issue1 {51  struct A {52    constexpr A() {}53  };54 55  struct B {56    int called_ctor;57    constexpr explicit B(A) : called_ctor(0) {}58    constexpr explicit B(std::vector<A>) : called_ctor(1) {}59  };60 61  struct C {62    B b;63    constexpr C() : b({A()}) {}64  };65 66  static_assert(C().b.called_ctor == 0);67}68 69// https://github.com/llvm/llvm-project/pull/77768#issuecomment-195717180570namespace Issue2 {71  struct A {72    constexpr A(int x_) {}73    constexpr A(const std::vector<A>& a) {}74  };75 76  void f() {77    constexpr std::vector<A> a{1,2};78    constexpr std::vector<A> b{a};79    // -> constexpr std::vector<A> b(std::initializer_list<A>{ A(a) });80    static_assert(b.size() == 1);81  }82}83