www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 10980] New: [reg] static initialization of immutable structs with disabled postblit fails

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

           Summary: [reg] static initialization of immutable structs with
                    disabled postblit fails
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: regression
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: monarchdodra gmail.com


--- Comment #0 from monarchdodra gmail.com 2013-09-06 08:08:48 PDT ---
Let S be a struct a disabled potsblit, and we want to create a static instance
of an immutable S:

//----
alias immutable(S) IS;
static IS i = IS.init;
//----

2.060: OK!
2.061: Error: variablei of type struct immutable(S) uses this(this), which is
not allowed in static initialization
2.062: Error: variable hello.i of type struct immutable(S) uses this(this),
which is not allowed in static initialization
2.063: OK!
2.063.2: OK!

So... it broke and it was fixed (apparently).

BUT!
Let's try that in a template now:

//----
template foo(T)
{
    static T i = T.init;
    alias i foo;
}

struct S
{
     disable this(this);
}
alias immutable(S) IS;

//IS i = IS.init; //Uncoment me

void main()
{
    auto p = &foo!IS;
}
//----
2.060: OK!
2.061: Error: variable main.i of type struct immutable(S) uses this(this),
which is not allowed in static initialization
2.062: Error: variable main.i of type struct immutable(S) uses this(this),
which is not allowed in static initialization
2.063: Error: template instance main.foo!(immutable(S)) error instantiating
2.063.2: Error: template instance main.foo!(immutable(S)) error instantiating

Now, we simply have an "unclear" error that the template failed, but with no
diagnostics (at least, I am unable to provide any).

Funny story: if we uncomment the global static, it works again. Another
workaround is to declare the static inside a function, and have the function
return the static by reference.

This issue is also "semi-blocker" in emplace, which needs to create a static
instance of T, no matter T's type.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Sep 06 2013
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10980


Kenji Hara <k.hara.pg gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull, rejects-valid
            Summary|[reg] static initialization |static initialization of
                   |of immutable structs with   |immutable structs with
                   |disabled postblit fails     |disabled postblit fails
           Severity|regression                  |blocker


--- Comment #1 from Kenji Hara <k.hara.pg gmail.com> 2013-09-08 23:34:36 PDT ---
(In reply to comment #0)
 Let S be a struct a disabled potsblit, and we want to create a static instance
 of an immutable S:
 
 //----
 alias immutable(S) IS;
 static IS i = IS.init;
 //----
 
 2.060: OK!
 2.061: Error: variablei of type struct immutable(S) uses this(this), which is
 not allowed in static initialization
 2.062: Error: variable hello.i of type struct immutable(S) uses this(this),
 which is not allowed in static initialization
 2.063: OK!
 2.063.2: OK!
 
 So... it broke and it was fixed (apparently).
The issue had not been fixed, instead it just be hidden by the regression bug 10998, from 2.063.
 BUT!
 Let's try that in a template now:
 
 //----
 template foo(T)
 {
     static T i = T.init;
     alias i foo;
 }
 
 struct S
 {
      disable this(this);
 }
 alias immutable(S) IS;
 
 //IS i = IS.init; //Uncoment me
 
 void main()
 {
     auto p = &foo!IS;
 }
 //----
 2.060: OK!
 2.061: Error: variable main.i of type struct immutable(S) uses this(this),
 which is not allowed in static initialization
 2.062: Error: variable main.i of type struct immutable(S) uses this(this),
 which is not allowed in static initialization
 2.063: Error: template instance main.foo!(immutable(S)) error instantiating
 2.063.2: Error: template instance main.foo!(immutable(S)) error instantiating
 
 Now, we simply have an "unclear" error that the template failed, but with no
 diagnostics (at least, I am unable to provide any).
 
 Funny story: if we uncomment the global static, it works again. Another
 workaround is to declare the static inside a function, and have the function
 return the static by reference.
 
 This issue is also "semi-blocker" in emplace, which needs to create a static
 instance of T, no matter T's type.
Because the current compile-time postblit call check is not enough strict. I opened a compiler fix to improve check mechanism. https://github.com/D-Programming-Language/dmd/pull/2541 -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Sep 08 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10980



--- Comment #2 from github-bugzilla puremagic.com 2013-09-09 14:08:31 PDT ---
Commit pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/4af52deaba5a24130695a48c132f8e7d46236859
fix Issue 10980 - static initialization of immutable structs with disabled
postblit fails

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Sep 09 2013
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10980


Walter Bright <bugzilla digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |bugzilla digitalmars.com
         Resolution|                            |FIXED


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