Rvalue references - The resolution

Jonathan M Davis jmdavisProg at gmx.com
Sat May 4 18:49:42 PDT 2013


On Sunday, May 05, 2013 01:03:17 Andrej Mitrovic wrote:
> On 5/4/13, Walter Bright <newshound2 at digitalmars.com> wrote:
> > Andrei & I argued that we needed to make it work with just ref
> > annotations.
> 
> So to recap, 2.063 turns slices into r-values which will break code
> that used ref, e.g.:
> 
> -----
> void parse(ref int[] arr) { }
> 
> void main()
> {
>     int[] arr = [1, 2];
>     parse(arr[]);  // ok in 2.062, error in 2.063
> }
> -----
> 
> Then the user might introduce a non-ref overload:
> 
> -----
> void parse(ref int[] arr) { }
> void parse(int[] arr) { }  // picks this one
> -----
> 
> And later down the road, maybe even in 2.064, ref will take r-values
> making the new code error because of ambiguity between the two
> functions.
> 
> Has code breakage ever been taken into account during this dconf
> conversation?
> 
> I doubt a short verbal conversation can solve design problems or take
> into account all edge-cases, this is why we have the web where we can
> document all code samples and the flaws of some design spec.
> 
> This "resolution" should be a DIP that goes through a review just like
> all the other DIPs, otherwise DIPs are pointless if they get overruled
> by some behind-the-scenes conversation.

The rvalue part wasn't agreed upon, just the @safety solution. I'm sure that 
the @safety solution can be discussed further if there's dissension, but it's 
completely non-breaking change (the only case where you'd get an Error is one 
where the code was operating on a variable which had already left scope and 
been destroyed). So, I wouldn't expect there to be any real issues with that. 
The rvalue portion, however, definitely needs further discussion. Walter was in 
favor of ref accepting rvalues (I think that he though that accepting rvalues 
was only a safety issue, but I'm not sure), so maybe that's why he was 
thinking that that was resolved, but there was certainly no agreement on it 
even between him and Andrei, let alone among the rest of us.

- Jonathan M Davis


More information about the Digitalmars-d mailing list