Skip to content

Commit 38018ec

Browse files
committed
[clang][Interp][NFC] Add a failing test case for ArrayInitLoopExprs
1 parent 71bb5f7 commit 38018ec

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

clang/test/AST/Interp/arrays.cpp

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// RUN: %clang_cc1 -fexperimental-new-constant-interpreter -verify %s
2-
// RUN: %clang_cc1 -verify=ref %s
2+
// RUN: %clang_cc1 -verify=ref -DCUR_INTERP %s
33

44
constexpr int m = 3;
55
constexpr const int *foo[][5] = {
@@ -350,3 +350,24 @@ namespace ZeroInit {
350350
static_assert(b.f[0] == 0.0, "");
351351
static_assert(b.f[1] == 0.0, "");
352352
}
353+
354+
namespace ArrayInitLoop {
355+
/// FIXME: The ArrayInitLoop for the decomposition initializer in g() has
356+
/// f(n) as its CommonExpr. We need to evaluate that exactly once and not
357+
/// N times as we do right now.
358+
#ifndef CUR_INTERP
359+
struct X {
360+
int arr[3];
361+
};
362+
constexpr X f(int &r) {
363+
return {++r, ++r, ++r};
364+
}
365+
constexpr int g() {
366+
int n = 0;
367+
auto [a, b, c] = f(n).arr;
368+
return a + b + c;
369+
}
370+
static_assert(g() == 6); // expected-error {{failed}} \
371+
// expected-note {{15 == 6}}
372+
#endif
373+
}

0 commit comments

Comments
 (0)