https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61736

            Bug ID: 61736
           Summary: Conditional expression yields wrong value category
           Product: gcc
           Version: 4.10.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: kaballo86 at hotmail dot com

The following snippet results in a compilation error: invalid initialization of
non-const reference of type ‘int&’ from an rvalue of type ‘int’:

    int* foo(){ return nullptr; }
    int& bar(){ return foo() != nullptr ? *foo() : throw 0; } // error

    int main() {
      int& ref = bar();
    }

According to [expr.cond]/2:
> If either the second or the third operand has type void, one of the following 
> shall hold:
>  — The second or the third operand (but not both) is a (possibly 
> parenthesized) throw-expression (15.1); the result is of the type and value 
> category of the other.

The value category of the conditional expression would be that of `*foo()`,
which should be an lvalue and bind to `int&`.

Reply via email to