Thread overview
Undescriptive linker error. (bug?)
Apr 05, 2019
Sjoerd Nijboer
Apr 05, 2019
Adam D. Ruppe
Apr 05, 2019
Sjoerd Nijboer
April 05, 2019
module mymodule;

class Foo{}

Foo Bar()
{
	Foo foo();
	
	return foo;
}

int main()
{
	auto foo = Bar();

    return 0;
}

This code doesn't compile with a linker error that there's a missing symbol for `Foo Bar()` on windows.
After all, `Foo foo();` isn't legitimate D.
But why does it return a linker error?
shouldn't it give an error that is more descriptive about a class instance being wrong?
I feel like this would be a common thing people try to write.
Especially in templates this would become difficult to narrow down.
April 05, 2019
On Friday, 5 April 2019 at 21:59:35 UTC, Sjoerd Nijboer wrote:
> Foo Bar()
> {
> 	Foo foo();

It looks like the compiler is treating that as a function prototype without a body (that just happens to be nested in another function).

> 	return foo;

And then, this foo is given the optional parens treatment, as if it was a call to foo() of the given function, which is why the linker complains.

Weird combination of cases that maybe should be illegal.

April 05, 2019
On Friday, 5 April 2019 at 22:08:50 UTC, Adam D. Ruppe wrote:
> Weird combination of cases that maybe should be illegal.

It errors with the highly descriptive errormessage:

app.obj(app)
 Error 42: Symbol Undefined __D8mymodule3BarFZ3fooMFZCQx3Foo
Error: linker exited with status 1