mixin()-ed code not treated the same as surrounding code
Roman Hargrave via Digitalmars-d
digitalmars-d at puremagic.com
Sun Aug 13 12:50:57 PDT 2017
I have a mixin & generator I defined in order to mimic a
corresponding CPP macro, DefineList(string name, string typename):
// See Torch - List.h, macro DEFINE_NEW_LIST(NAME, TYPE)
string DefineList(string name, string typename)
{
return
"class " ~ name ~ " : TorchObject {"
~ "public: "
~ typename ~ "** nodes;"
~ "int n_nodes;"
~ "@disable this();"
~ "final void add(" ~ name ~ "* list);"
~ "final void addNode(" ~ typename ~ "* node);"
~ "}";
}
When used in an extern block, the compiler does not use the
requested linkage when generating symbols for the class.
Given the following:
extern(C++, Torch)
{
private import CXXTorch.TorchObject;
private import CXXTorch.List;
private import CXXTorch.general;
class Sequence : TorchObject
{
// body
};
mixin(DefineList("SequenceList", "Sequence"));
}
I would expect the following linker symbols:
_ZN5Torch12SequenceList7addNodeEPNS_8SequenceE
_ZN5Torch12SequenceList3addEPS0_
_ZN5Torch12SequenceListC1Ev
_ZN5Torch12SequenceListC2Ev
But instead I get:
_D8Sequence5Torch12SequenceList6__initZ
_D8Sequence5Torch12SequenceList7__ClassZ
_D8Sequence5Torch12SequenceList6__vtblZ
Which dont reflect any of the classifiers, nor the linkage
specified for SequenceList by DefineList.
Firstly, add() and addNode() are potentially virtual (even though
marked final), and a constructor is present (even though it has
@disable, though I'm unfamiliar with the ABI semantics of
@disable).
Adding the linkage specifier to the return value of DefineList
makes no difference.
The compiler does use the requested linkage for class Sequence,
though.
More information about the Digitalmars-d
mailing list