Bug 1404 – Link failure with template mixin and function literal
Status
RESOLVED
Resolution
WORKSFORME
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
x86
OS
Linux
Creation time
2007-08-07T18:51:39Z
Last change time
2017-10-25T02:49:52Z
Keywords
link-failure
Assigned to
No Owner
Creator
Stéphan Kochen
Comments
Comment #0 by stephan — 2007-08-07T18:51:39Z
When passing a function literal to a template such as:
template Foo(alias condition)
{
bool invert()
{
return !condition();
}
}
.. the linker will fail if that template is mixed into a class. For example:
class Bar
{
mixin Foo!(function { return false; });
}
int main(char[][] args)
{
auto baz = new Bar();
if (baz.invert())
return 0;
else
return 1;
}
Compiling this results in the following error:
$ dmd invertfail.d
gcc invertfail.o -o invertfail -m32 -Xlinker -L/usr/local/bin/../lib -lphobos -lpthread -lm
invertfail.o:(.rodata+0x2c): undefined reference to `_D10invertfail3Bar14__funcliteral1MFZb'
collect2: ld gaf exit-status 1 terug
--- errorlevel 1
However, the test case compiles and runs properly when instead the template is mixed directly into the main procedure. So this is specific the mixing into a class.
Comment #1 by Marco.Leise — 2014-01-18T17:42:38Z
I have a similar case to add. Not sure if it is exactly the same bug, but I guess so. Somehow function literals disappear from the output when they are passed as an alias into a mixin template.
template Impl(string entryPoint, alias wrapper)
{
mixin(`alias ` ~ entryPoint ~ `Checked = wrapper;`);
}
template OpenAL11()
{
mixin Impl!("alGetProcAddress", () {});
}
void main()
{
OpenAL11!().alGetProcAddressChecked();
}
Comment #2 by Marco.Leise — 2014-01-18T17:43:25Z
*** Issue 2220 has been marked as a duplicate of this issue. ***
Comment #3 by Marco.Leise — 2014-01-18T17:44:57Z
The test case from Issue 2220:
// ---
template Foo(alias f) {
void foo() {
f();
}
}
class Bar {
mixin Foo!( function { } );
}
void main() {}
// ---
dmd issue211.d && issue211
OPTLINK (R) for Win32 Release 8.00.1
Copyright (C) Digital Mars 1989-2004 All rights reserved.
issue211.obj(issue211)
Error 42: Symbol Undefined _D8issue2113Bar14__funcliteral1MFZv