www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 7169] New: [CTFE] Assertion failure with inner struct

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

           Summary: [CTFE] Assertion failure with inner struct
           Product: D
           Version: D2
          Platform: x86
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: youxkei gmail.com


--- Comment #0 from Hisayuki Mima <youxkei gmail.com> 2011-12-27 18:29:01 JST
---
struct Struct(T){
    T t;
}

void func(T)(T t){
    Struct!T s;
    s.t = t;
}

static assert({
    struct InnerStruct{
        void func(){}
    }
    func(InnerStruct());
    return true;
}());

void main(){}


This code doesn't work.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Dec 27 2011
parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7169


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |ice-on-invalid-code
                 CC|                            |clugdbug yahoo.com.au


--- Comment #1 from Don <clugdbug yahoo.com.au> 2012-01-01 11:43:28 PST ---
According to the spec, I don't think this is supposed to work.
expression.html says:
----
Nested structs cannot be used as fields or as the element type of an array:

void foo() {
  int i = 7;
  struct SS {
    int x,y;
    int bar() { return x + i + 1; }
  }
  struct DD {
    SS s;  // error, cannot be field
  }
}
----
So creating such a struct by passing the nested struct as a template parameter
shouldn't work either. But, the compiler accepts the examples that the spec
says are errors. So I'm not sure if the bug is in the spec or the compiler.


The ICE is a variation of bug 6419, but where the nested struct is part of a
struct literal. Here's a test case with the same ICE, but this time where it's
part of an array.

void func2(T)(T t){
    T[2] s;
    s[0] = t;
}

static assert({
    struct InnerStruct{
        void func(){}
    }
    func2(InnerStruct());
    return true;
}());

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 01 2012