xref: /aosp_15_r20/external/clang/test/SemaCXX/constant-expression-cxx1z.cpp (revision 67e74705e28f6214e480b399dd47ea732279e315)
1*67e74705SXin Li // RUN: %clang_cc1 -std=c++1z -verify %s -fcxx-exceptions -triple=x86_64-linux-gnu
2*67e74705SXin Li 
3*67e74705SXin Li namespace BaseClassAggregateInit {
4*67e74705SXin Li   struct A {
5*67e74705SXin Li     int a, b, c;
ABaseClassAggregateInit::A6*67e74705SXin Li     constexpr A(int n) : a(n), b(3 * n), c(b - 1) {} // expected-note {{outside the range of representable}}
ABaseClassAggregateInit::A7*67e74705SXin Li     constexpr A() : A(10) {};
8*67e74705SXin Li   };
9*67e74705SXin Li   struct B : A {};
10*67e74705SXin Li   struct C { int q; };
11*67e74705SXin Li   struct D : B, C { int k; };
12*67e74705SXin Li 
13*67e74705SXin Li   constexpr D d1 = { 1, 2, 3 };
14*67e74705SXin Li   static_assert(d1.a == 1 && d1.b == 3 && d1.c == 2 && d1.q == 2 && d1.k == 3);
15*67e74705SXin Li 
16*67e74705SXin Li   constexpr D d2 = { 14 };
17*67e74705SXin Li   static_assert(d2.a == 14 && d2.b == 42 && d2.c == 41 && d2.q == 0 && d2.k == 0);
18*67e74705SXin Li 
19*67e74705SXin Li   constexpr D d3 = { A(5), C{2}, 1 };
20*67e74705SXin Li   static_assert(d3.a == 5 && d3.b == 15 && d3.c == 14 && d3.q == 2 && d3.k == 1);
21*67e74705SXin Li 
22*67e74705SXin Li   constexpr D d4 = {};
23*67e74705SXin Li   static_assert(d4.a == 10 && d4.b == 30 && d4.c == 29 && d4.q == 0 && d4.k == 0);
24*67e74705SXin Li 
25*67e74705SXin Li   constexpr D d5 = { __INT_MAX__ }; // expected-error {{must be initialized by a constant expression}}
26*67e74705SXin Li   // expected-note-re@-1 {{in call to 'A({{.*}})'}}
27*67e74705SXin Li }
28