www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 8118] New: Impossible to initialize a member struct without default constructor or assigment

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8118

           Summary: Impossible to initialize a member struct without
                    default constructor or assigment
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: critical
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: wfunction hotmail.com


--- Comment #0 from wfunction hotmail.com 2012-05-18 17:05:19 PDT ---
struct S
{
     disable this();
    this(int) { }
     disable void opAssign(typeof(this));
}

class Test
{
    S s = void;      // I *EXPLICITLY* told it not to be initialized, but...
    this() { s = S(to!int("1")); }
}

void main() { new Test(); }


Error: function S.opAssign is not callable because it is annotated with
 disable
Error: default construction is disabled for type Test



Structs without default constructors are pretty much impossible to use.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 18 2012
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8118



--- Comment #1 from wfunction hotmail.com 2012-05-18 17:05:45 PDT ---
Possibly related:
http://d.puremagic.com/issues/show_bug.cgi?id=8117

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 18 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8118


Dmitry Olshansky <dmitry.olsh gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |dmitry.olsh gmail.com


--- Comment #2 from Dmitry Olshansky <dmitry.olsh gmail.com> 2012-05-19
03:44:28 PDT ---
(In reply to comment #0)
 struct S
 {
      disable this();
     this(int) { }
      disable void opAssign(typeof(this));
 }
 
 class Test
 {
     S s = void;      // I *EXPLICITLY* told it not to be initialized, but...
     this() { s = S(to!int("1")); }
 }
 
 void main() { new Test(); }
 
 
 Error: function S.opAssign is not callable because it is annotated with
  disable
 Error: default construction is disabled for type Test
 
 
 
 Structs without default constructors are pretty much impossible to use.

No bug here you just diabled too much. Undisable opAssign. It's opAssign that gets called whne a = ... is seen: this() { s = S(to!int("1")); } If opAssign is trivial it replaced with bitblit. (that is disable comes first!) -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
May 19 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8118



--- Comment #3 from wfunction hotmail.com 2012-05-19 12:15:42 PDT ---
(In reply to comment #2)
 No bug here you just diabled too much. Undisable opAssign.
 
 It's opAssign that gets called whne a = ... is seen:
 this() { s = S(to!int("1")); }
 If opAssign is trivial it replaced with bitblit. (that is disable comes first!)

Uh, no, it's a bug IMO. I never asked for an assignment. I want to CONSTRUCT the object manually. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
May 19 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8118



--- Comment #4 from wfunction hotmail.com 2012-05-19 12:17:48 PDT ---
(In reply to comment #3)
 (In reply to comment #2)
 No bug here you just diabled too much. Undisable opAssign.
 
 It's opAssign that gets called whne a = ... is seen:
 this() { s = S(to!int("1")); }
 If opAssign is trivial it replaced with bitblit. (that is disable comes first!)

Uh, no, it's a bug IMO. I never asked for an assignment. I want to CONSTRUCT the object manually.

For example, pretend this is the Scoped struct. I *obviously* wouldn't want to assign anything, but I'd want to construct the object. The fact that it's **impossible** to call the constructor directly without an assignment getting in the way (as far as I see) is a bug. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
May 19 2012
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8118


Marco Leise <Marco.Leise gmx.de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |Marco.Leise gmx.de


--- Comment #5 from Marco Leise <Marco.Leise gmx.de> 2013-02-15 06:17:42 PST ---
(In reply to comment #4)
 The fact that it's **impossible** to call the constructor directly without an
 assignment getting in the way (as far as I see) is a bug.

I agree with you. I have a struct that is not supposed to be copied. Now I cannot use it as a field in any other struct/class. In some cases a work-around may be to allow assignments, but check that the receiver is S.init. Also I tried "= void" first. So it may be the most intuitive to use for the bug fix. I haven't checked, but it could allow code like this if not currently possible: S s = void; if (xyz) { s = S(3); } else { s = S(7); } -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Feb 15 2013