Thread overview
[Issue 2380] New: static struct initializer accepted as non static initializer
Sep 30, 2008
d-bugmail
Oct 02, 2008
d-bugmail
Oct 02, 2008
d-bugmail
Oct 02, 2008
d-bugmail
Oct 03, 2008
d-bugmail
Oct 03, 2008
d-bugmail
[Issue 2380] static struct initializer accepted as non static initializer is not documented
Oct 03, 2008
d-bugmail
Oct 03, 2008
d-bugmail
Oct 03, 2008
d-bugmail
Oct 21, 2008
d-bugmail
September 30, 2008
http://d.puremagic.com/issues/show_bug.cgi?id=2380

           Summary: static struct initializer accepted as non static
                    initializer
           Product: D
           Version: 1.034
          Platform: PC
        OS/Version: All
            Status: NEW
          Keywords: accepts-invalid
          Severity: major
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla@digitalmars.com
        ReportedBy: tomas@famolsen.dk


D has different syntax for static struct initializers and struct literals. several threads on the NG has been about this and there are enhancement requests on this tracker as well...

dmd currently accepts the invalid code:

module structinitbug;
struct S {
        void* ptr;
}
void main() {
        S s = {null};
}

it seems that there are several issues surrounding initializers lately...

I found this due to it actually being used in Tango (xml.Document) and LLVMDC not handling it properly.


-- 

October 02, 2008
http://d.puremagic.com/issues/show_bug.cgi?id=2380


bugzilla@digitalmars.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |INVALID




------- Comment #1 from bugzilla@digitalmars.com  2008-10-02 04:02 -------
Static initializers are allowed for initializing non-statics. It is not a bug.


-- 

October 02, 2008
http://d.puremagic.com/issues/show_bug.cgi?id=2380


tomas@famolsen.dk changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
           Keywords|accepts-invalid             |spec
         Resolution|INVALID                     |




------- Comment #2 from tomas@famolsen.dk  2008-10-02 05:08 -------
It's not documented though, reopening as a spec bug


-- 

October 02, 2008
http://d.puremagic.com/issues/show_bug.cgi?id=2380





------- Comment #3 from kamm-removethis@incasoftware.de  2008-10-02 11:05 -------
What I found surprising was that you can use static initializers to initialize non-statics with non-static data. This passes on DMD and LLVMDC:

class C
{
  struct S {
    C ptr;
  }

  S foo() {
    S loc = {this};
    return loc;
  }
}

void main()
{
  auto c = new C;
  assert(c.foo().ptr is c);
}


-- 

October 03, 2008
http://d.puremagic.com/issues/show_bug.cgi?id=2380





------- Comment #4 from samukha@voliacable.com  2008-10-03 02:47 -------
What's more surprising is that not all static initializers are allowed to initialize non-statics:

int[] a = [1, 2, 3]; // ok. int[] b = [1 : 2, 3]; // fails. only static arrays can be initialized like this

Though it seems to be according to the specs, I don't see the reason why initializers with indexes are special cased.

And this one may be considered a bug:
void foo()
{
  int[3] a = [ 1:2, 3 ]; // fails. static static arrays, only:
  static int[3] a = [ 1:2, 3 ]; // ok
}


-- 

October 03, 2008
http://d.puremagic.com/issues/show_bug.cgi?id=2380


bugzilla@digitalmars.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|REOPENED                    |RESOLVED
         Resolution|                            |INVALID




------- Comment #5 from bugzilla@digitalmars.com  2008-10-03 03:39 -------
I agree it's an inconsistent design, but it is not a bug. Static initializer syntax is different. You can enter an enhancement request to change the design.


-- 

October 03, 2008
http://d.puremagic.com/issues/show_bug.cgi?id=2380


tomas@famolsen.dk changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
         Resolution|INVALID                     |
            Summary|static struct initializer   |static struct initializer
                   |accepted as non static      |accepted as non static
                   |initializer                 |initializer is not
                   |                            |documented




------- Comment #6 from tomas@famolsen.dk  2008-10-03 04:23 -------
but it's still not documented !!! reopening, changing the description a bit. the spec should mention that this is allowed..


-- 

October 03, 2008
http://d.puremagic.com/issues/show_bug.cgi?id=2380





------- Comment #7 from tomas@famolsen.dk  2008-10-03 04:53 -------
also the point that Christian mentions, that the initializer need not be static is especially surprising given no documentation.


-- 

October 03, 2008
http://d.puremagic.com/issues/show_bug.cgi?id=2380





------- Comment #8 from bugzilla@digitalmars.com  2008-10-03 14:57 -------
Ok :-)


-- 

October 21, 2008
http://d.puremagic.com/issues/show_bug.cgi?id=2380


bugzilla@digitalmars.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|REOPENED                    |RESOLVED
         Resolution|                            |FIXED




------- Comment #9 from bugzilla@digitalmars.com  2008-10-20 22:19 -------
Fixed dmd 1.036 and 2.020


--