struct S;
constexpr int extract(const S &s);
struct S {
constexpr S() : n(extract(*this)), m(0) {} constexpr S(int k) : n(k), m(extract(*this)) {}
int n, m;
};
constexpr int extract(const S &s) { return s.n; }
void f() {
constexpr S s1; constexpr S s2(10);
}
typedef __attribute__((vector_size(16))) int vector_int;
struct T {
constexpr T() : arr() {}
int arr[4];
};
struct U : T {
constexpr U(const int *p) : T(), another(), p(p) {}
constexpr U(const U &u) : T(), another(), p(u.p) {}
T another;
const int *p;
};
constexpr U u1(&u1.arr[2]);
constexpr int test_printing(int a, float b, _Complex int c, _Complex float d,
int *e, int &f, vector_int g, U h) {
return *e; }
U u2(0); static_assert(test_printing(12, 39.762, 3 + 4i, 12.9 + 3.6i, &u2.arr[4], u2.another.arr[2], (vector_int){5, 1, 2, 3}, u1) == 0, "");
struct V {
int arr[256] = {[255] = 42}; };
constexpr V v;
constexpr int get(const int *p) { return *p; } constexpr int passLargeArray(V v) { return get(v.arr+256); } static_assert(passLargeArray(v) == 0, "");
union Union {
constexpr Union(int n) : b(n) {}
constexpr Union(const Union &u) : b(u.b) {}
int a, b;
};
constexpr Union myUnion = 76;
constexpr int badness(Union u) { return u.a + u.b; } static_assert(badness(myUnion), "");
struct MemPtrTest {
int n;
void f();
};
MemPtrTest mpt; constexpr int MemPtr(int (MemPtrTest::*a), void (MemPtrTest::*b)(), int &c) {
return c; }
static_assert(MemPtr(&MemPtrTest::n, &MemPtrTest::f, mpt.*&MemPtrTest::n), "");
template<typename CharT>
constexpr CharT get(const CharT *p) { return p[-1]; }
constexpr char c = get("test\0\\\"\t\a\b\234"); constexpr char c8 = get(u8"test\0\\\"\t\a\b\234"); constexpr char16_t c16 = get(u"test\0\\\"\t\a\b\234\u1234"); constexpr char32_t c32 = get(U"test\0\\\"\t\a\b\234\u1234\U0010ffff"); constexpr wchar_t wc = get(L"test\0\\\"\t\a\b\234\u1234\xffffffff");
constexpr char32_t c32_err = get(U"\U00110000");
#define fold(x) (__builtin_constant_p(x) ? (x) : (x))
typedef decltype(sizeof(int)) LabelDiffTy;
constexpr LabelDiffTy mulBy3(LabelDiffTy x) { return x * 3; } void LabelDiffTest() {
static_assert(mulBy3(fold((LabelDiffTy)&&a-(LabelDiffTy)&&b)) == 3, ""); a:b:return;
}
constexpr bool test_bool_printing(bool b) { return 1 / !(2*b | !(2*b)); } constexpr bool test_bool_0 = test_bool_printing(false); constexpr bool test_bool_1 = test_bool_printing(true);