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

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Assignee|mpolacek at gcc dot gnu.org        |unassigned at gcc dot 
gnu.org
             Status|ASSIGNED                    |NEW

--- Comment #4 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Why is this a bug in GCC?


The test is basically

void
g (char *p)
{
  const char*&& r = static_cast<char*&&>(p);
}

We are initializing a reference, so go to [dcl.init.ref]/5:
A reference to type “cv1 T1” is initialized by an expression of type “cv2 T2”
as follows:

const char * and char * are related (~ similar types), but not compatible.

We don't have an lvalue reference so 5.1 and 5.2 are not applicable.
5.3.1 requires the initializer to be an rvalue but also "and “cv1 T1” is
reference-compatible with “cv2 T2”" which they're not here.  5.3.2 is about
classes.  So we go to 5.4 which says "Otherwise, T1 shall not be
reference-related to T2." but here they are.

Reply via email to