https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96286
--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
It also doesn't help that the compiler thwarts my attempt to trigger errors
earlier like so:
// Return index of _Tp in _Types.
// Ill-formed if _Tp doesn't occur exactly once in _Types.
template<typename _Tp, typename... _Types>
constexpr size_t
__find_uniq_type_in_pack()
{
constexpr ptrdiff_t __idx = std::__find_type_in_pack<_Tp, _Types...>();
static_assert(__idx >= 0,
"the type T in std::get<T> must occur exactly once in the tuple");
return size_t{__idx};
}
The return statement *should* be an ill-formed narrowing conversion, but G++
(and Clang) think that because I'm in a system header we probably wanted to
ignore that, so we return a huge value and get 200 lines of errors again.
Maybe this will work?
{
constexpr ptrdiff_t __idx = std::__find_type_in_pack<_Tp, _Types...>();
static_assert(__idx >= 0,
"the type T in std::get<T> must occur exactly once in the tuple");
if (__idx >= 0)
return __idx;
__builtin_unreachable();
}
No, now I get 200 lines telling me that the I in std::get<I> is not a constant
expression because of __builtin_unreachable.
OK, let's try return enable_if_t<__idx >= 0, size_t>{__idx};
This prints "error: no type named 'type' in 'struct std::enable_if'" as
expected, but then 200 lines telling me std::get<I> is not a constant
expression because it flows off the end of the function.
Why is the compiler even doing overload resolution for std::get<I> if I is an
invalid constant expression?! It's not going to match any overload!
It shouldn't be this hard. Just stop compiling already.