[Issue 14210] invalid merging of template instances

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Fri Feb 20 18:22:53 PST 2015


https://issues.dlang.org/show_bug.cgi?id=14210

--- Comment #2 from Kenji Hara <k.hara.pg at gmail.com> ---
(In reply to Ketmar Dark from comment #0)
> compiler erroneously merges templates with different delegate types. let's
> run the following code:
> 
[snip]
>
> both results are obviously wrong, 'cause compiler should not merge two
> instantiations. yet compiler checks for merge possibility by checking
> mangled names, and both types mangles to the same string.
> 
> this breaks automatic CTFE wrapping of functions for some scripting engines,
> and possibly many more cases.

In D, default arguments of a function pointer/delegate type is not a part of
type.
I's mostly fixed in the PR:
https://github.com/D-Programming-Language/dmd/pull/1102

In a nutshell, instantiated templates cannot take a type with default
arguments. They should be stripped off in the instantiation.

In the OP code, the two 'test' function template call should instantiate only
one function with DT = int function(int) pure nothrow @nogc @safe.

--


More information about the Digitalmars-d-bugs mailing list