[Clang][Bytecode] Implement P1061 structured binding pack (#146474)
Other part of this feature was implemented by #121417.
This commit is contained in:
@@ -5275,7 +5275,7 @@ bool Compiler<Emitter>::visitCompoundStmt(const CompoundStmt *S) {
|
||||
template <class Emitter>
|
||||
bool Compiler<Emitter>::maybeEmitDeferredVarInit(const VarDecl *VD) {
|
||||
if (auto *DD = dyn_cast_if_present<DecompositionDecl>(VD)) {
|
||||
for (auto *BD : DD->bindings())
|
||||
for (auto *BD : DD->flat_bindings())
|
||||
if (auto *KD = BD->getHoldingVar(); KD && !this->visitVarDecl(KD))
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
// RUN: %clang_cc1 -fsyntax-only -std=c++26 %s -verify
|
||||
// RUN: %clang_cc1 -fsyntax-only -std=c++26 %s -verify -fexperimental-new-constant-interpreter
|
||||
|
||||
template <typename T>
|
||||
struct type_ { };
|
||||
|
||||
template <typename ...T>
|
||||
auto sum(T... t) { return (t + ...); }
|
||||
constexpr auto sum(T... t) { return (t + ...); }
|
||||
|
||||
struct my_struct {
|
||||
int a;
|
||||
@@ -17,7 +18,7 @@ struct fake_tuple {
|
||||
int arr[4] = {1, 2, 3, 6};
|
||||
|
||||
template <unsigned i>
|
||||
int get() {
|
||||
constexpr int& get() {
|
||||
return arr[i];
|
||||
}
|
||||
};
|
||||
@@ -233,3 +234,28 @@ void g() {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
namespace constant_interpreter {
|
||||
using Arr = int[2];
|
||||
struct Triple { int x, y, z = 3; };
|
||||
|
||||
constexpr int ref_to_same_obj(auto&& arg) {
|
||||
auto& [...xs] = arg;
|
||||
auto& [...ys] = arg;
|
||||
(..., (xs += 2));
|
||||
return sum(ys...);
|
||||
}
|
||||
static_assert(ref_to_same_obj(Arr{}) == 4);
|
||||
static_assert(ref_to_same_obj(fake_tuple{}) == 20);
|
||||
static_assert(ref_to_same_obj(Triple{}) == 9);
|
||||
|
||||
constexpr int copy_obj(auto&& arg) {
|
||||
auto& [...xs] = arg;
|
||||
auto [...ys] = arg;
|
||||
(..., (xs += 2));
|
||||
return sum(ys...);
|
||||
}
|
||||
static_assert(copy_obj(Arr{}) == 0);
|
||||
static_assert(copy_obj(fake_tuple{}) == 12);
|
||||
static_assert(copy_obj(Triple{}) == 3);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user