Bug 7169 – [CTFE] Assertion failure with inner struct

Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2011-12-27T01:29:00Z
Last change time
2013-10-05T22:55:34Z
Keywords
CTFE, ice
Assigned to
nobody
Creator
youxkei

Comments

Comment #0 by youxkei — 2011-12-27T01:29:01Z
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.
Comment #1 by clugdbug — 2012-01-01T11:43:28Z
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; }());
Comment #2 by bugzilla — 2013-10-05T22:53:15Z
(In reply to comment #0) > 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. It produces a correct error message: test.d(6): Error: delegate test.__lambda4 is a nested function and cannot be accessed from test.func!(InnerStruct).func
Comment #3 by bugzilla — 2013-10-05T22:55:34Z
(In reply to comment #1) > According to the spec, I don't think this is supposed to work. It's not. > void func2(T)(T t){ > T[2] s; > s[0] = t; > } > > static assert({ > struct InnerStruct{ > void func(){} > } > func2(InnerStruct()); > return true; > }()); This also produces a correct error message: test.d(2): Error: cannot access frame pointer of test.__lambda3.InnerStruct test.d(10): Error: template instance test.func2!(InnerStruct) error instantiating Not an ICE.