Richard Smith | 08d6e03 | 2011-12-16 19:06:07 +0000 | [diff] [blame^] | 1 | // RUN: %clang_cc1 %s -std=c++11 -fsyntax-only -verify |
| 2 | |
| 3 | constexpr int extract(struct S &s); |
| 4 | |
| 5 | struct S { |
| 6 | constexpr S() : n(extract(*this)), m(0) {} |
| 7 | constexpr S(int k) : n(k), m(extract(*this)) {} |
| 8 | int n, m; |
| 9 | }; |
| 10 | |
| 11 | constexpr int extract(S &s) { return s.n; } |
| 12 | |
| 13 | // FIXME: once we produce notes for constexpr variable declarations, this should |
| 14 | // produce a note indicating that S.n is used uninitialized. |
| 15 | constexpr S s1; // expected-error {{constant expression}} |
| 16 | constexpr S s2(10); |
| 17 | |
| 18 | typedef __attribute__((vector_size(16))) int vector_int; |
| 19 | |
| 20 | struct T { |
| 21 | constexpr T() : arr() {} |
| 22 | int arr[4]; |
| 23 | }; |
| 24 | struct U : T { |
| 25 | constexpr U(const int *p) : T(), another(), p(p) {} |
| 26 | constexpr U(const U &u) : T(), another(), p(u.p) {} |
| 27 | T another; |
| 28 | const int *p; |
| 29 | }; |
| 30 | constexpr U u1(&u1.arr[2]); |
| 31 | |
| 32 | constexpr int test_printing(int a, float b, _Complex int c, _Complex float d, |
| 33 | int *e, int &f, vector_int g, U h) { |
| 34 | return *e; // expected-note {{subexpression}} |
| 35 | } |
| 36 | U u2(0); |
| 37 | 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, ""); // \ |
| 38 | expected-error {{constant expression}} \ |
| 39 | expected-note {{in call to 'test_printing(12, 3.976200e+01, 3+4i, 1.290000e+01+3.600000e+00i, &u2.T::arr[4], u2.another.arr[2], {5, 1, 2, 3}, {{{}}, {{}}, &u1.T::arr[2]})'}} |
| 40 | |
| 41 | struct V { |
| 42 | // FIXME: when we can generate these as constexpr constructors, remove the |
| 43 | // explicit definitions. |
| 44 | constexpr V() : arr{[255] = 42} {} |
| 45 | constexpr V(const V &v) : arr{[255] = 42} {} |
| 46 | int arr[256]; |
| 47 | }; |
| 48 | constexpr V v; |
| 49 | constexpr int get(const int *p) { return *p; } // expected-note {{subexpression}} |
| 50 | constexpr int passLargeArray(V v) { return get(v.arr+256); } // expected-note {{in call to 'get(&v.arr[256])'}} |
| 51 | static_assert(passLargeArray(v) == 0, ""); // expected-error {{constant expression}} expected-note {{in call to 'passLargeArray({{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ...}})'}} |
| 52 | |
| 53 | union Union { |
| 54 | constexpr Union(int n) : b(n) {} |
| 55 | constexpr Union(const Union &u) : b(u.b) {} |
| 56 | int a, b; |
| 57 | }; |
| 58 | constexpr Union myUnion = 76; |
| 59 | |
| 60 | constexpr int badness(Union u) { return u.a + u.b; } // expected-note {{subexpression}} |
| 61 | static_assert(badness(myUnion), ""); // expected-error {{constant expression}} \ |
| 62 | expected-note {{in call to 'badness({.b = 76})'}} |
| 63 | |
| 64 | struct MemPtrTest { |
| 65 | int n; |
| 66 | void f(); |
| 67 | }; |
| 68 | MemPtrTest mpt; |
| 69 | constexpr int MemPtr(int (MemPtrTest::*a), void (MemPtrTest::*b)(), int &c) { |
| 70 | return c; // expected-note {{subexpression}} |
| 71 | } |
| 72 | static_assert(MemPtr(&MemPtrTest::n, &MemPtrTest::f, mpt.*&MemPtrTest::n), ""); // expected-error {{constant expression}} \ |
| 73 | expected-note {{in call to 'MemPtr(&MemPtrTest::n, &MemPtrTest::f, mpt.n)'}} |