[Issue 15529] New: opEquals(string) conflicts with opEquals(const(char)*)
    via Digitalmars-d-bugs 
    digitalmars-d-bugs at puremagic.com
       
    Fri Jan  8 03:54:34 PST 2016
    
    
  
https://issues.dlang.org/show_bug.cgi?id=15529
          Issue ID: 15529
           Summary: opEquals(string) conflicts with opEquals(const(char)*)
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: code at benjamin-thaut.de
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)*.
--
    
    
More information about the Digitalmars-d-bugs
mailing list