We have some code that has been recently ported to Linux (gcc 7.1 - glibc 2.17). I've included some snippets below - we use these macros in our class headers like shown below.
This is all fine on Windows (VS2019 - 64 bit only). However under gcc we get recursive_init_error. I think the problem is that InitQueryMap (produced by the BEGIN_QUERY_MAP macro) contains recursive call to D::InitQueryMap and gcc protects against this. I thought that if we forced this to inline (we've tried all the -f "inline" compiler options) we could get around this.
Thoughts?
BEGIN_QUERY_MAP(SDSVector);
ADD_INTERFACE(awr::dfem::IVectorElemental<T>);
ADD_CLASS(SDVector);
END_QUERY_MAP();
#define BEGIN_QUERY_MAP(C) \
public: \
const QueryMap& GetQueryMap() const override { static auto queryMap = C::InitQueryMap(); return queryMap;} \
const char* GetObjectPtr() const override { return (const char*) this;} \
const char* GetCName() override { return typeid(*this).name();} \
const std::type_info& GetTypeInfo() override {return typeid(*this); }\
static inline QueryMap InitQueryMap(int offset = 0) \
{ \
QueryMap qmap(10); \
auto cPtr = (C*)1
#define ADD_CLASS(D) { \
const auto &tmpqmap = D::InitQueryMap((int)((char*)((D*)cPtr) - (char*)cPtr) + offset); \
qmap.insert(tmpqmap.begin(), tmpqmap.end()); \
}
#define ADD_INTERFACE(I) \
qmap.emplace(typeid(I).name(), offset + int((char*)((I*)(cPtr)) - (char*)cPtr)); \
qmap.try_emplace(typeid(awr::IAWRUnknown).name(), offset + int((char*)((awr::IAWRUnknown*)((I*)(cPtr))) - (char*)cPtr ))