[Bug libstdc++/113007] `std::variant` converting constructor and `operator=` compile while the C++ Standard says they must not
redi at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Thu Dec 14 01:03:21 GMT 2023
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113007
--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Pavel Novikov from comment #0)
> e.g. for `std::variant<std::monostate, bool, int64_t, double>` the overload
> set would be
>
> void F(std::monostate) {}
> void F(bool) {}
> void F(int64_t) {}
> void F(double) {}
No, because it says:
"build an imaginary function FUN(Ti) for each alternative type Ti for which Ti
x[] = {std::forward<T>(t)}; is well-formed for some invented variable x."
That array initializer would be ill-formed for all except int64_t.
std::monostate just can't be initialized from an int, and for double and bool
it's a narrowing conversion (because of the braces).
I think libstdc++ is correct.
More information about the Gcc-bugs
mailing list