I will give the first person to correctly explain why this compiles a nice compliment

#include <iostream>

class A {};

int main() {
std::cout << &(A() = a) << "\n";
}

Oops there is missing declaration of the variable a. This is what you should be examining:

class A {};

int main() {
A a;
std::cout << &(A() = a) << "\n";
}

@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

Follow

@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

Sign in to participate in the conversation
📟🐱 GlitchCat

A small, community‐oriented Mastodon‐compatible Fediverse (GlitchSoc) instance managed as a joint venture between the cat and KIBI families.