<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/152375>152375</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Mangling of structured bindings
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
jakubjelinek
</td>
</tr>
</table>
<pre>
Consider
```c
template <typename T>
int
foo ()
{
static int a = 1, b = 2, c = 3;
int d = a++ + b++ + c++;
{
static int a = 1, b = 2, c = 3;
d += a++ + b++ + c++;
{
static auto [a, b1, b2, b3, c] = T {};
return a++ + c++ + b2++ + d;
}
}
}
struct A { int a, b, c, d, e; };
void
bar ()
{
foo <A> ();
}
namespace std {
template<typename T> struct tuple_size;
template<int, typename> struct tuple_element;
}
struct B {
int a[5];
template <int I> int &get () { return a[I]; }
};
template<> struct std::tuple_size<B> { static const int value = 5; };
template<int I> struct std::tuple_element<I,B> { using type = int; };
void
baz ()
{
foo <B> ();
}
```
E.g. in foo <B>, both clang++ and g++ properly mangle the outermost a, b, c as
_ZZ3fooI1BEivE1{a,b,c}
the one in the next scope
_ZZ3fooI1BEivE1{a,b,c}_0
but then g++ mangles the individual vars in the tuple structured bindings
_ZZ3fooI1BEivE{1a_1,2b1,2b2,2b3,1c_1}
but clang++ mangles those instead
_ZZ3fooI1BEivE{1a.1,2b1,2b2,2b3,1c.1}
I think g++ is right and clang++ is wrong.
Another question is how to mangle structured binding packs.
I've filed https://github.com/itanium-cxx-abi/cxx-abi/issues/200 but nothing happened there.
Testcase would be pretty similar,
```c
template <typename T>
int
foo ()
{
static int a = 1, b = 2, c = 3;
int d = a++ + b++ + c++;
{
static int a = 1, b = 2, c = 3;
d += a++ + b++ + c++;
{
static auto [a, ...b, c] = T {};
return a++ + c++ + b...[0]++ + d;
}
}
}
struct A { int a, b, c, d, e; };
void
bar ()
{
foo <A> ();
}
namespace std {
template<typename T> struct tuple_size;
template<int, typename> struct tuple_element;
}
struct B {
int a[5];
template <int I> int &get () { return a[I]; }
};
template<> struct std::tuple_size<B> { static const int value = 5; };
template<int I> struct std::tuple_element<I,B> { using type = int; };
void
baz ()
{
foo <B> ();
}
```
One question is whether to somehow show in the whole structured binding mangling that there is a pack in it and where (so one could demangle it as foo<B>()::[a, ...b, c] instead of just foo<B>()::[a, b, c]
And another one what mangling to use for the elements of the structured binding pack.
One possibility is just pretend it is sizeof...(pack) separate instantiations of the local variable (i.e. use b_1, b_2, b_3 in the testcase because b_0 and b_1 were previously used already), or do something else?
@ricejasonf @AaronBallman @cor3ntin
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzsV01v4zYQ_TX0ZRBBpqw4OfggOQmQQ9HLnvZiUOLYYkKTKknZ6_31xZDyRxJvt2mBogUKJAwVcua9-dA8W3ivNgZxwcqalQ8TMYTOusWLeB2aF9TK4OuksfKwWFrjlUTH8ord5umnZXkVcNtrERBYsQyHHo3YInxhxSPLK2UCy6u1tcD4HeP3ZDuvWV4B-CCCakGZAAJY8QBTxpfQxC2nbRu3BSvSfboo478E4zXjNdBvc7Fv0_5oMAJ9FgcIhbz8aaD3UGIIFlhZiwiU4CJSU0Q8Vj5EyC_Rbv5w9gPgMAzOvEFuL1nwiwc5GpKLFPBDzG9c88oHN7QB6LxO4UcOiQJfgqQFWVHDiQPLq51VkuVVI9zHksU6FsuKFY_Hw2R2hKTS-160CD7IY1bg2CDv-wNGhmHoNa68-o5jQBcG1EB8CUe7D1aocYsmvOMxXqlPFFL4ZV2y8uEdCCQUeCbftGH8doNhDDAm71SUsn5ODi5yfVE86oTz-8CK5QVdHyQrKlZUl9Eu65jKeX1sndYaHyKLndADxjYp35TobW4S6-sQp9Qsnxk_Iw1emU1MaPSuYvKut8D3Dy0wdkD9gw44jgWWV4_ZJgNlLi1i-9nQQauF2YyNLIyE4753tkenD7AVZqMRQodgh4Bua_2b9gXhWV6tvn4t1tY-T-tHtXucsnl84-hG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