__FILE__ and __LINE__ in case of import expression
Andrey Zherikov
andrey.zherikov at gmail.com
Sun Aug 23 12:50:36 UTC 2020
On Friday, 21 August 2020 at 22:34:49 UTC, Adam D. Ruppe wrote:
> On Friday, 21 August 2020 at 22:12:48 UTC, Steven Schveighoffer
> wrote:
>> Who does that though?
>
> An incompetent coder:
>
> http://dpldocs.info/experimental-docs/source/arsd.cgi.d.html#L5713
> http://dpldocs.info/experimental-docs/source/arsd.cgi.d.html#L5943
> http://dpldocs.info/experimental-docs/source/arsd.cgi.d.html#L6018
> http://dpldocs.info/experimental-docs/source/arsd.cgi.d.html#L6058
Even this approach can lead to unclear result if you move
'q{...}' outside of mixin:
=========================
void test(string file = __FILE__, size_t line = __LINE__)
{
writefln("file: '%s', line: '%s'", file, line);
}
int main(string[] args)
{
enum code = q{
// empty line 15
// empty line 16
// empty line 17
// empty line 18
// empty line 19
test(); // line 20
};
test(); // line 23
mixin(code); // line 24
test(); // line 25
return 0; // line 26
} // line 27
===========================
The output is the following:
file: 'test.d', line: '23'
file: 'test.d-mixin-24', line: '30'
file: 'test.d', line: '25'
Note that there is no line 30!
More information about the Digitalmars-d-learn
mailing list