Bug 5821 – Calling spawn in std.concurrency without all the parameters required by void function(T) fn
Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Linux
Creation time
2011-04-08T13:33:00Z
Last change time
2011-06-04T22:52:55Z
Assigned to
nobody
Creator
jsancio
Comments
Comment #0 by jsancio — 2011-04-08T13:33:50Z
I am not sure if this a language, compiler, or library issue but when you call spawn without passing all the parameters required by the fn it can either segfault if you are lucky or worst yet have an unpredictable behavior.
For example the following code will compile and execute:
import std.concurrency;
void main()
{
spawn(&fun);
}
void fun(int i) {}
My intuition is that the code above should not compile.
Comment #1 by andrden — 2011-04-12T08:55:29Z
Seems more like it's language:
arg: 100
arg: 134851556 (any number actually)
is printed by the following which should not compile:
import std.stdio;
void func(int value){
writeln("arg: ",value);
}
void myspawn(T...)( void function(T) fn, T args ){
fn(args);
}
void main(){
myspawn(&func,100);
myspawn(&func);
}
Comment #2 by yebblies — 2011-06-04T22:52:55Z
With only the function pointer as an argument, spawn becomes:
void spawn(void function() fn)
and &fun is (incorrectly) implicitly converted to void function() fn.
*** This issue has been marked as a duplicate of issue 3797 ***