www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 18875] New: String literals can't disambiguate between


          Issue ID: 18875
           Summary: String literals can't disambiguate between
                    const(char)[] and const(char)* overload.
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: phobos
          Assignee: nobody puremagic.com
          Reporter: dmitry.olsh gmail.com

void add(const(char)* path){ }

void add(const(char)[] path){ }

void main(){

On DMD 2.080 prints:

bug.d(6): Error: bug.add called with argument types (string) matches both:
bug.d(1):     bug.add(const(char)* path)
bug.d(3):     bug.add(const(char)[] path)

I believe that for string literals we should probably pick D version of
const(char)[]. Some might argue the other way around since it's likely a
C-string function so it will be more efficient to present it as C-string.

Truth be told we need a sentinel terminated string type in DRuntime and cstring
would be one of them.

At the very least there has to be something in the spec about this.

May 19 2018