string file = __FILE__ considered harmful (and solution)

FeepingCreature feepingcreature at gmail.com
Wed May 30 12:05:55 UTC 2018


On Wednesday, 30 May 2018 at 11:59:05 UTC, bauss wrote:
> On Wednesday, 30 May 2018 at 08:27:16 UTC, FeepingCreature 
> wrote:
>> There's a very common idiom where in order to report line 
>> numbers of an error or a log line at the callsite of a 
>> function, you pass __FILE__ and __LINE__ as default parameters:
>>
>> [...]
>
> void foo(string file = __FILE__, size_t line = __LINE__)(string 
> msg);
>
> Wouldn't this solve it?

No, because a) then you're completely pointlessly making a foo 
for every line it's called in, b) you're not future compatible 
with, say, call column, and c) you get exactly the same problem 
with template value parameters, ie. foo!"some ct argument".


More information about the Digitalmars-d mailing list