On 1/4/21 3:48 PM, Jakub Jelinek wrote:
On Mon, Jan 04, 2021 at 03:44:46PM -0500, Jason Merrill wrote:
This change is OK, but part of the problem is that we're trying to do
overload resolution for an S copy/move constructor, which we shouldn't be
because bit_cast is a prvalue, so in C++17 and up we should use it to
directly initialize the target without any implied constructor call.
It seems we're mishandling this because the code in
build_special_member_call specifically looks for TARGET_EXPR or CONSTRUCTOR,
and BIT_CAST_EXPR is neither of those.
Wrapping a BIT_CAST_EXPR of aggregate type in a TARGET_EXPR would address
this, and any other places that expect a class prvalue to come in the form
of a TARGET_EXPR.
I can try that tomorrow. Won't that cause copying through extra temporary
in some cases though, or is that guaranteed to be optimized?
It won't cause any extra copying when it's used to initialize another
object (like the return value of std::bit_cast). Class prvalues are
always expressed with a TARGET_EXPR in the front end; the TARGET_EXPR
melts away when used as an initializer, it only creates a temporary when
it's used in another way.
Jason