aaron.ballman added inline comments.

================
Comment at: clang/lib/AST/Interp/ByteCodeExprGen.cpp:1417-1418
+      assert(!BD->getHoldingVar()); // FIXME
+      if (!this->allocateVariable(BD, BD->getBinding()))
+        return false;
+    }
----------------
tbaeder wrote:
> aaron.ballman wrote:
> > <uncertain>Is this correct? IIRC, the decomposition declaration is its own 
> > object, but the bindings themselves are references back to the 
> > decomposition declaration object directly and so they're not distinct 
> > objects themselves (they're more like aliases).</uncertain>
> Is this not reflected in the individual bindings? What does it mean that the 
> bindings aren't "distinct objects themselves"?
Bindings are basically a label back to an object. Taking the easy case of a 
structure being bound:
```
struct S { int i, j; } s;

int main() {
  auto [val1, val2] = s;
  return val1 + val2;
}
```
The way this works under the hood is akin to:
```
struct S { int i, j; } s;

int main() {
  S __s = s; // This is the decomposition declaration
  return __s.i + __s.j; // And the structured bindings give alternative names 
to the fields in the decomposition declaration
}
```
so there's no allocation made for `val1` or `val2` because they're not really 
objects, just names. You can see that in: https://godbolt.org/z/sdj3Mvqhb (note 
the LLVM IR, which is identical between `foo` and `bar` aside from debug info).


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D138802/new/

https://reviews.llvm.org/D138802

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to