August 31, 2020 [Issue 21211] New: `__FILE__.ptr` as default argument gives wrong value | ||||
---|---|---|---|---|
| ||||
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@puremagic.com Reporter: pro.mathias.lang@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++)`... -- |
Copyright © 1999-2021 by the D Language Foundation