[Issue 10276] New: Compiler pointlessly makes a struct nested even if it doesn't need to be

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Jun 5 09:40:42 PDT 2013


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

           Summary: Compiler pointlessly makes a struct nested even if it
                    doesn't need to be
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: andrej.mitrovich at gmail.com


--- Comment #0 from Andrej Mitrovic <andrej.mitrovich at gmail.com> 2013-06-05 09:40:41 PDT ---
-----
import std.traits;

unittest
{
    /* static */ struct S1
    {
        int x;
    }

    /* static */ struct S2
    {
        this(int) { }
        int x;
    }


    static assert(!isNested!S1);
    static assert(!isNested!S2);  // fails
}

void main()
{
}
-----

There is absolutely no need to make a struct nested *unless* it needs the
context pointer. The compiler seems to make it a nested type as soon as it has
any function or ctor implemented. This seems like arbitrary behavior.

This is a problem with structs defined within unittests, because they end up
breaking template code in weird ways (for example nested types can't be used
with T.init).

Using static explicitly is of course the workaround, but it should never be a
requirement. The compiler should prefer making a struct static *unless* it has
to do otherwise.

-- 
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