www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - inout problems

reply Andrej Mitrovic <andrej.mitrovich gmail.com> writes:
class Foo
{
    this(int) inout
    { }

    Foo makeFoo() { return new Foo(1); }
}

void main() { }

test.d(8): Error: cannot implicitly convert expression (new Foo(1)) of
type inout(Foo) to test.Foo

Is this a bug?
Feb 21 2012
next sibling parent reply deadalnix <deadalnix gmail.com> writes:
Le 22/02/2012 05:01, Andrej Mitrovic a écrit :
 class Foo
 {
      this(int) inout
      { }

      Foo makeFoo() { return new Foo(1); }
 }

 void main() { }

 test.d(8): Error: cannot implicitly convert expression (new Foo(1)) of
 type inout(Foo) to test.Foo

 Is this a bug?

inout is supposed to propagate a parameter qualifier to the return type. Here, inout is useless, and it isn't surprising that it doesn't work.
Feb 22 2012
parent Timon Gehr <timon.gehr gmx.ch> writes:
On 02/22/2012 01:22 PM, deadalnix wrote:
 Le 22/02/2012 05:01, Andrej Mitrovic a écrit :
 class Foo
 {
 this(int) inout
 { }

 Foo makeFoo() { return new Foo(1); }
 }

 void main() { }

 test.d(8): Error: cannot implicitly convert expression (new Foo(1)) of
 type inout(Foo) to test.Foo

 Is this a bug?

inout is supposed to propagate a parameter qualifier to the return type. Here, inout is useless, and it isn't surprising that it doesn't work.

It is not useless, inout constructors are supposed to work and already work for structs. The idea is that such a constructor is able to create an object of arbitrary const-ness.
Feb 22 2012
prev sibling parent Timon Gehr <timon.gehr gmx.ch> writes:
On 02/22/2012 05:01 AM, Andrej Mitrovic wrote:
 class Foo
 {
      this(int) inout
      { }

      Foo makeFoo() { return new Foo(1); }
 }

 void main() { }

 test.d(8): Error: cannot implicitly convert expression (new Foo(1)) of
 type inout(Foo) to test.Foo

 Is this a bug?

Yes. See http://d.puremagic.com/issues/show_bug.cgi?id=7053
Feb 22 2012