[Issue 23948] New: __FILE__ and __MODULE__ cannot be implicitly converted to const(char)* as default paramenter
    d-bugmail at puremagic.com 
    d-bugmail at puremagic.com
       
    Tue May 30 23:06:41 UTC 2023
    
    
  
https://issues.dlang.org/show_bug.cgi?id=23948
          Issue ID: 23948
           Summary: __FILE__ and __MODULE__ cannot be implicitly converted
                    to const(char)* as default paramenter
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: mail at ernestocastellotti.it
One expects this code to be valid:
void foo(const(char)* mod = __MODULE__)() {
}
void main() {
    foo();
}
However you get the error:
onlineapp.d(9): Error: cannot implicitly convert expression `"onlineapp.d"` of
type `string` to `const(char)*`
onlineapp.d(9): Error: template instance `foo!((__error))` incompatible
arguments for template instantiation
onlineapp.d(9): Error: none of the overloads of template `onlineapp.foo` are
callable using argument types `!()()`
onlineapp.d(3):        Candidate is: `foo(const(char)* mod = __FILE__)
While if you do the same with __FUNCTION__ the code compiles:
void foo(const(char)* fun = __FUNCTION__)() {
}
void main() {
    foo();
}
--
    
    
More information about the Digitalmars-d-bugs
mailing list