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

            Bug ID: 123296
           Summary: Can't direct-list-initialize unnamed temporary int&
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: blubban at gmail dot com
  Target Milestone: ---

(apologies if this is wrong terminology, I think this is case 2 of
https://en.cppreference.com/w/cpp/language/list_initialization.html )


int main() {
    int num;
    using intref = int&;
    int& ref = intref{ num };
}


No flags needed.


Expected: Compile it. Maybe with an unused-variable warning.

Actual:

<source>: In function 'int main()':
<source>:4:28: error: cannot bind non-const lvalue reference of type 'intref'
{aka 'int&'} to an rvalue of type 'int'
    4 |     int& ref = intref{ num };
      |                            ^
Compiler returned: 1


https://godbolt.org/z/K787vqMrY


Reduced from bug 123290

Reply via email to