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