Issue |
132463
|
Summary |
Invalid `tuple_size` expressions in structured bindings not always detected
|
Labels |
clang:frontend,
clang:diagnostics,
c++26
|
Assignees |
|
Reporter |
cor3ntin
|
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?
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs