https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86184
--- Comment #2 from zhonghao at pku dot org.cn ---
(In reply to Jonathan Wakely from comment #1)
> (In reply to zhonghao from comment #0)
> > gcc++ produces errors when compiling the following code:
>
> I don't see any errors. You didn't say which version of GCC you're using or
> what options you're using, as requested by https://gcc.gnu.org/bugs/
I am sorry. I provide a wrong code sample from the clang bug report. The
correct code sample is:
#include
struct X {
X() { printf("X(): this=%p\n", this); }
X(const X& other) { printf("X(const ):this=%p, other=%p\n", this, ); }
~X() { printf("~X(): this=%p\n", this); }
operator bool() { printf("X::operator bool(): this=%p\n", this); return true;
}
};
int main() {
X x = X()? : X();
}
g++ rejects the above code, and the error message is:
error: lvalue required as unary '&' operand
X x = X()? : X();
clang++ accepts the code.