Richard Smith | 872307e | 2016-03-08 22:17:41 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -std=c++1z -verify %s -fcxx-exceptions -triple=x86_64-linux-gnu |
| 2 | |
| 3 | namespace BaseClassAggregateInit { |
| 4 | struct A { |
| 5 | int a, b, c; |
| 6 | constexpr A(int n) : a(n), b(3 * n), c(b - 1) {} // expected-note {{outside the range of representable}} |
| 7 | constexpr A() : A(10) {}; |
| 8 | }; |
| 9 | struct B : A {}; |
| 10 | struct C { int q; }; |
| 11 | struct D : B, C { int k; }; |
| 12 | |
| 13 | constexpr D d1 = { 1, 2, 3 }; |
| 14 | static_assert(d1.a == 1 && d1.b == 3 && d1.c == 2 && d1.q == 2 && d1.k == 3); |
| 15 | |
| 16 | constexpr D d2 = { 14 }; |
| 17 | static_assert(d2.a == 14 && d2.b == 42 && d2.c == 41 && d2.q == 0 && d2.k == 0); |
| 18 | |
| 19 | constexpr D d3 = { A(5), C{2}, 1 }; |
| 20 | static_assert(d3.a == 5 && d3.b == 15 && d3.c == 14 && d3.q == 2 && d3.k == 1); |
| 21 | |
| 22 | constexpr D d4 = {}; |
| 23 | static_assert(d4.a == 10 && d4.b == 30 && d4.c == 29 && d4.q == 0 && d4.k == 0); |
| 24 | |
| 25 | constexpr D d5 = { __INT_MAX__ }; // expected-error {{must be initialized by a constant expression}} |
| 26 | // expected-note-re@-1 {{in call to 'A({{.*}})'}} |
| 27 | } |
Richard Smith | 84a0b6d | 2016-10-18 23:39:12 +0000 | [diff] [blame] | 28 | |
| 29 | namespace NoexceptFunctionTypes { |
| 30 | template<typename T> constexpr bool f() noexcept(true) { return true; } |
Richard Smith | dfe85e2 | 2016-12-15 02:35:39 +0000 | [diff] [blame] | 31 | constexpr bool (*fp)() = f<int>; |
Richard Smith | 84a0b6d | 2016-10-18 23:39:12 +0000 | [diff] [blame] | 32 | static_assert(f<int>()); |
Richard Smith | dfe85e2 | 2016-12-15 02:35:39 +0000 | [diff] [blame] | 33 | static_assert(fp()); |
Richard Smith | 84a0b6d | 2016-10-18 23:39:12 +0000 | [diff] [blame] | 34 | |
| 35 | template<typename T> struct A { |
| 36 | constexpr bool f() noexcept(true) { return true; } |
| 37 | constexpr bool g() { return f(); } |
Richard Smith | 5f4b388 | 2016-10-19 00:14:23 +0000 | [diff] [blame] | 38 | constexpr bool operator()() const noexcept(true) { return true; } |
Richard Smith | 84a0b6d | 2016-10-18 23:39:12 +0000 | [diff] [blame] | 39 | }; |
| 40 | static_assert(A<int>().f()); |
| 41 | static_assert(A<int>().g()); |
Richard Smith | 5f4b388 | 2016-10-19 00:14:23 +0000 | [diff] [blame] | 42 | static_assert(A<int>()()); |
Richard Smith | 84a0b6d | 2016-10-18 23:39:12 +0000 | [diff] [blame] | 43 | } |
Richard Smith | b8c0f55 | 2016-12-09 18:49:13 +0000 | [diff] [blame] | 44 | |
| 45 | namespace Cxx17CD_NB_GB19 { |
| 46 | const int &r = 0; |
| 47 | constexpr int n = r; |
| 48 | } |