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

--- Comment #2 from Konstantin Kharlamov <Hi-Angel at yandex dot ru> ---
(In reply to Jonathan Wakely from comment #1)
> That would require a lot of special-casing just for std::variant.

Well, I think, in place of std::variant there could be any struct-wrapper; but
I get it.

> Clang does print a lot more info, including this:
> 
> /home/jwakely/gcc/latest/lib/gcc/x86_64-pc-linux-gnu/9.0.0/../../../../
> include/c++/9.0.0/variant:1093:2: note: candidate template ignored:
> substitution failure [with _Tp = PacketErr &, $1 = void, $2 = void]:
> implicit instantiation of undefined template
>       'std::variant<std::monostate,
> PacketErr>::__to_type_impl<18446744073709551615, false>'
>         variant(_Tp&& __t)
>         ^
> 
> But that still doesn't come close to telling you that the type is not
> copyable.

Actually, GCC does give the like output if you'd replace `return {ret}` with
explicit `return std::variant<std::monostate, PacketErr>{ret}`, though it
doesn't hint about the type being non-copyable either.

> N.B. If you just write "return ret;" it will compile fine. In general
> "return x;" is better than "return {x};" because it doesn't prevent NRVO.

Thanks, I prefer the `{x}` to just `x` because in the latter I'm being explicit
that the `x` is not the type I'm returning, but there's some other type that
it's being wrapped to.

As far as such trivial optimizations concerned, I'd prefer to rely on the
compiler figuring that out — in the end, that's why we don't write assembly,
right? =)

Reply via email to