Comment #0 by witold.baryluk+d — 2009-04-03T08:35:45Z
cclass A {
int m() {
return 1;
}
float m() {
return 2.0;
}
}
class B {
int m() {
return 1;
}
int m() {
return 2;
}
}
void main() {
auto a = new A();
assert(a.m() == 1);
auto b = new B();
assert(b.m() == 1);
}
/+
dmd -c bugcopy.d
bugcopy.d(23): function bugcopy.A.m called with argument types:
()
matches both:
bugcopy.A.m()
and:
bugcopy.A.m()
bugcopy.d(25): function bugcopy.B.m called with argument types:
()
matches both:
bugcopy.B.m()
and:
bugcopy.B.m()
Exit 1
+/
Without main this program compiles without any warning or error. This connected with for example overloding over aliases/or const can lead to problems.
class B {
int m(S[] c) {
return 1;
}
int m(invariant(S)[] c) {
return 2;
}
}
If S is already invariant, then this code is erratic, but compiler will not report it to user.
Comment #1 by smjg — 2009-04-15T11:08:07Z
This was a bug in the D1 line ages ago - it seems for some reason the fix wasn't applied to the D2 line. BTW no classes are needed to show the bug - it happens with global functions just as well.
Comment #2 by witold.baryluk+d — 2010-01-31T09:04:23Z
(In reply to comment #1)
> This was a bug in the D1 line ages ago - it seems for some reason the fix
> wasn't applied to the D2 line. BTW no classes are needed to show the bug - it
> happens with global functions just as well.
Hmm. You are right, global functions also have this problem. The problem is that if you don't use this functions, and they have different return types, even linker will not give you any error.
Comment #3 by yebblies — 2012-01-29T07:25:12Z
The check for D2 was disabled because it didn't play nice with const, according to comments in FuncDeclaration::overloadInsert.
This bug report may be related or a duplicate
https://issues.dlang.org/show_bug.cgi?id=13283
The problem persists in dmd v2.067.1
It is particularly nasty since even the linker won't catch it in some cases.
For example:
main_lib.d
---------------------------
module main_lib;
import std.stdio;
alias t_TaskFunction = void function();
// duplicate overloads that should not compile
void Task(){
writeln("A");
}
void Task(){
writeln("B");
}
main.d
---------------------------
import main_lib;
int main()
{
t_TaskFunction TaskFunction = &Task; // ???
TaskFunction();
return 0;
}
$dmd main_lib.d -lib -O -oflibmain_lib.a
$dmd main2.d -O -L-L./ -L-lmain_lib -ofmain
$./main
Output is "A" on my system.
Comment #16 by greensunny12 — 2018-02-08T00:03:53Z
Comment #18 by witold.baryluk+d — 2020-05-15T16:26:07Z
Interesting, gdc 9.2 does report duplicate:
<source>:16:6: error: example.B.m at <source>:16:6 conflicts with example.B.m at <source>:12:6
16 | int m() {
The issue is still present in dmd nightly, dmd 2.089, ldc 1.20, ldc trunk.
Link with an example: https://godbolt.org/z/xE6fK7
Comment #19 by ibuclaw — 2020-08-03T10:24:11Z
(In reply to Witold Baryluk from comment #18)
> Interesting, gdc 9.2 does report duplicate:
>
> <source>:16:6: error: example.B.m at <source>:16:6 conflicts with
> example.B.m at <source>:12:6
>
> 16 | int m() {
>
>
>
> The issue is still present in dmd nightly, dmd 2.089, ldc 1.20, ldc trunk.
>
> Link with an example: https://godbolt.org/z/xE6fK7
This is checked in the codegen pass. Would be better if the front-end did it for us.
Comment #20 by witold.baryluk+d — 2023-10-26T00:06:03Z
This appears to have been fixed at some point, as I cannot reproduce it anymore:
$ dmd t.d
t.d(6): Error: function `t.A.m()` conflicts with previous declaration at t.d(2)
t.d(16): Error: function `t.B.m()` conflicts with previous declaration at t.d(12)
$ ldc t.d
ldc2 ldc-build-runtime ldc-profdata ldc-prune-cache
$ ldc2 t.d
t.d(6): Error: function `t.A.m()` conflicts with previous declaration at t.d(2)
t.d(16): Error: function `t.B.m()` conflicts with previous declaration at t.d(12)
$ gdc t.d
t.d:6:11: error: function ‘t.A.m()’ conflicts with previous declaration at t.d:2:9
6 | float m() {
| ^
t.d:16:9: error: function ‘t.B.m()’ conflicts with previous declaration at t.d:12:9
16 | int m() {
| ^
Same with global functions.
DMD64 D Compiler v2.105.2
LDC - the LLVM D compiler (1.30.0):
based on DMD v2.100.1 and LLVM 14.0.6
gdc (Debian 13.2.0-5) 13.2.0
Comment #21 by witold.baryluk+d — 2023-10-26T00:15:58Z