Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.

Commit a20c647

Browse files
committed
core.stdcpp.{exception,typeinfo}: Fix D/C++ symbol conflicts
... and missing D vtable entries.
1 parent 5cbf268 commit a20c647

File tree

2 files changed

+46
-29
lines changed

2 files changed

+46
-29
lines changed

src/core/stdcpp/exception.d

+17-6
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,14 @@ version (GenericBaseException)
6767
class exception
6868
{
6969
@nogc:
70+
extern(D):
7071
///
7172
this() nothrow {}
7273
///
73-
~this() nothrow {} // HACK: this should extern, but then we have link errors!
74+
~this() nothrow {}
7475

7576
///
76-
const(char)* what() const nothrow { return "unknown"; } // HACK: this should extern, but then we have link errors!
77+
const(char)* what() const nothrow { return "unknown"; }
7778

7879
protected:
7980
this(const(char)*, int = 1) nothrow { this(); } // compat with MS derived classes
@@ -85,19 +86,20 @@ else version (CppRuntime_Microsoft)
8586
class exception
8687
{
8788
@nogc:
89+
extern (D):
8890
///
8991
this(const(char)* message = "unknown", int = 1) nothrow { msg = message; }
9092
///
91-
extern(D) ~this() nothrow {}
93+
~this() nothrow {}
9294

9395
///
94-
extern(D) const(char)* what() const nothrow { return msg != null ? msg : "unknown exception"; }
96+
const(char)* what() const nothrow { return msg != null ? msg : "unknown exception"; }
9597

9698
// TODO: do we want this? exceptions are classes... ref types.
9799
// final ref exception opAssign(ref const(exception) e) nothrow { msg = e.msg; return this; }
98100

99101
protected:
100-
void _Doraise() const {}
102+
void _Doraise() const { assert(0); }
101103

102104
protected:
103105
const(char)* msg;
@@ -111,6 +113,15 @@ else
111113
class bad_exception : exception
112114
{
113115
@nogc:
116+
extern(D):
117+
private static immutable msg = "bad exception";
118+
114119
///
115-
this(const(char)* message = "bad exception") { super(message); }
120+
this(const(char)* message = msg.ptr) nothrow { super(message); }
121+
122+
version (GenericBaseException)
123+
{
124+
///
125+
override const(char)* what() const nothrow { return msg.ptr; }
126+
}
116127
}

src/core/stdcpp/typeinfo.d

+29-23
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,12 @@ else version (CppRuntime_Microsoft)
7070

7171
class type_info
7272
{
73-
//virtual ~this();
74-
void dtor() { } // reserve slot in vtbl[]
73+
@nogc:
74+
extern(D) ~this() nothrow {}
7575
//bool operator==(const type_info rhs) const;
7676
//bool operator!=(const type_info rhs) const;
77-
final bool before(const type_info rhs) const;
78-
final const(char)* name(__type_info_node* p = &__type_info_root_node) const;
77+
final bool before(const type_info rhs) const nothrow;
78+
final const(char)* name(__type_info_node* p = &__type_info_root_node) const nothrow;
7979

8080
private:
8181
void* pdata;
@@ -85,14 +85,12 @@ else version (CppRuntime_Microsoft)
8585

8686
class bad_cast : exception
8787
{
88-
this(const(char)* msg = "bad cast");
89-
//virtual ~this();
88+
extern(D) this(const(char)* msg = "bad cast") @nogc nothrow { super(msg); }
9089
}
9190

9291
class bad_typeid : exception
9392
{
94-
this(const(char)* msg = "bad typeid");
95-
//virtual ~this();
93+
extern(D) this(const(char)* msg = "bad typeid") @nogc nothrow { super(msg); }
9694
}
9795
}
9896
else version (CppRuntime_Gcc)
@@ -108,39 +106,47 @@ else version (CppRuntime_Gcc)
108106

109107
class type_info
110108
{
111-
void dtor1(); // consume destructor slot in vtbl[]
112-
void dtor2(); // consume destructor slot in vtbl[]
113-
final const(char)* name()() const nothrow {
109+
@nogc:
110+
extern(D):
111+
~this() {}
112+
final const(char)* name()() const nothrow
113+
{
114114
return _name[0] == '*' ? _name + 1 : _name;
115115
}
116-
final bool before()(const type_info _arg) const {
116+
final bool before()(const type_info _arg) const nothrow
117+
{
117118
import core.stdc.string : strcmp;
118119
return (_name[0] == '*' && _arg._name[0] == '*')
119120
? _name < _arg._name
120121
: strcmp(_name, _arg._name) < 0;
121122
}
122123
//bool operator==(const type_info) const;
123-
bool __is_pointer_p() const;
124-
bool __is_function_p() const;
125-
bool __do_catch(const type_info, void**, uint) const;
126-
bool __do_upcast(const __class_type_info, void**) const;
124+
// dummy implementations to populate the D vtable:
125+
bool __is_pointer_p() const { assert(0); }
126+
bool __is_function_p() const { assert(0); };
127+
bool __do_catch(const type_info, void**, uint) const { assert(0); };
128+
bool __do_upcast(const __class_type_info, void**) const { assert(0); };
127129

130+
protected:
128131
const(char)* _name;
129-
this(const(char)*);
132+
133+
this(const(char)* name) { _name = name; }
130134
}
131135

132136
class bad_cast : exception
133137
{
134-
this();
135-
//~this();
136-
override const(char)* what() const;
138+
@nogc:
139+
extern(D):
140+
this() nothrow {}
141+
override const(char)* what() const nothrow { return "bad cast"; }
137142
}
138143

139144
class bad_typeid : exception
140145
{
141-
this();
142-
//~this();
143-
override const(char)* what() const;
146+
@nogc:
147+
extern(D):
148+
this() nothrow {}
149+
override const(char)* what() const nothrow { return "bad typeid"; }
144150
}
145151
}
146152
else

0 commit comments

Comments
 (0)