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)
       "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:


But instead I get:


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 

Adding the linkage specifier to the return value of DefineList 
makes no difference.

The compiler does use the requested linkage for class Sequence, 

More information about the Digitalmars-d mailing list