<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/132463>132463</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Invalid `tuple_size` expressions in structured bindings not always detected
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang:frontend,
clang:diagnostics,
c++26
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
cor3ntin
</td>
</tr>
</table>
<pre>
Consider
```cpp
#include <utility>
template <typename... T>
struct S {};
namespace std {
template<typename... T>
struct tuple_size<S<T...>> {
size_t value = sizeof...(T); // std::tuple_size<S<int>>::value' is not a valid integral constant expression
};
}
template <typename... T>
constexpr void test() {
auto [...a] = S<T...>{}; // #1 error (expected)
static_assert(sizeof...(a) == sizeof...(T));
const auto [...b] = S<T...>{}; // #2 no error
static_assert(sizeof...(b) == sizeof...(T)); // says that `sizeof...(b)` is 0!!!!
static_assert(std::tuple_size<S<T...>>::value == sizeof...(T)); // correctly detect the lack of static
}
template void test<int>();
```
https://godbolt.org/z/enWdoM96j
`tuple_size<S<...>::value` is not a constant expression.
This is correctly detected on line `#1`.
But on line `#2` , we report no error,
considering instead (on the following line) that 'sizeof...(b)' evaluates to 0.
The only difference is that the decomposition is `const` on line `#2` - are we trying to perform constant folding? Incorrectly apply C++ constant expressions rules?
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJyMVU1v2zgQ_TX0ZVBBJi1bPujgjxroYU8NsMeAEkc2uzQpkKOk7q9fjCRHaZLdBiAgQEO9ee_xDaVTsmePWIliL4rjQvd0CbFqQlSerF_UwdyqQ_DJGowg8h2vdT6upuumN1JZ37jeIAh16Mk6Szehvo5VwmvnNA01unXo9RWzLIOHcUei2DcE30Fs9mJzFGo_fsbbUqcbhERmKM5Q_4tEfefwMdlfvO27UIeHLMt4h_o6wQAAcP2R4Em7npkdhxeh5a2yfBByK9QeQMiTkCdmINROqN07bOtphB7rA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