Bug 2210 – Error: void initializer has no value

Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
x86
OS
Linux
Creation time
2008-07-09T10:41:00Z
Last change time
2014-03-01T00:36:11Z
Assigned to
bugzilla
Creator
moritzwarning

Comments

Comment #0 by moritzwarning — 2008-07-09T10:41:24Z
template isStaticArrayTypeInst( T ) { const T isStaticArrayTypeInst = void; } Compile error: Error: void initializer has no value
Comment #1 by 2korden — 2008-07-09T11:10:42Z
Please, do not hurry in posting your bug report! The piece of code itself doesn't have any issues. I think the issue you are talking about is this: template instance(T) { const T instance = void; } void main() { int i = instance!(char[]).length; // works at runtime const int i = instance!(char[]).length; // doesn't work at compile time } I can not judge whether it is a correct behavior or not. It just worked before but doesn't anymore.
Comment #2 by moritzwarning — 2008-07-09T11:26:47Z
Right, I was in a hurry. Sorry for that. Anyway, it looks like it's no dmd bug, since the length property would be undefined at runtime. The same should apply at compile time.
Comment #3 by 2korden — 2008-07-09T11:34:51Z
I'm sorry, I didn't investigate problem deep enough. Issue is completely different. Let's start with a bachground, first. The following template is used to work prior to DMD1.032 release: private template isStaticArrayTypeInst( T ) { const T isStaticArrayTypeInst = void; } /** * Evaluates to true if T is a static array type. */ template isStaticArrayType( T ) { static if( is( typeof(T.length) ) && !is( typeof(T) == typeof(T.init) ) ) { const bool isStaticArrayType = is( T == typeof(T[0])[isStaticArrayTypeInst!(T).length] ); } else { const bool isStaticArrayType = false; } } But now it doesn't. I reduced the test case to the following difference: template Test( T ) { const bool Test = ( is( typeof(T) == typeof(T.init) ) ); } void main() { static assert( Test!(int) ); } This asserts succeeded in DMD1.031 and fails in DMD1.032. As you see, it's a typeof(int) issue, that was discussed last days. That's it.