https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111172
Bug ID: 111172
Summary: Dead code in std::get for variant?
Product: gcc
Version: 14.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: libstdc++
Assignee: unassigned at gcc dot gnu.org
Reporter: hewillk at gmail dot com
Target Milestone: ---
In libstdc++'s implementation of variant's std::get, there are static_asserts
that require T not to be void, for example:
template<typename _Tp, typename... _Types>
constexpr _Tp&
get(variant<_Types...>& __v)
{
static_assert(__detail::__variant::__exactly_once<_Tp, _Types...>,
"T must occur exactly once in alternatives");
static_assert(!is_void_v<_Tp>, "_Tp must not be void");
constexpr size_t __n = std::__find_uniq_type_in_pack<_Tp, _Types...>();
return std::get<__n>(__v);
}
But it looks like such static_asserts are *never* fired because the return type
already causes a compile error of forming reference to void when T is void.