[Issue 7378] New: inout constructors do not properly resolve to immutable.

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Jan 27 06:44:14 PST 2012


http://d.puremagic.com/issues/show_bug.cgi?id=7378

           Summary: inout constructors do not properly resolve to
                    immutable.
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Keywords: wrong-code
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: schveiguy at yahoo.com


--- Comment #0 from Steven Schveighoffer <schveiguy at yahoo.com> 2012-01-27 06:44:10 PST ---
The following code:

import std.stdio;

struct T
{
  int *data;
  this(inout(int)* d) inout {this.data = d;}
}

void main()
{
  int x;
  const int xc;
  immutable int xi;

  writeln(typeof(T(&x)).stringof);
  writeln(typeof(T(&xc)).stringof);
  writeln(typeof(T(&xi)).stringof);
}

outputs:

T
const(T)
const(T)

It should output:

T
const(T)
immutable(T)

I suspect the issue is that the constructor's this pointer is being treated as
a parameter instead of the result, and it's implicitly declared as mutable.  If
you consider that in a constructor, the return value is a newly constructed T
struct, the 'this' parameter is semantically the return value.

So what should happen is the inout resolution mechanism should treat the
parameters to the constructor as the only parameters, and the implicit this
parameter as the return value.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list