Skip to content

Commit d733947

Browse files
pbackusBolpat
authored andcommitted
Document use of struct vs. class with extern(C++) (#4166)
1 parent 32e52ee commit d733947

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

spec/cpp_interface.dd

+15-4
Original file line numberDiff line numberDiff line change
@@ -290,8 +290,19 @@ $(H2 $(LNAME2 classes, Classes))
290290

291291
$(P D structs and classes have different semantics whereas C++ structs and
292292
classes are basically the same. The use of a D struct or class depends on
293-
the C++ implementation and not on the used C++ keyword.
294-
When mapping a D $(CODE class) onto a C++ $(CODE struct),
293+
the C++ implementation and not on the used C++ keyword.)
294+
295+
$(UL
296+
$(LI If the C++ implementation has one or more $(CODE virtual) member
297+
functions (including inherited member functions), it should be declared as
298+
an $(CODE extern(C++) class) in D.)
299+
300+
$(LI If the C++ implementation does not have any $(CODE virtual) member
301+
functions (including inherited member functions), it should be declared as
302+
an $(CODE extern(C++) struct) in D.)
303+
)
304+
305+
$(P When mapping a D $(CODE class) onto a C++ $(CODE struct),
295306
use $(CODE extern(C++, struct)) to avoid linking problems with C++ compilers
296307
(notably MSVC) that distinguish between C++'s $(CODE class) and $(CODE struct)
297308
when mangling. Conversely, use $(CODE extern(C++, class)) to map a D
@@ -811,12 +822,12 @@ $(H2 $(LNAME2 data-type-compatibility, Data Type Compatibility))
811822

812823
$(TROW
813824
$(ARGS $(CODE extern (C++)) $(B struct)),
814-
$(ARGS $(B struct) or $(B class))
825+
$(ARGS $(B struct) or $(B class) without virtual member functions)
815826
)
816827

817828
$(TROW
818829
$(ARGS $(CODE extern (C++)) $(B class)),
819-
$(ARGS $(B struct) or $(B class))
830+
$(ARGS $(B struct) or $(B class) with virtual member functions)
820831
)
821832

822833
$(TROW

0 commit comments

Comments
 (0)