What to do about default function arguments

Timon Gehr timon.gehr at gmx.ch
Thu Apr 26 03:11:55 PDT 2012


On 04/26/2012 11:46 AM, Don Clugston wrote:
> On 26/04/12 11:28, Timon Gehr wrote:
>> On 04/26/2012 10:51 AM, Don Clugston wrote:
>>> On 26/04/12 05:44, 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, which leads to the nasty behavior in the bug
>>>> report.
>>>>
>>>> The problem centers around name mangling. If two types mangle the same,
>>>> then they are the same type. But default arguments are not part of the
>>>> mangled string. Hence the schizophrenic behavior.
>>>>
>>>> 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 it is a mistake to allow default arguments in function pointers
>>> and delegates (it's OK for delegate literals, there you have the
>>> declaration).
>>
>> The parenthesised part is in conflict with your other statement.
>
> No it doesn't. A default argument is a delegate literal is part of the
> declaration, not part of the type.

If types cannot specify default arguments, then those will be thrown 
away right away, because what is later called is based on the type of 
the delegate and not on the implicit function declaration that has its 
address taken. What is the point of allowing it if it cannot be used?


More information about the Digitalmars-d mailing list