View mode: basic / threaded / horizontal-split · Log in · Help
November 03, 2012
[Issue 8955] New: Can't have qualified field with not-qualified constructor/postblit
http://d.puremagic.com/issues/show_bug.cgi?id=8955

          Summary: Can't have qualified field with not-qualified
                   constructor/postblit
          Product: D
          Version: D2
         Platform: All
       OS/Version: All
           Status: NEW
         Keywords: rejects-valid
         Severity: normal
         Priority: P2
        Component: DMD
       AssignedTo: nobody@puremagic.com
       ReportedBy: verylonglogin.reg@gmail.com


--- Comment #0 from Denis Shelomovskij <verylonglogin.reg@gmail.com> 2012-11-03 15:55:14 MSK ---
Currently constructor/postblit isn't qualified (see Issue 4338 and Issue 4867).
But it's violated for struct members:

---
struct S
{
   this(this) { }
   ~this() { }
}

struct S2
{ S s; }

const S  globalS;  // ok
const S2 globalS2; // ok

void f()
{
   const S  localS;  // ok
   const S2 localS2; // ok
}


struct S3 // or class, or union
{ const S s; } // any qualifier causes errors
---


Errors for S with postblit only:
---
Error: function main.S.__postblit () is not callable using argument types ()
const
---


Errors for S with destructor ony (note generated `opAssign`):
---
Error: destructor main.S.~this () is not callable using argument types () const
Error: function main.S.opAssign (S p) is not callable using argument types
(const(S)) const
---


Errors for S with postblit and destructor:
---
Error: destructor main.S.~this () is not callable using argument types () const
Error: function main.S.__postblit () is not callable using argument types ()
const
---


There is no line numbers in errors because of Issue 8954.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
November 03, 2012
[Issue 8955] Can't have qualified field with not-qualified constructor/postblit
http://d.puremagic.com/issues/show_bug.cgi?id=8955



--- Comment #1 from Denis Shelomovskij <verylonglogin.reg@gmail.com> 2012-11-03 17:25:18 MSK ---
Partial workaround:

For const/immutable postblit/dtor:
---
struct S
{
   private void myPostblit() { }
   this(this) inout
   { (cast(S*) &this).myPostblit(); }

   private void myDtor() { }
   ~this() inout // Plese `inout` before `~this()` if Issue 8953 unfixed
   { (cast(S*) &this).myDtor(); }
}

struct S_ { const S sc; immutable S si; }
---
Note: at least `this(this) inout { }` or `opAssign` is required for dtor

For shared dtor:
---
struct S
{
   void opAssign(shared S s) shared { this = s; } // required for dtor

   private void myDtor() { }
   shared~this()  // Plese `inout` before `~this()` if Issue 8953 unfixed
   { (cast(S*) &this).myDtor(); }
}

struct S_ { shared S sc; }
---

Same for constructor except it doesn't require somebody like dtor.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 09, 2013
[Issue 8955] Can't have qualified field with not-qualified constructor/postblit
http://d.puremagic.com/issues/show_bug.cgi?id=8955


jens.k.mueller@gmx.de changed:

          What    |Removed                     |Added
----------------------------------------------------------------------------
                CC|                            |jens.k.mueller@gmx.de


--- Comment #2 from jens.k.mueller@gmx.de 2013-01-09 06:58:53 PST ---
I stumbled over this today. What I don't understand is why/how postblit can be
const? I mean if the object is const then I shouldn't be allowed to change it.
Because you are copying to something that is const.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Top | Discussion index | About this forum | D home