@vaporeon_ evidently I have burnt my brain today
@vaporeon_ it should be #include
@vaporeon_ what the fuck is mastodon is hiding the hashtag
@vaporeon_ it should be #include <iostream>
@wallhackio Maybe it's stripping out <iostream>
because it thinks that it's a HTML tag that it doesn't recognize?
@vaporeon_ @wallhackio likely
@wallhackio OK, if the a
is declared, then I think that A()
is creating a new object of class A
, and then = a
copies the values from a
into it, and, like any assignment, returns its right part, so returns a
, and &
will simply return the address of a
.
But I'm too stupid for C++, I'm probably wrong
@vaporeon_ @wallhackio this is very close but there is some pedantry here
&
) out of the result of the expurression. (no i do not even know how to begin to explain what an lvalue refurence “is”)@aescling @wallhackio > the value of the left side (after assignment) is the value of the assignment expurression
Oh... So will &(A() = a)
, instead of returning the address of a
, return the address of the newly-created A()
?
@vaporeon_ @aescling yes
@vaporeon_ @aescling but the result of A()
is an rvalue, which is not allowed to be given to & or appear on the left side of an assignment. That is the mystifying part here
@wallhackio it's just outputting the address of a temporary object? and then a newline? why wouldn't it compile? there's not even any UB here i think (since you never dereference the resulting pointer)
@alyssa a constructor returns an rvalue which is not supposed to be allowed to appear on the left side of an assignment
@wallhackio at least in C++23 it returns a prvalue, which can be implicitly converted to an xvalue. although, hmm, an xvalue is only a glvalue, not an lvalue (which the assignment operator requires) so that doesn't seem to explain it. alas idk
@wallhackio Now it won't compile because there's nothing after the include: