Bug 17972 – __traits(getLinkage) doesn't work for classes

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86
OS
All
Creation time
2017-11-07T13:15:41Z
Last change time
2018-06-14T10:32:36Z
Keywords
C++
Assigned to
No Owner
Creator
Jacob Carlborg

Comments

Comment #0 by doob — 2017-11-07T13:15:41Z
I'm not sure if this should be considered a bug or an enhancement request. I think that __traits(getLinkage) should work for classes, structs and interfaces. This is useful to identify a C++ class/struct or an Objective-C interface. Technically the class might not have a linkage but since one usually put the linkage on a class I think it make sense to be able to get the linkage from a class. From an implementation point of view, it looks like the original implementation [1] assumed that all declarations inherit from the Declaration class, but this is not the case for structs, classes and interfaces. [1] https://github.com/dlang/dmd/pull/6822
Comment #1 by razvan.nitu1305 — 2017-11-13T08:56:44Z
This is a bit complicated since you cannot get the linkage directly for aggregate declarations. The only way to obtain it is to visit the AST and search for LinkDeclarations that point out to the class/struct of interest. I wonder why structs and classes don't have a linkage property.
Comment #2 by doob — 2017-11-17T21:27:46Z
What about using the existing fields in ClassDeclaration: "cpp", "objc" and so on [1]? I know it's not exactly the same. [1] https://github.com/dlang/dmd/blob/master/src/ddmd/dclass.d#L215-L218
Comment #3 by turkeyman — 2018-04-30T07:17:13Z
I've just run into this issue. I was trying to fix `destroy()` not working on C++ classes, and quickly realised I needed a reliable way to detect C++ classes! So, we can't fix destroy() until we have this, or an alternative accepted solution...
Comment #4 by razvan.nitu1305 — 2018-06-14T10:32:36Z