dmd 2.093.1: duplicate method definitions ignored altogether

kdevel kdevel at vogtner.de
Tue Jan 5 04:19:44 UTC 2021


On Tuesday, 5 January 2021 at 03:36:47 UTC, Paul Backus wrote:
> On Tuesday, 5 January 2021 at 02:02:39 UTC, kdevel wrote:

[...]

> If you try to call .toString directly on a const(S), you get 
> the following error:
>
> onlineapp.d(27): Error: onlineapp.S.toString called with 
> argument types () const matches both:
> onlineapp.d(9):     onlineapp.S.toString() const
> and:
> onlineapp.d(13):     onlineapp.S.toString() const

Sure, but that's too late. IMHO the compiler should detect 
duplicate
definitions (probably concealing a program error) regardless 
whether
the method is called. There is a difference between calls which 
match
two or more functions and duplicate definitions. Isn't it?

Other compilers for other languages complain loud and clear:

```ddcpp.cc
template<typename T>
struct X {
    int foo ()
    {
       return 0;
    }
    int foo ()
    {
       return 0;
    }
};
```

result from clang++:

ddcpp.cc:7:8: error: class member cannot be redeclared
    int foo ()
        ^
ddcpp.cc:3:8: note: previous declaration is here
    int foo ()
        ^
ddcpp.cc:7:8: error: redefinition of 'foo'
    int foo ()
        ^
ddcpp.cc:3:8: note: previous definition is here
    int foo ()
        ^
2 errors generated.



More information about the Digitalmars-d-learn mailing list