struct NonAggr1 { NonAggr1(int, int) { }
int m;
};
struct Base { };
struct NonAggr2 : public Base { int m;
};
class NonAggr3 { int m;
};
struct NonAggr4 { int m;
virtual void f();
};
NonAggr1 na1 = { 17 }; NonAggr2 na2 = { 17 };
NonAggr3 na3 = { 17 }; NonAggr4 na4 = { 17 }; #if __cplusplus <= 201402L
#else
NonAggr2 na2b = { {}, 17 }; #endif
typedef int type[][2];
const type foo = {0};
typedef short __v4hi __attribute__ ((__vector_size__ (8)));
__v4hi v1 = { (void *)1, 2, 3 };
int a[] = { (void *)1 };
struct S { int a; } s = { (void *)1 };
struct A {
A();
A(int);
~A();
A(const A&) = delete; };
struct B {
A a;
};
struct C {
const A& a;
};
void f() {
A as1[1] = { };
A as2[1] = { 1 };
#if __cplusplus <= 201402L
#endif
B b1 = { };
B b2 = { 1 };
#if __cplusplus <= 201402L
#endif
C c1 = { 1 };
}
class Agg {
public:
int i, j;
};
class AggAgg {
public:
Agg agg1;
Agg agg2;
};
AggAgg aggagg = { 1, 2, 3, 4 };
namespace diff_cpp14_dcl_init_aggr_example {
struct derived;
struct base {
friend struct derived;
private:
base();
};
struct derived : base {};
derived d1{};
#if __cplusplus > 201402L
#endif
derived d2;
}
namespace ProtectedBaseCtor {
struct A {
protected:
A();
};
struct B : public A {
friend B f();
friend B g();
friend B h();
};
B f() { return {}; }
#if __cplusplus > 201402L
#endif
B g() { return {{}}; }
#if __cplusplus <= 201402L
#else
#endif
B h() { return {A{}}; }
#if __cplusplus <= 201402L
#endif
}
namespace IdiomaticStdArrayInitDoesNotWarn {
#pragma clang diagnostic push
#pragma clang diagnostic warning "-Wmissing-braces"
template<typename T, int N> struct StdArray {
T contents[N];
};
StdArray<int, 3> x = {1, 2, 3};
template<typename T, int N> struct ArrayAndSomethingElse {
T contents[N];
int something_else;
};
ArrayAndSomethingElse<int, 3> y = {1, 2, 3};
#if __cplusplus >= 201703L
template<typename T, int N> struct ArrayAndBaseClass : StdArray<int, 3> {
T contents[N];
};
ArrayAndBaseClass<int, 3> z = {1, 2, 3};
template<typename T, int N> struct JustABaseClass : StdArray<T, N> {};
JustABaseClass<int, 3> w = {1, 2, 3};
JustABaseClass<int, 3> v = {{1, 2, 3}};
template <typename T, int N> struct OnionBaseClass : JustABaseClass<T, N> {};
OnionBaseClass<int, 3> u = {1, 2, 3};
OnionBaseClass<int, 3> t = {{{1, 2, 3}}};
struct EmptyBase {};
template <typename T, int N> struct AggregateAndEmpty : StdArray<T, N>, EmptyBase {};
AggregateAndEmpty<int, 3> p = {1, 2, 3}; #endif
#pragma clang diagnostic pop
}
namespace HugeArraysUseArrayFiller {
struct A { int n; int arr[1000 * 1000 * 1000]; } a = {1, {2}};
}
namespace ElementDestructor {
class X { int f; ~X(); }; struct Y { X x; };
void test0() {
auto *y = new Y {}; }
struct S0 { int f; ~S0() = delete; }; struct S1 { S0 s0; int f; };
S1 test1() {
auto *t = new S1 { .f = 1 }; return {2}; }
struct S2 { S0 a[4]; };
void test2() {
auto *t = new S2 {1,2,3,4}; }
#if __cplusplus >= 201703L
namespace BaseDestructor {
struct S0 { int f; ~S0() = delete; };
struct S3 : S0 {};
void test3() {
S3 s3 = {1}; }
}
#endif
struct A { friend struct B; private: ~A(); };
struct B { B(); A a; };
struct C { B b; };
C c = { B() };
}