1 // RUN: %clang_cc1 -fexperimental-new-constant-interpreter -std=c++17 -verify=expected,both %s
2 // RUN: %clang_cc1 -std=c++17 -verify=ref,both %s
4 struct F
{ int a
; int b
;};
9 auto [a1
, b1
] = getF();
10 auto [a2
, b2
] = getF();
12 return a1
+ a2
+ b1
+ b2
;
14 static_assert(f() == 30);
17 constexpr int structRefs() {
18 const auto &[a
, b
] = getF();
22 static_assert(structRefs() == 15);
24 constexpr int structRefs2() {
26 const auto &[a
, b
] = f
;
30 static_assert(structRefs2() == 15);
37 constexpr Tuple(T a
, T b
) : first(a
), second(b
) {}
40 constexpr T
addTuple(const Tuple
<T
> &Tu
) {
46 constexpr T
addTuple2(const Tuple
<T
> &Tu
) {
48 return Tu
.first
+ Tu
.second
;
51 constexpr Tuple
<int> T1
= Tuple(1,2);
52 static_assert(addTuple(T1
) == 3);
53 static_assert(addTuple2(T1
) == 3);
55 constexpr Tuple
<short> T2
= Tuple
<short>(11,2);
56 static_assert(addTuple(T2
) == 13);
57 static_assert(addTuple2(T2
) == 13);
59 constexpr int Modify() {
60 auto T
= Tuple
<int>(10, 20);
64 return T
.first
+ T
.second
;
66 static_assert(Modify() == 32, "");
73 static_assert(a() == 8);
82 static_assert(b() == 11);
85 template<typename T
> struct A
: T
{
86 constexpr int f() const { return 0; }
89 struct Y
{ virtual int f() const; };
90 struct Z
: virtual X
{};
92 constexpr int z
= A
<Z
>().f(); // both-error {{must be initialized by a constant expression}} \
93 // both-note {{non-literal type 'A<Z>' cannot be used in a constant expression}}
96 /// The diagnostics between the two interpreters used to be different here.
98 constexpr S
getS() { // both-error {{constexpr function never produces a constant expression}}
99 (void)(1/0); // both-note 2{{division by zero}} \
100 // both-warning {{division by zero}}
103 constexpr S s
= getS(); // both-error {{must be initialized by a constant expression}} \
104 // both-note {{in call to 'getS()'}} \
105 // both-note {{declared here}}
106 static_assert(s
.a
== 12, ""); // both-error {{not an integral constant expression}} \
107 // both-note {{initializer of 's' is not a constant expression}}