[Issue 21211] New: `__FILE__.ptr` as default argument gives wrong value
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Mon Aug 31 00:58:36 UTC 2020
https://issues.dlang.org/show_bug.cgi?id=21211
Issue ID: 21211
Summary: `__FILE__.ptr` as default argument gives wrong value
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Severity: normal
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: pro.mathias.lang at gmail.com
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++)`...
--
More information about the Digitalmars-d-bugs
mailing list