https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78113

--- Comment #2 from Antony Polukhin <antoshkka at gmail dot com> ---
Here's another example:

#include <variant>

struct A {};
struct B : A {};
struct C : A {};
struct D : A {};
struct E : A {};
struct X : A {};

struct visitor {
    template <class T>
    A& operator()(T& v) const noexcept { return v; }
};

A& get_base(std::variant<B, C, D, E, X>& in) {
    return std::visit(visitor{}, in);
}


GCC's current implementation via table of function pointers is badly optimized
by GCC-9 (trunk) and generates a lot of equal functions:
https://godbolt.org/z/g9hJjV

Boost's approach produces a better result on the same compiler:
https://godbolt.org/z/BnemR1

Reply via email to