Function pointers/delegates default args were stealth removed?

Manu turkeyman at gmail.com
Mon Aug 27 06:44:32 PDT 2012


On 27 August 2012 15:48, Robert Clipsham <robert at octarineparrot.com> wrote:

> I seem to recall I looked at this issue myself at one point. It goes
> something like:
> ----
>
> auto foo = (int a = 1) { return a; };
> auto bar = (int a) { return a; };
> ----
> int function(int) is mangled exactly the same as int function(int = 1) as
> default args aren't used for mangling. dmd does semantic analysis on the
> type of foo, which returns int function(int = 1), which is mangled as int
> function(int) and stored in dmd's hashmap of types (default args aren't
> mangled). When the semantic analysis of bar is done it checks the hashmap,
> sees that the type is already there (has the same name mangling) and does
> not repeat semantic analysis. If you switch the order of declarations then
> the opposite happens - the default arg is ignored.
>

Cached in a hashmap! precisely what I suspected (without knowing anything
about it) ;)
That explains why Walter keeps going on about the name mangling. It's all
clear.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20120827/63c4144c/attachment.html>


More information about the Digitalmars-d mailing list