www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 21211] New: `__FILE__.ptr` as default argument gives wrong


          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 ()

// 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++)`...

Aug 30 2020