https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118434
Bug ID: 118434
Summary: std::visit should be updated to handle immediate
functions
Product: gcc
Version: 15.0
Status: UNCONFIRMED
Keywords: rejects-valid
Severity: normal
Priority: P3
Component: libstdc++
Assignee: unassigned at gcc dot gnu.org
Reporter: de34 at live dot cn
Target Milestone: ---
It seems that the following example should be valid since C++20 (patched by
P2564R3).
```
#include <variant>
consteval auto func(const std::variant<int>& v1, const std::variant<int>& v2) {
return std::visit([](auto x, auto y) consteval { return x + y; }, v1, v2);
}
static_assert(func(std::variant<int>{42}, std::variant<int>{1729}) == 1771);
```
But libstdc++ currently rejects it (https://godbolt.org/z/h59hWK9G3), because
the there's a hand-made vtable which will contain pointers to immediate
(immediate-escalated) functions while being constexpr.
I guess we can make the vtable a non-constexpr variable of automatic storage
duration when the vtable can't be constexpr. It seems that we can determine
this by testing that
`__some_alias_template<__gen_vtable_impl<...>::_S_apply>()>` is not a valid
type.