On 09/10/19 16:29 -0400, Marek Polacek wrote:
On Wed, Oct 09, 2019 at 11:01:39AM +0100, Jonathan Wakely wrote:
On 07/10/19 14:56 -0400, Jason Merrill wrote:
> On 10/7/19 1:42 PM, Marek Polacek wrote:
> > @@ -7401,8 +7432,20 @@ convert_like_real (conversion *convs, tree expr, 
tree fn, int argnum,
> >             error_at (loc, "cannot bind non-const lvalue reference of "
> >                       "type %qH to an rvalue of type %qI", totype, extype);
> >           else if (!reference_compatible_p (TREE_TYPE (totype), extype))
> > -           error_at (loc, "binding reference of type %qH to %qI "
> > -                     "discards qualifiers", totype, extype);
> > +           {
> > +             /* If we're converting from T[] to T[N], don't talk
> > +                about discarding qualifiers.  (Converting from T[N] to
> > +                T[] is allowed by P0388R4.)  */
> > +             if (TREE_CODE (extype) == ARRAY_TYPE
> > +                 && TYPE_DOMAIN (extype) == NULL_TREE
> > +                 && TREE_CODE (TREE_TYPE (totype)) == ARRAY_TYPE
> > +                 && TYPE_DOMAIN (TREE_TYPE (totype)) != NULL_TREE)
> > +               error_at (loc, "binding reference of type %qH to %qI "
> > +                         "discards array bounds", totype, extype);
>
> If we're converting to T[N], that would be adding, not discarding, array
> bounds?

I don't think the diagnostic would be very good if we say "adds array
bounds" though. How about being consistent with the existing error for
similar cases?

a.cc:4:17: error: invalid initialization of reference of type ‘int (&)[3]’ from 
expression of type ‘int []’
  int (&b)[3] = a;
                ^

In my latest patch the error message reads "cannot bind reference of type T to U due 
to different array bounds".
It'd be trivial to adjust it if anyone hates that.

Works for me.

Reply via email to