<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/60724>60724</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[C++17] Underlying variables of structured bindings should not be treated as having external or module linkage
</td>
</tr>
<tr>
<th>Labels</th>
<td>
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
frederick-vs-ja
</td>
</tr>
</table>
<pre>
For the following example with two translation units:
```C++
// main.cpp
using Arr = int[2];
auto [bx, by] = Arr{};
int main(){}
```
```C++
// a.cpp
using Arr = int[2];
auto [bx, by] = Arr{};
```
Currently a linker error is emitted ([Godbolt link](https://godbolt.org/z/Esoo53Gsa)):
> /opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/13.0.1/../../../../x86_64-linux-gnu/bin/ld: CMakeFiles/test.dir/main.cpp.o:(.bss+0x0): multiple definition of `_ZDC2bx2byE'; CMakeFiles/test.dir/a.cpp.o:(.bss+0x0): first defined here
The linker succeeds if `[bx, by]` is changed to `[bx, bz]` in either TU (but not both).
Presumably, `_ZDC2bx2byE` is the mangled name of the unnamed variable created in the structured binding declaration. Per current standard wording ([[basic.link]](https://eel.is/c++draft/basic.link), see also discussion in cplusplus/CWG#240), structured bindings have no linkage, and so do the unname variables because they don't even have names.
So linker should be successful for this example, and both TUs have its own distinct unnamed variable.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy0VUlv4zgT_TX0pWBBpjb74ENsRzl9QANfggHm0uBSstihSIGLY_evH1CyO04nM5jLALIMkY-1vVdF5r06GsQtqXakOixYDL11286hRKfE6_Lklz_Yglt52bbWQegROqu1fVPmCHhmw6gR3lToIbxZCI4Zr1lQ1kA0KnhSPJD8QPIHUufzsyd0l555lbaEtjAwZTIxjvNi9Mn2g3NAigMoE0i1o6Q6kOJ6isVggVQ7fiZ0D_xCqsMEfXCONDvSvCPntzJhckHomtDNFfIxqn8R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