Bug 14193 – Provide a way to mangle a D struct as a C++ class.

Status
RESOLVED
Resolution
WORKSFORME
Severity
enhancement
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
All
Creation time
2015-02-17T12:19:09Z
Last change time
2018-04-10T05:54:32Z
Keywords
C++
Assigned to
No Owner
Creator
Guillaume Chatelet

Comments

Comment #0 by chatelet.guillaume — 2015-02-17T12:19:09Z
It seems better to implement C++ types as structs in D because of value semantic and easier integration. Unfortunately, Microsoft's compiler mangles structs and classes in a different way so using a struct on D side will fail to link with the C++ object. See http://en.wikipedia.org/wiki/Visual_C%2B%2B_name_mangling#Data_Type. Maybe we could define something like the following : extern(C++, std) { pragma(mangleAs, "class") struct basic_string() { ... } }
Comment #1 by dfj1esp02 — 2015-02-17T14:13:58Z
Though, this doesn't sound like a painless C++ integration. Clean support for C++ structs and classes would be better.
Comment #2 by code — 2015-02-17T15:36:38Z
The core issue is that sometimes C++ libraries will use "class" for value types. On Windows (at least MSVC) struct and class types are mangled differently. So it is not possible to declare std::string as a struct on the D side (which would be possible on gcc / clang because they don't mangle structs and classes differently). This has nothing to do with a "painless C++ integration". It would just help integrating C++ when you don't have control over the C++ source.
Comment #3 by dfj1esp02 — 2015-02-17T16:09:29Z
I mean, use classes for classes, structs for structs naturally. If dmd codebase is not ready for the task, that's a different problem :)
Comment #4 by code — 2015-02-17T18:05:49Z
That doesn't work. C++ does not have a concept of value types and reference types. D does. So you can't "simply" use classes as classes and structs as structs.
Comment #5 by bugzilla — 2018-04-10T05:54:32Z
extern (C++, class) struct ... will mangle it as a class.