Bug 21211 – `__FILE__.ptr` as default argument gives wrong value
Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2020-08-31T00:58:36Z
Last change time
2021-02-05T16:46:34Z
Assigned to
No Owner
Creator
Mathias LANG
Comments
Comment #0 by pro.mathias.lang — 2020-08-31T00:58:36Z
Using `__FILE__.ptr` will get const-folded, meaning it will always be the caller's site showing up:
```
// a.d
import b;
void main ()
{
foo();
}
```
```
// b.d
import core.stdc.stdio;
void foo(const(char)* file = __FILE__.ptr)
{
printf("Called from %s\n", file);
}
```
Using the latest DMD (v2.093.1):
```
$ dmd -i -run a.d
Called from b.d
```
But why would one ever use `__FILE__.ptr`, might you ask ? Just use `__FILE__` !
Well I would, but in my original code, `foo` is `extern(C++)`...
Comment #1 by pro.mathias.lang — 2020-08-31T01:09:10Z
Side note: `__FUNCTION__` and `__PRETTY_FUNCTION__` work correctly.
Comment #2 by dkorpel — 2021-02-05T16:46:34Z
*** This issue has been marked as a duplicate of issue 18919 ***