digitalmars.D.learn - Templates with alias param instantiated with null cached by DMD..?
- simendsjo (13/13) Oct 23 2013 I've stumbled upon a strange bug, and I'm not sure what I should
- Kenji Hara (15/29) Oct 23 2013 A!(S1.init.p) is mostly same as A!( cast(S1*)null ), because the
- simendsjo (3/37) Oct 23 2013 Ok. Filed a bug. Probably not a good description, but I linked to
I've stumbled upon a strange bug, and I'm not sure what I should write in the bug report. Could someone explain what's going on here or file the bug for me? template A(alias T) { alias A = T; } void main() { struct S1 { S1* p; } static assert(is(typeof(A!(S1.init.p)) == S1*)); // ok pragma(msg, "NULL: ", typeof(A!(null))); // fail: S1* struct S2 { S2* p; } static assert(is(typeof(A!(S2.init.p)) == S2*)); // fail: S1* }
Oct 23 2013
On Wednesday, 23 October 2013 at 07:22:56 UTC, simendsjo wrote:I've stumbled upon a strange bug, and I'm not sure what I should write in the bug report. Could someone explain what's going on here or file the bug for me? template A(alias T) { alias A = T; } void main() { struct S1 { S1* p; } static assert(is(typeof(A!(S1.init.p)) == S1*)); // ok pragma(msg, "NULL: ", typeof(A!(null))); // fail: S1* struct S2 { S2* p; } static assert(is(typeof(A!(S2.init.p)) == S2*)); // fail: S1* }A!(S1.init.p) is mostly same as A!( cast(S1*)null ), because the expression S1.init.p is interpreted to a null value. 1. But current ABI does not support "a typed null template value argument" because all of null expression on template argument are mangled to 'n'. So the type of null value will be never encoded in the mangled name, and the three instantiations A!(S1.init.p), A!(null) and A!(S2.init.p) will have exactly same mangling. 2. However, the first instantiation A!(S1.init.p) wrongly caches the null value type (== S1*), and it appears in following instantiations during semantic analysis phase. not... Kenji Hara
Oct 23 2013
On Wednesday, 23 October 2013 at 08:11:59 UTC, Kenji Hara wrote:On Wednesday, 23 October 2013 at 07:22:56 UTC, simendsjo wrote:Ok. Filed a bug. Probably not a good description, but I linked to your post: http://d.puremagic.com/issues/show_bug.cgi?id=11328I've stumbled upon a strange bug, and I'm not sure what I should write in the bug report. Could someone explain what's going on here or file the bug for me? template A(alias T) { alias A = T; } void main() { struct S1 { S1* p; } static assert(is(typeof(A!(S1.init.p)) == S1*)); // ok pragma(msg, "NULL: ", typeof(A!(null))); // fail: S1* struct S2 { S2* p; } static assert(is(typeof(A!(S2.init.p)) == S2*)); // fail: S1* }A!(S1.init.p) is mostly same as A!( cast(S1*)null ), because the expression S1.init.p is interpreted to a null value. 1. But current ABI does not support "a typed null template value argument" because all of null expression on template argument are mangled to 'n'. So the type of null value will be never encoded in the mangled name, and the three instantiations A!(S1.init.p), A!(null) and A!(S2.init.p) will have exactly same mangling. 2. However, the first instantiation A!(S1.init.p) wrongly caches the null value type (== S1*), and it appears in following instantiations during semantic analysis phase. not... Kenji Hara
Oct 23 2013