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) {
52755275template <class Emitter >
52765276bool Compiler<Emitter>::maybeEmitDeferredVarInit(const VarDecl *VD) {
52775277 if (auto *DD = dyn_cast_if_present<DecompositionDecl>(VD)) {
5278- for (auto *BD : DD->bindings ())
5278+ for (auto *BD : DD->flat_bindings ())
52795279 if (auto *KD = BD->getHoldingVar (); KD && !this ->visitVarDecl (KD))
52805280 return false ;
52815281 }
Original file line number Diff line number Diff line change 11// 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
23
34template <typename T>
45struct type_ { };
56
67template <typename ...T>
7- auto sum (T... t) { return (t + ...); }
8+ constexpr auto sum (T... t) { return (t + ...); }
89
910struct my_struct {
1011 int a;
@@ -17,7 +18,7 @@ struct fake_tuple {
1718 int arr[4 ] = {1 , 2 , 3 , 6 };
1819
1920 template <unsigned i>
20- int get () {
21+ constexpr int & get () {
2122 return arr[i];
2223 }
2324};
@@ -233,3 +234,28 @@ void g() {
233234}
234235
235236}
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