struct one { char c[1]; };
struct two { char c[2]; };
namespace std {
typedef decltype(sizeof(int)) size_t;
template <class _E>
class initializer_list
{
const _E* __begin_;
size_t __size_;
initializer_list(const _E* __b, size_t __s)
: __begin_(__b),
__size_(__s)
{}
public:
typedef _E value_type;
typedef const _E& reference;
typedef const _E& const_reference;
typedef size_t size_type;
typedef const _E* iterator;
typedef const _E* const_iterator;
initializer_list() : __begin_(nullptr), __size_(0) {}
size_t size() const {return __size_;}
const _E* begin() const {return __begin_;}
const _E* end() const {return __begin_ + __size_;}
};
}
namespace objects {
struct X1 { X1(int); };
struct X2 { explicit X2(int); };
template <int N>
struct A {
A() { static_assert(N == 0, ""); }
A(int, double) { static_assert(N == 1, ""); }
};
template <int N>
struct F {
F() { static_assert(N == 0, ""); }
F(int, double) { static_assert(N == 1, ""); }
F(std::initializer_list<int>) { static_assert(N == 3, ""); }
};
template <int N>
struct D {
D(std::initializer_list<int>) { static_assert(N == 0, ""); } D(std::initializer_list<double>) { static_assert(N == 1, ""); } };
template <int N>
struct E {
E(int, int) { static_assert(N == 0, ""); }
E(X1, int) { static_assert(N == 1, ""); }
};
void overload_resolution() {
{ A<0> a{}; }
{ A<0> a = {}; }
{ A<1> a{1, 1.0}; }
{ A<1> a = {1, 1.0}; }
{ F<0> f{}; }
{ F<0> f = {}; }
{ F<3> f{1, 1.0}; } { F<3> f = {1, 1.0}; } { F<3> f{1, 2, 3, 4, 5, 6, 7, 8}; }
{ F<3> f = {1, 2, 3, 4, 5, 6, 7, 8}; }
{ F<3> f{1, 2, 3, 4, 5, 6, 7, 8}; }
{ F<3> f{1, 2}; }
{ D<0> d{1, 2, 3}; }
{ D<1> d{1.0, 2.0, 3.0}; }
{ D<-1> d{1, 2.0}; }
{ E<0> e{1, 2}; }
}
void explicit_implicit() {
{ X1 x{0}; }
{ X1 x = {0}; }
{ X2 x{0}; }
{ X2 x = {0}; } }
struct C {
C();
C(int, double);
C(int, int);
int operator[](C);
};
C function_call() {
void takes_C(C);
takes_C({1, 1.0});
C c;
c[{1, 1.0}];
return {1, 1.0};
}
void inline_init() {
(void) C{1, 1.0};
(void) new C{1, 1.0};
(void) A<1>{1, 1.0};
(void) new A<1>{1, 1.0};
}
struct B { B(C, int, C); };
void nested_init() {
B b1{{1, 1.0}, 2, {3, 4}};
B b2{{1, 1.0, 4}, 2, {3, 4}}; }
void overloaded_call() {
one ov1(B); two ov1(C);
static_assert(sizeof(ov1({})) == sizeof(two), "bad overload");
static_assert(sizeof(ov1({1, 2})) == sizeof(two), "bad overload");
static_assert(sizeof(ov1({{1, 1.0}, 2, {3, 4}})) == sizeof(one), "bad overload");
ov1({1});
one ov2(int);
two ov2(F<3>);
static_assert(sizeof(ov2({1})) == sizeof(one), "bad overload"); static_assert(sizeof(ov2({1, 2, 3})) == sizeof(two), "bad overload"); }
struct G { template<typename ...T>
G(std::initializer_list<int>, T ...); };
struct H { explicit H(int, int); H(int, void*); };
void edge_cases() {
G g1{1, 2, 3}; (void) new G{1, 2, 3}; (void) G{1, 2, 3};
G g2({1, 2, 3});
(void) new G({1, 2, 3});
(void) G({1, 2, 3});
H h1({1, 2}); (void) new H({1, 2}); (void) H({1, 2});
H h2({1, nullptr});
(void) new H({1, nullptr});
(void) H({1, nullptr});
H h3{1, 2};
(void) new H{1, 2};
(void) H{1, 2};
}
struct memberinit {
H h1{1, nullptr};
H h2 = {1, nullptr};
H h3{1, 1};
H h4 = {1, 1}; };
}
namespace PR12092 {
struct S {
S(const char*);
};
struct V {
template<typename T> V(T, T);
void f(std::initializer_list<S>);
void f(const V &);
};
void g() {
extern V s;
s.f({"foo", "bar"});
}
}
namespace PR12117 {
struct A { A(int); };
struct B { B(A); } b{{0}}; struct C { C(int); } c{0};
}
namespace PR12167 {
template<int N> struct string {};
struct X {
X(const char v);
template<typename T> bool operator()(T) const;
};
template<int N, class Comparator> bool g(const string<N>& s, Comparator cmp) {
return cmp(s);
}
template<int N> bool f(const string<N> &s) {
return g(s, X{'x'});
}
bool s = f(string<1>());
}
namespace PR12257_PR12241 {
struct command_pair
{
command_pair(int, int);
};
struct command_map
{
command_map(std::initializer_list<command_pair>);
};
struct generator_pair
{
generator_pair(const command_map);
};
const std::initializer_list<generator_pair> x = {{{{{3, 4}}}}};
const std::initializer_list<generator_pair> y = {{{{1, 2}}}};
}
namespace PR12120 {
struct A { explicit A(int); A(float); }; A a = { 0 };
struct B { explicit B(short); B(long); }; B b = { 0 };
struct C { explicit C(short); C(long); }; C c = {{ 0 }}; }
namespace PR12498 {
class ArrayRef;
struct C {
void foo(const ArrayRef&); };
static void bar(C* c)
{
c->foo({ nullptr, 1 }); }
}
namespace explicit_default {
struct A {
explicit A(); };
A a {}; A b = {}; }
namespace init_list_default {
struct A {
A(std::initializer_list<int>);
};
A a {};
struct B {
B();
B(std::initializer_list<int>) = delete;
};
B b {}; }
namespace PR13470 {
struct W {
explicit W(int); };
struct X {
X(const X&) = delete; X(int);
};
template<typename T, typename Fn> void call(Fn f) {
f({1}); f(T{1}); }
void ref_w(const W &); void call_ref_w() {
ref_w({1}); ref_w(W{1});
call<W>(ref_w); }
void ref_x(const X &);
void call_ref_x() {
ref_x({1});
ref_x(X{1});
call<X>(ref_x); }
void val_x(X); void call_val_x() {
val_x({1});
val_x(X{1}); call<X>(val_x); }
template<typename T>
struct Y {
X x{1};
void f() { X x{1}; }
void h() {
ref_w({1}); ref_w(W{1});
ref_x({1});
ref_x(X{1});
val_x({1});
val_x(X{1}); }
Y() {}
Y(int) : x{1} {}
};
Y<int> yi;
Y<int> yi2(0);
void g() {
yi.f();
yi.h(); }
}
namespace PR19729 {
struct A {
A(int);
A(const A&) = delete;
};
struct B {
void *operator new(std::size_t, A);
};
B *p = new ({123}) B;
}
namespace PR11410 {
struct A {
A() = delete; A(int);
};
A a[3] = {
{1}, {2}
};
struct B {
A a; } b = {
};
struct C {
C(int = 0); C(float = 0); };
C c[3] = {
0, 1
}; C c2[3] = {
[0] = 1, [2] = 3 }; }