Bug 10573 – Weird linking problem with associative array cast [DMD 2.63]
Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2013-07-08T07:08:00Z
Last change time
2013-09-06T22:56:48Z
Keywords
link-failure, pull
Assigned to
nobody
Creator
kozzi11
Comments
Comment #0 by kozzi11 — 2013-07-08T07:08:43Z
With new DMD I have some issue when linking:
obj/Debug/TestD.o: In function `_D6object40__T16AssociativeArrayTiTC7handler5mysqlZ16AssociativeArray6rehashMFNdZHiC7handler5mysql':
/usr/include/d/druntime/import/object.di:484: undefined reference to `_D26TypeInfo_HiC7handler5mysql6__initZ'
With LDMD2 and DMD 2.62 everything seems ok.
Problematic code:
//---- main.d ----//
module main;
import handler;
void main(string[] args) {}
//---- handler.d ----//
module handler;
abstract class base {}
class mysql : base {}
class handler {
private mysql[int] mysql_servers;
public void foo() {
base[int] hServers = cast(base[int])mysql_servers;
}
}
Comment #1 by andrej.mitrovich — 2013-07-08T13:21:36Z
I can recreate this on win32 but only with the -g flag.
Comment #2 by andrej.mitrovich — 2013-07-08T13:56:38Z
Btw, I'd be very careful using casts on hashes like that, there's no runtime checking when you cast hashes, even if the key or value is a base class which is casted to a derived class. For example:
-----
class A { }
class B : A { void call() { } }
void main()
{
A[int] a;
a[1] = new A();
B[int] b = cast(B[int])a; // unsafe, no exceptions thrown
b[1].call(); // crash
}
-----
Comment #3 by kozzi11 — 2013-07-08T23:20:16Z
(In reply to comment #2)
> Btw, I'd be very careful using casts on hashes like that, there's no runtime
> checking when you cast hashes, even if the key or value is a base class which
> is casted to a derived class. For example:
>
> -----
> class A { }
> class B : A { void call() { } }
>
> void main()
> {
> A[int] a;
> a[1] = new A();
>
> B[int] b = cast(B[int])a; // unsafe, no exceptions thrown
> b[1].call(); // crash
> }
> -----
Yes, I realize I can avoid this kind of cast in my case, so now the code is more safe and compilable.