C++ PATCH for C++20 P0388R4 (conversions to arrays of unknown bounds) and CWG 1307 (c++/91364, c++/69531)

Jonathan Wakely jwakely@redhat.com
Wed Oct 9 10:13:00 GMT 2019


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;
                 ^



More information about the Gcc-patches mailing list