dmd 2.093.1: duplicate method definitions ignored altogether

kdevel kdevel at vogtner.de
Tue Jan 5 02:02:39 UTC 2021


~~~tsnf.d
import std.stdio: writeln;

struct S {
    string s;
    string toString ()
    {
       return __PRETTY_FUNCTION__ ~ `: ` ~ s;
    }
    string toString () const // def #1
    {
       return __PRETTY_FUNCTION__ ~ `: ` ~ s;
    }
    const string toString () // def #2
    {
       return __PRETTY_FUNCTION__ ~ `: ` ~ s;
    }
}

void foo (T) (in ref T t) // fancy way of declaring t const
{
    writeln (t);
}

int main ()
{
    S s;
    writeln (s);
    foo (s);
    return 0;
}
~~~

$ dmd tsnf
$ ./tsnf
string tsnf.S.toString():
const(S)("")

expected output: none. The compiler should have rejected the code 
after the duplicate definition def #2. dmd 2.093.1 ignores both 
definitions instead. Is this a bug or a bug?


More information about the Digitalmars-d-learn mailing list