[Issue 10980] New: [reg] static initialization of immutable structs with disabled postblit fails

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Sep 6 08:08:49 PDT 2013


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 at puremagic.com
        ReportedBy: monarchdodra at gmail.com


--- Comment #0 from monarchdodra at 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: -------


More information about the Digitalmars-d-bugs mailing list