dmd 1.054 and 2.038 release

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Fri Jan 1 08:16:00 PST 2010


Steven Schveighoffer wrote:
> On Thu, 31 Dec 2009 16:20:08 -0500, Walter Bright 
> <newshound1 at digitalmars.com> wrote:
> 
>> Steven Schveighoffer wrote:
>>>> (I'm assuming bug 1961('scoped const') is considered to be fixed).
>>>  Sadly, it's not fixed yet :(
>>>   struct S
>>> {
>>>     int x;
>>>     inout(int)* getX() inout { return &x;}
>>> }
>>>  void main()
>>> {
>>>     S s;
>>>     int *x = s.getX();
>>> }
>>>   testinout.d(10): Error: function testinout.S.getX () inout is not 
>>> callable using argument types ()
>>> testinout.d(10): Error: cannot implicitly convert expression 
>>> (s.getX()) of type inout(int)* to int*
>>>  It appears the auto-conversion is not happening on the return, and 
>>> also the call isn't working.
>>
>> The inout on the return has to be at the top level, as in inout(int 
>> *). This probably needs improvement.
> 
> Yes, this is an important distinction.
> 
> With your recommended change, the error is now:
> 
> testinout.d(4): Error: inout on return means inout must be on a 
> parameter as well for inout inout(int*)()
> 
> inout doesn't seem to work with ref either.  The only thing I could get 
> to work is this:
> 
> 
> struct S
> {
>     int x;
> }
> 
> inout(int *) getSX(inout S* s) { return &s.x;}
> 
> void main()
> {
>     S s;
>     const(S)* sp = &s;
>     int *x = getSX(&s);
>     //int *y = getSX(sp);  // uncomment this line for an error
>     const(int) *y = getSX(sp);
> }
> 
> If you uncomment the designated line, the error reads:
> 
> testinout.d(13): Error: cannot implicitly convert expression (getSX(sp)) 
> of type const(int*) to int*
> 
> which looks good.
> 
> -Steve

Well I'm sorry to tell that inout is useless as currently implemented. 
One important motivating use case was:

inout(char)[] blah(inout(char)[] input) {
     return input;
}

void main()
{
     blah("xyz");
     blah("xyz".dup);
}

That doesn't work at all. The second motivating case also doesn't work:

class A {
     A _next;
     inout A next() inout { return _next; }
}

void main()
{
     auto a = new A;
     const b = a;
     auto c = a.next();
     auto d = b.next();
}

There are few, if any, cases where the current inout does help. The good 
news is that most of the implementation effort has been done so probably 
making things work will not be very difficult.


Andrei


More information about the Digitalmars-d-announce mailing list