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

            Bug ID: 91849
           Summary: Misleading diagnostic message when binding reference
                    to unrelated type
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: mpolacek at gcc dot gnu.org
  Target Milestone: ---

void
g ()
{
  float f = 1.f;
  int &r = f;
}

void
g2 ()
{
  int &r = 1.f;
}

gives
q.C: In function ‘void g()’:
q.C:5:12: error: cannot bind non-const lvalue reference of type ‘int&’ to an
rvalue of type ‘int’
    5 |   int &r = f;
      |            ^
q.C: In function ‘void g2()’:
q.C:11:12: error: cannot bind non-const lvalue reference of type ‘int&’ to an
rvalue of type ‘int’
   11 |   int &r = 1.f;
      |            ^~~

which could be improved.  clang++ says
q.C:5:8: error: non-const lvalue reference to type 'int' cannot bind to a value
of
      unrelated type 'float'
  int &r = f;
       ^   ~
q.C:11:8: error: non-const lvalue reference to type 'int' cannot bind to a
temporary of
      type 'float'
  int &r = 1.f;
       ^   ~~~

Reply via email to