1 // RUN: %clang_cc1 -fexperimental-new-constant-interpreter -verify=expected,both %s
2 // RUN: %clang_cc1 -verify=ref,both %s
6 constexpr const int &b
= a
;
7 static_assert(a
== b
, "");
9 constexpr int assignToReference() {
16 static_assert(assignToReference() == 100, "");
19 constexpr void setValue(int &dest
, int val
) {
23 constexpr int checkSetValue() {
28 static_assert(checkSetValue() == 200, "");
30 constexpr int readLocalRef() {
35 static_assert(readLocalRef() == 20, "");
37 constexpr int incRef() {
45 static_assert(incRef() == 1, "");
48 template<const int &V
>
49 constexpr void Plus3(int &A
) {
52 constexpr int foo
= 4;
54 constexpr int callTemplate() {
59 static_assert(callTemplate() == 7, "");
62 constexpr int& getValue(int *array
, int index
) {
65 constexpr int testGetValue() {
66 int values
[] = {1, 2, 3, 4};
67 getValue(values
, 2) = 30;
70 static_assert(testGetValue() == 30, "");
72 constexpr const int &MCE
= 20;
73 static_assert(MCE
== 20, "");
74 static_assert(MCE
== 30, ""); // both-error {{static assertion failed}} \
75 // both-note {{evaluates to '20 == 30'}}
77 constexpr int LocalMCE() {
81 static_assert(LocalMCE() == 100, "");
82 static_assert(LocalMCE() == 200, ""); // both-error {{static assertion failed}} \
83 // both-note {{evaluates to '100 == 200'}}
89 constexpr int RefToMemberExpr() {
97 static_assert(RefToMemberExpr() == 11, "");
103 constexpr int RecordWithRef() {
109 static_assert(RecordWithRef() == 200, "");
114 constexpr Ref2(int &a
) : a(a
) {}
117 constexpr int RecordWithRef2() {
123 static_assert(RecordWithRef2() == 200, "");
125 const char (&nonextended_string_ref
)[3] = {"hi"};
126 static_assert(nonextended_string_ref
[0] == 'h', "");
127 static_assert(nonextended_string_ref
[1] == 'i', "");
128 static_assert(nonextended_string_ref
[2] == '\0', "");
130 /// This isa non-constant context. Reading A is not allowed,
131 /// but taking its address is.
135 namespace Temporaries
{
137 struct B
{ const A
&a
; };
138 const B j
= {{1}}; // both-note {{temporary created here}}
140 static_assert(j
.a
.n
== 1, ""); // both-error {{not an integral constant expression}} \
141 // both-note {{read of temporary is not allowed in a constant expression outside the expression that created the temporary}}