ADL

Timon Gehr via Digitalmars-d digitalmars-d at puremagic.com
Sun Sep 4 14:36:42 PDT 2016


On 04.09.2016 22:22, Walter Bright wrote:
> On 9/4/2016 5:30 AM, Andrei Alexandrescu wrote:
>> Might be a sensible enhancement. Removing artificial limitations is good
>> programming language design. Turtles! -- Andrei
>
> The design of executable function bodies is very much "declare before
> use", quite unlike at the declaration levels which is all "order is not
> relevant". Changing this will have consequences (such as our discussion
> of exactly when a declaration becomes valid),

The rule should be the same as for module-level functions. Note that the 
rules for module-level functions are currently inadequate:

pragma(msg, foo(0)); // calls double overload
static if(foo(0)){ // calls double overload
     bool foo(int x){ return false; }
}
bool foo(double x){ return true; }
pragma(msg, foo(0)); // calls int overload

Declare-call ordering issues for overload sets are not limited to local 
scopes. This problem needs to be solved anyway. The fact that the scope 
is local adds exactly zero additional complications.

> and I just feel that
> function code is just easier to understand if "declare before use" is
> the rule,

Overloading does not violate declare before use. You seem to be 
conflating it with forward referencing.

> because that is how we reason about how it is executed.
>
> Besides, I showed a method of how the overloads could be done with the
> existing language.

That's not the point. What's perhaps more telling is that you initially 
got it wrong. It /wants/ to be valid code.


More information about the Digitalmars-d mailing list