[Bug c++/86475] New: CWG 1550

zhonghao at pku dot org.cn gcc-bugzilla@gcc.gnu.org
Wed Jul 11 00:40:00 GMT 2018


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

            Bug ID: 86475
           Summary: CWG 1550
           Product: gcc
           Version: 8.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: zhonghao at pku dot org.cn
  Target Milestone: ---

I looked around to see if a bug was already filed on this and couldn't find
one.

CWG 1550, passed in Bristol, changes the value category of the result of a
conditional operator when one operand is an lvalue and the other is a
throw-expression:

* 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.

Here is a test, that should compile in C++:

struct X
{
    int i_;
    bool b_;

    int& test() {return b_ ? i_ : throw 1;}
};

Current behavior is:

 error: cannot bind non-const lvalue reference of type 'int&' to an rvalue of
type 'int'
  int& test() {return b_ ? i_ : throw 1;}
                      ~~~^~~~~~~~~~~~~~

                        ^~~~~~~~~~~~~~~~~
1 error generated.

I tried clang++. It accepts the code.


More information about the Gcc-bugs mailing list