File tree Expand file tree Collapse file tree 2 files changed +29
-3
lines changed Expand file tree Collapse file tree 2 files changed +29
-3
lines changed Original file line number Diff line number Diff line change @@ -5275,7 +5275,7 @@ bool Compiler<Emitter>::visitCompoundStmt(const CompoundStmt *S) {
5275
5275
template <class Emitter >
5276
5276
bool Compiler<Emitter>::maybeEmitDeferredVarInit(const VarDecl *VD) {
5277
5277
if (auto *DD = dyn_cast_if_present<DecompositionDecl>(VD)) {
5278
- for (auto *BD : DD->bindings ())
5278
+ for (auto *BD : DD->flat_bindings ())
5279
5279
if (auto *KD = BD->getHoldingVar (); KD && !this ->visitVarDecl (KD))
5280
5280
return false ;
5281
5281
}
Original file line number Diff line number Diff line change 1
1
// RUN: %clang_cc1 -fsyntax-only -std=c++26 %s -verify
2
+ // RUN: %clang_cc1 -fsyntax-only -std=c++26 %s -verify -fexperimental-new-constant-interpreter
2
3
3
4
template <typename T>
4
5
struct type_ { };
5
6
6
7
template <typename ...T>
7
- auto sum (T... t) { return (t + ...); }
8
+ constexpr auto sum (T... t) { return (t + ...); }
8
9
9
10
struct my_struct {
10
11
int a;
@@ -17,7 +18,7 @@ struct fake_tuple {
17
18
int arr[4 ] = {1 , 2 , 3 , 6 };
18
19
19
20
template <unsigned i>
20
- int get () {
21
+ constexpr int & get () {
21
22
return arr[i];
22
23
}
23
24
};
@@ -233,3 +234,28 @@ void g() {
233
234
}
234
235
235
236
}
237
+
238
+ namespace constant_interpreter {
239
+ using Arr = int [2 ];
240
+ struct Triple { int x, y, z = 3 ; };
241
+
242
+ constexpr int ref_to_same_obj (auto && arg) {
243
+ auto & [...xs ] = arg;
244
+ auto & [...ys ] = arg;
245
+ (..., (xs += 2 ));
246
+ return sum (ys...);
247
+ }
248
+ static_assert (ref_to_same_obj(Arr{}) == 4 );
249
+ static_assert (ref_to_same_obj(fake_tuple{}) == 20 );
250
+ static_assert (ref_to_same_obj(Triple{}) == 9 );
251
+
252
+ constexpr int copy_obj (auto && arg) {
253
+ auto & [...xs ] = arg;
254
+ auto [...ys ] = arg;
255
+ (..., (xs += 2 ));
256
+ return sum (ys...);
257
+ }
258
+ static_assert (copy_obj(Arr{}) == 0 );
259
+ static_assert (copy_obj(fake_tuple{}) == 12 );
260
+ static_assert (copy_obj(Triple{}) == 3 );
261
+ }
You can’t perform that action at this time.
0 commit comments