https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88103
Bug ID: 88103 Summary: Wrong value category when conditional expression result is used as object expression Product: gcc Version: 8.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: okannen at gmail dot com Target Milestone: --- In the code below, if the conditional expression is an xvalue, and only when this xvalue is used as the object expression in class member access, gcc treat it as if it were an lvalue. The problem does not happen when the conditional expression is a prvalue: struct A { A(int); A&& foo() && ; int i; }; void free(A&&); void test_xvalue(A a){ //No error A&& ref = true? static_cast<A&&>(a) : static_cast<A&&>(a); //No error free(true? static_cast<A&&>(a) : static_cast<A&&>(a)); //Unexpected error: passing A as this discard qualifier (true? static_cast<A&&>(a) : static_cast<A&&>(a)).foo(); //Unexpected error: error cannot bind rvalue reference // of type int&& to lvalue of type int int&& k=(true? static_cast<A&&>(a) : static_cast<A&&>(a)).i; } void test_prvalue(A a){ //No error A&& ref = true? static_cast<A&&>(a) : 1; //No error free(true? static_cast<A&&>(a) : 1); //No error (true? static_cast<A&&>(a) : 1).foo(); //No error int&& k=(true? static_cast<A&&>(a) : 1).i; }