Re: string file = __FILE__ considered harmful (and solution)

2018-06-01 Thread Walter Bright via Digitalmars-d
On 6/1/2018 12:30 AM, Mike Franklin wrote: I already have a pending PR at https://github.com/dlang/dmd/pull/8310 which I can modify to fix for both __LINE__ and __FILE_ if I can get clarification on how it *should* work. I followed up there. Thanks for taking care of this!

Re: string file = __FILE__ considered harmful (and solution)

2018-06-01 Thread Mike Franklin via Digitalmars-d
On Friday, 1 June 2018 at 03:14:11 UTC, Walter Bright wrote: On 5/30/2018 2:45 PM, John Colvin wrote: https://run.dlang.io/is/oMe7KQ Less elegant, but solves the problem of accidental argument adding (CallerFile acts as a barrier). Unfortunately, while it works in theory, in practice the

Re: string file = __FILE__ considered harmful (and solution)

2018-05-31 Thread Walter Bright via Digitalmars-d
On 5/30/2018 1:27 AM, 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__); What's wrong

Re: string file = __FILE__ considered harmful (and solution)

2018-05-31 Thread Walter Bright via Digitalmars-d
On 5/30/2018 2:45 PM, John Colvin wrote: https://run.dlang.io/is/oMe7KQ Less elegant, but solves the problem of accidental argument adding (CallerFile acts as a barrier). Unfortunately, while it works in theory, in practice the compiler crashes LOL Please post bug reports when you find

Re: string file = __FILE__ considered harmful (and solution)

2018-05-31 Thread Steven Schveighoffer via Digitalmars-d
On 5/31/18 7:14 AM, bauss wrote: Instead of these hack keywords. Perhaps a __traits() in the compiler with the information would be better suited like: void foo() {     enum caller = __traits(getCaller);     } getCaller would return a compile-time struct with additional information

Re: string file = __FILE__ considered harmful (and solution)

2018-05-31 Thread bauss via Digitalmars-d
On Wednesday, 30 May 2018 at 14:40:50 UTC, Steven Schveighoffer wrote: On 5/30/18 4:27 AM, 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:

Re: string file = __FILE__ considered harmful (and solution)

2018-05-30 Thread John Colvin via Digitalmars-d
On Wednesday, 30 May 2018 at 14:40:50 UTC, Steven Schveighoffer wrote: On 5/30/18 4:27 AM, 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:

Re: string file = __FILE__ considered harmful (and solution)

2018-05-30 Thread Nick Sabalausky (Abscissa) via Digitalmars-d
On 05/30/2018 10:40 AM, Steven Schveighoffer wrote: But if we fixed the behavior that causes your idea not to work, then we could probably easily define a function like so: CallerInfo __CALLER__(string file = __FILE__, size_t line = __LINE__) {     return CallerInfo(file, line); } Love

Re: string file = __FILE__ considered harmful (and solution)

2018-05-30 Thread Steven Schveighoffer via Digitalmars-d
On 5/30/18 10:40 AM, Steven Schveighoffer wrote: But if we fixed the behavior that causes your idea not to work, then we could probably easily define a function like so: CallerInfo __CALLER__(string file = __FILE__, size_t line = __LINE__) {     return CallerInfo(file, line); } Filed an

Re: string file = __FILE__ considered harmful (and solution)

2018-05-30 Thread Steven Schveighoffer via Digitalmars-d
On 5/30/18 4:27 AM, 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__); What's wrong

Re: string file = __FILE__ considered harmful (and solution)

2018-05-30 Thread FeepingCreature via Digitalmars-d
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

Re: string file = __FILE__ considered harmful (and solution)

2018-05-30 Thread bauss via Digitalmars-d
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

Re: string file = __FILE__ considered harmful (and solution)

2018-05-30 Thread FeepingCreature via Digitalmars-d
Shit it doesn't work, I only checked if it compiled; it gives the wrong file/line number. NEVERMIND ALL

Re: string file = __FILE__ considered harmful (and solution)

2018-05-30 Thread rikki cattermole via Digitalmars-d
On 30/05/2018 8:27 PM, 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__); What's

string file = __FILE__ considered harmful (and solution)

2018-05-30 Thread FeepingCreature via Digitalmars-d
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__); What's wrong with this? Say you add a string parameter,