https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91023
--- Comment #1 from Christoph Höger <christoph.hoeger at celeraone dot com> --- Since it might help investigating the issue, here is a workaround: #include <variant> #include <optional> template <typename T, typename S> struct Foo { }; template <typename... T, typename S> std::optional<std::variant<T...>> parse_variant(const Foo<T, S> &... variants) { return {}; } struct A {}; struct B {}; using var_test = std::variant<A, B>; Foo<A, var_test> a() { return {}; } Foo<B, var_test> b() { return {}; } int main() { const auto x = parse_variant(a(), b()); return 0; }