__FILE__

Mathias LANG geod24 at gmail.com
Thu Aug 5 03:14:33 UTC 2021


On Monday, 26 July 2021 at 11:43:56 UTC, workman wrote:
> file test.d:
>
>     -------------
>     module test;
>     import abc;
>     void doTest(){
>     	log!"test"();
>     }
>     -----------
>
>     file abc.d:
>     -------------
>     module abc;
>     import test;
>     void log(string fmt, int line = __LINE__, string path = 
> __FILE__[0..$], A...)(A a) {
>     	import core.stdc.stdio;
>     	printf("[%s:%d] \n", path.ptr, line);
>     }
>     extern(C) int main() {
>     	doTest();
>     	return 0;
>     }
>
> -------------
>
> retult: [abc.d:4]
>
> expect: [test.d:4]

It's a known bug: https://issues.dlang.org/show_bug.cgi?id=18919
If you remove the slicing from `__FILE__`, it'll work as expected.


More information about the Digitalmars-d-learn mailing list