Bug 18875 – String literals can't disambiguate between const(char)[] and const(char)* overload.

Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2018-05-19T15:35:23Z
Last change time
2023-07-14T12:33:46Z
Assigned to
No Owner
Creator
Dmitry Olshansky

Comments

Comment #0 by dmitry.olsh — 2018-05-19T15:35:23Z
void add(const(char)* path){ } void add(const(char)[] path){ } void main(){ add("ABC"); } 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) and: 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.
Comment #1 by nick — 2023-07-14T12:33:46Z
> At the very least there has to be something in the spec about this. See: https://issues.dlang.org/show_bug.cgi?id=11900#c8 *** This issue has been marked as a duplicate of issue 11900 ***