Bug 6196 – with statement with single statement breaks linking
Status
RESOLVED
Resolution
WORKSFORME
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
Other
OS
Windows
Creation time
2011-06-22T11:05:00Z
Last change time
2014-12-07T14:28:22Z
Assigned to
nobody
Creator
andrej.mitrovich
Comments
Comment #0 by andrej.mitrovich — 2011-06-22T11:05:51Z
module test;
static import std.stdio;
void main()
{
with (std.stdio) writeln();
}
OPTLINK (R) for Win32 Release 8.00.12
Copyright (C) Digital Mars 1989-2010 All rights reserved.
http://www.digitalmars.com/ctg/optlink.html
C:\DOCUME~1\Andrej\LOCALS~1\Temp\.rdmd\rdmd-test.d-A365FA805A6F8950E12081529066367B\test-d-A365FA805A6F8950E12081529066367B.obj(test-d-A365FA805A6F8950E12081529066367B)
Error 42: Symbol Undefined _D3std5stdio12__T7writelnZ7writelnFZv
This will work:
module test;
static import std.stdio;
void main()
{
with (std.stdio) { writeln(); }
}
Note how in the next example the first `with` statement has curly braces and references writeln(), it gets linked in, and the linker errors are gone for the second `with` statement:
static import std.stdio;
void main()
{
with (std.stdio) { writeln(); }
with (std.stdio) writeln();
}
Comment #1 by bearophile_hugs — 2011-06-22T11:45:22Z
(In reply to comment #0)
> module test;
> static import std.stdio;
>
> void main()
> {
> with (std.stdio) writeln();
My guess is that with() was designed mostly for struct instances, class instances, and enum instances. I didn't even know you are allowed to use it with modules.
Comment #2 by lovelydear — 2012-04-24T11:34:18Z
Compiles and runs fine with 2.059 Win32.
Comment #3 by andrej.mitrovich — 2012-04-24T14:10:20Z
(In reply to comment #2)
> Compiles and runs fine with 2.059 Win32.
That's not true.
module test;
static import std.stdio;
void main()
{
with (std.stdio) writeln();
}
$ dmd test.d
> OPTLINK (R) for Win32 Release 8.00.12
Copyright (C) Digital Mars 1989-2010 All rights reserved.
http://www.digitalmars.com/ctg/optlink.html
test.obj(test)
Error 42: Symbol Undefined _D3std5stdio12__T7writelnZ7writelnFZv
--- errorlevel 1
Maybe it works on Posix, but it's not working on my win32 system.
Comment #4 by hsteoh — 2012-10-27T10:44:14Z
It doesn't work on Linux 64-bit, git HEAD:
$ dmd test
test.o: In function `_Dmain':
test.d:(.text._Dmain+0x4): undefined reference to `_D3std5stdio12__T7writelnZ7writelnFZv'
collect2: error: ld returned 1 exit status
--- errorlevel 1
Comment #5 by hsteoh — 2012-10-27T10:47:09Z
Interestingly enough, if I replace the with() clause with std.stdio.writeln() (which links without errors) and look at the resulting executable, it does define _D3std5stdio12__T7writelnZ7writelnFZv.
Which means that the template isn't getting instantiated when used with a 'with' clause, perhaps?
Comment #6 by andrej.mitrovich — 2012-10-27T10:47:27Z
The symbol is probably not referenced properly or something.
module test;
static import std.stdio;
void main()
{
std.stdio.writeln("test"); // reference symbol
with (std.stdio) writeln("test");
}
If you remove the commented line you'll get a linker error.
Comment #7 by andrej.mitrovich — 2013-02-18T09:59:11Z
*** Issue 8414 has been marked as a duplicate of this issue. ***
Comment #8 by hsteoh — 2014-12-05T18:52:06Z
Seems to have been fixed in git HEAD; could you re-test?
Comment #9 by andrej.mitrovich — 2014-12-07T14:28:22Z
(In reply to hsteoh from comment #8)
> Seems to have been fixed in git HEAD; could you re-test?
Yeah I can confirm it works now.. although I'm worried it's just a side-effect of any import changes we might have made within std.stdio, and the actual problem not being properly fixed.
We'll see if it resurfaces.