Bug 7919 – Sample code works on GDC but fails with DMD
Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-04-15T11:45:00Z
Last change time
2012-05-12T10:34:34Z
Keywords
pull, rejects-valid
Assigned to
nobody
Creator
russel
Comments
Comment #0 by russel — 2012-04-15T11:45:57Z
The code:
import std.algorithm ;
import std.range ;
import std.stdio ;
import core.thread ;
int main ( immutable string[] args ) {
auto threads = array ( map ! ( ( int a ) {
void delegate ( ) f ( ) {
return delegate ( ) { writeln ( a ) ; } ;
}
return new Thread ( f ) ;
} ) ( iota ( 10 ) ) ) ;
foreach ( t ; threads ) { t.start ( ) ; }
foreach ( t ; threads ) { t.join ( ) ; }
return 0 ;
}
compiles and runs as expected when using GDC on Linux:
Using built-in specs.
COLLECT_GCC=gdc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/4.6/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Debian 4.6.3-1' --with-bugurl=file:///usr/share/doc/gdc-4.6/README.Bugs --enable-languages=c,c++,d --prefix=/usr --program-suffix=-4.6 --enable-shared --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.6 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-time=yes --enable-gnu-unique-object --disable-libmudflap --enable-plugin --disable-multilib --with-arch-32=i586 --with-tune=generic --disable-libquadmath --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.6.3 (Debian 4.6.3-1)
However when using DMD 2.059, the compilation fails with the error:
/home/users/russel/lib.Linux.x86_64/DMD2/bin64/../../src/phobos/std/traits.d(1482): Error: void does not have a default initializer
/home/users/russel/lib.Linux.x86_64/DMD2/bin64/../../src/phobos/std/traits.d(1493): Error: template instance std.traits.hasIndirections!(Thread).Impl!(void[168LU]) error instantiating
/home/users/russel/lib.Linux.x86_64/DMD2/bin64/../../src/phobos/std/array.d(143): instantiated from here: hasIndirections!(Thread)
/home/users/russel/lib.Linux.x86_64/DMD2/bin64/../../src/phobos/std/array.d(143): Error: template instance std.traits.hasIndirections!(Thread) error instantiating
/home/users/russel/lib.Linux.x86_64/DMD2/bin64/../../src/phobos/std/array.d(243): Error: template instance std.array.blockAttribute!(Thread) error instantiating
/home/users/russel/lib.Linux.x86_64/DMD2/bin64/../../src/phobos/std/array.d(194): instantiated from here: arrayAllocImpl!(false,Thread[],uint)
/home/users/russel/lib.Linux.x86_64/DMD2/bin64/../../src/phobos/std/array.d(42): instantiated from here: uninitializedArray!(Thread[],uint)
initializingWithAMap.d(9): instantiated from here: array!(Result)
/home/users/russel/lib.Linux.x86_64/DMD2/bin64/../../src/phobos/std/array.d(194): Error: template instance std.array.arrayAllocImpl!(false,Thread[],uint) error instantiating
/home/users/russel/lib.Linux.x86_64/DMD2/bin64/../../src/phobos/std/array.d(42): instantiated from here: uninitializedArray!(Thread[],uint)
initializingWithAMap.d(9): instantiated from here: array!(Result)
/home/users/russel/lib.Linux.x86_64/DMD2/bin64/../../src/phobos/std/array.d(42): Error: template instance std.array.uninitializedArray!(Thread[],uint) error instantiating
initializingWithAMap.d(9): instantiated from here: array!(Result)
initializingWithAMap.d(9): Error: template instance std.array.array!(Result) error instantiating
Comment #1 by ibuclaw — 2012-04-15T11:50:49Z
I am just going to point out that gdc is on 2.057 release. And my best assumption would be this would be a library bug, not a compiler.
Comment #2 by k.hara.pg — 2012-04-15T17:53:07Z
There are related two issues.
1. The implementation of core.thread.Thread class was hidden by adding hand-made di file in 2.059. It hides actual class members with 'void[N] data'.
2. std.traits.hasIndirections doesn't define its behavior against void[N] type.
I think hasIndirections template should return true for void static array types, because void data *may* have some indirections - it's conservative way. But I'm not sure.
(In reply to comment #1)
> I am just going to point out that gdc is on 2.057 release. And my best
> assumption would be this would be a library bug, not a compiler.
Yes, this is druntime or Phobos issue, not compiler's.
I'll change 'Component' from dmd to Phobos.
Comment #3 by russel — 2012-04-16T03:18:09Z
Just to add a bit more data: the code works as anticipated with DMD 2.058.