Bug 15529 – opEquals(string) conflicts with opEquals(const(char)*)

Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2016-01-08T11:54:34Z
Last change time
2018-02-01T07:10:34Z
Keywords
rejects-valid
Assigned to
No Owner
Creator
Benjamin Thaut

Comments

Comment #0 by code — 2016-01-08T11:54:34Z
The following piece of code fails to compile in dmd 2.069.1 import core.stdc.string; struct StringWrapper { string str; bool opEquals(string str) const { return this.str == str; } bool opEquals(const(char)* cStr) const { return this.str == cStr[0..strlen(cStr)]; } } void main(string[] args) { auto w = StringWrapper("test"); assert(w == "test"); assert(w == "test\0".ptr); } The error is: /d233/f675.d(22): Error: overloads const bool(string str) and const bool(const(char)* cStr) both match argument list for opEquals /d233/f675.d(22): Error: f675.StringWrapper.opEquals called with argument types (string) matches both: /d233/f675.d(7): f675.StringWrapper.opEquals(string str) and: /d233/f675.d(12): f675.StringWrapper.opEquals(const(char)* cStr) I assume this is due to the implicit conversion of a string literal into const(char)*.
Comment #1 by simen.kjaras — 2018-02-01T07:10:34Z
*** This issue has been marked as a duplicate of issue 11900 ***