What to do about default function arguments

Timon Gehr timon.gehr at gmx.ch
Thu Apr 26 00:47:54 PDT 2012


On 04/26/2012 05:44 AM, Walter Bright wrote:
> A subtle but nasty problem - are default arguments part of the type, or
> part of the declaration?
>
> See http://d.puremagic.com/issues/show_bug.cgi?id=3866
>
> Currently, they are both,

That is how it should be.

> which leads to the nasty behavior in the bug report.
>

It contributes, but it is not the main cause.

> The problem centers around name mangling. If two types mangle the same,
> then they are the same type.

Then they are equal types.

> But default arguments are not part of the
> mangled string. Hence the schizophrenic behavior.
>

The schizophrenic behavior occurs because the types cross-talk. Are 
mangled names kept unique in the compiler or what is the implementation 
issue exactly?

> But if we make default arguments solely a part of the function
> declaration, then function pointers (and delegates) cannot have default
> arguments. (And maybe this isn't a bad thing?)

I think default arguments for delegates and function pointers are quite 
a feat.

The proposal is to change the language in a backwards-incompatible way 
based on implementation issues that shouldn't be that hard to resolve.

(Related: Template instantiation should strip off the default arguments 
from delegate and function pointer types.)


More information about the Digitalmars-d mailing list