<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/99572>99572</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Unhelpful diagnostic when decomposing type that doesn't implement all tuple-like operations
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang:frontend
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
Michael137
</td>
</tr>
</table>
<pre>
Take this contrived example:
```
struct B {
int w;
int z;
};
namespace std {
template<typename T> struct tuple_size {
};
template<>
struct tuple_size<B> {
static constexpr int value = 2;
};
}
int main() {
auto [x, y] = B{1, 2};
return 0;
}
```
We get:
```
decomp.cpp:16:11: error: use of undeclared identifier 'get'
16 | auto [x, y] = B{1, 2};
| ^
decomp.cpp:16:11: note: in implicit initialization of binding declaration 'x'
1 error generated.
```
Compare this to the more helpful error message we get when we do actually implement the `get` operation:
```
struct B {
int w;
int z;
template<int> int get();
template<> int get<0>() { return w; }
template<> int get<1>() { return z; }
};
$ g++ decomp.cpp -std=c++2a
decomp.cpp:19:11: error: cannot decompose this type; 'std::tuple_element<0UL, B>::type' does not name a type
19 | auto [x, y] = B{1, 2};
| ^
decomp.cpp:19:11: note: in implicit initialization of binding declaration 'x'
1 error generated.
```
I found the second diagnostic to be better at nudging me in the write direction as to what's missing.
Not sure how actionable this is. I just ran into this when trying to write a test for a tuple-like decomposition of a custom type without including the `tuple` header.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzEVl-vm7gT_TTOy-hGYJKQPPCQP71Spd9vn1rt48rgCbg1NrKHm5v76VcD3JS2afdqq2qjCAh4zpw5njNBxWhqh1iI9UGsTwvVU-ND8X9TNQptmuWL0utr8UF9RqDGRKi8o2CeUAM-q7azKLK9SE4i2YtNMn2Hn5FCXxEcQOQHGG8BGEdwEdkB_uEzX__C66cU-ekNwV9BjCenWoydqhAi6RkjwrazilBkR7p2yMvgg8jewcSe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