About Store Forum Documentation Contact



Post Reply 
Problems with some c++ templates compilation
Author Message
zielony71 Offline
Member

Post: #1
Problems with some c++ templates compilation
Hi everybody!

After severals hours of struggling with compilation my c++ code in Esenthel Engine I want to share with some of my remarks.
First, I found the EE a very original and innovatory idea. It is quite different from what you can find in today's game development world. Someone may say that this is a disadventage, but I think that a progress is powered by the innovations. So, I regard EE as a very positive occurence, but I found that some work have to be done on it, because there are some lacks and even bugs in it. Besides the lack of inline methods (see the thread I previously started: link) there are two of them that I have found recently (both releated to c++ templates compilation) :

1. C++ code-reorganization made by EE transforms static variables declared in template class wrong. I mean the variables dependent on template argument. E. g. lets take a classic example of simple singleton pattern:
Code:
template <typename TT> class Singleton
   {
       static TT* sSingleton = 0;
   public:
       Singleton()
       {
           if (sSingleton)
           {
              throw std::exception("Attempt to recreate a                         singleton!");
           }
           sSingleton = static_cast<TT*>(this);
           }
       virtual ~Singleton() { sSingleton = 0; }
       static TT* getSingleton() { return sSingleton; }
   };

   class SomeSingleton : public Singleton<SomeSingleton>
   {
       ....
   };

After code-reoragnization the static definition of sSingleton should go to header file with templates, but it goes to .cpp file and is even not marked as template:
Code:
// Singleton.cpp:
        TT* Singleton<TT>::sSingleton = 0;
Of course such a code couses compilation error. It's evident bug, I think.

2. Free template functions placed in namespace do not compile when Android target is selected. The reason of it is that after the code-reorganization the function names are prepended by namespace name although the functions are yet enclosed in namespace scope. There is an example:

Code:
namespace SomeNamespace
{
    template <typename TT>  TT fun(TT arg)
    {
        return sin(cos(arg));
    }
}

After code-reorganization the function definition goes to a heder file with templates, but in this way:
Code:
// Some.template.h:
namespace SomeNamespace
{
    template <typename TT>  TT SomeNamespace::fun(TT arg)
    {
        return sin(cos(arg));
    }
}
As I know, such a redundant explicit qualification is forbidden in modern c++ (e.g. c++11). However it compiles when Windows target is selected. But it does not compile for Android target (compiler used for Android target is probably more restrictive in sticking to the c++ standard). The same applies to member functions of template class, and maybe also to template member functions (but I didn't check the last case).
So the second bug is: redundant namespace qualification of templates.
As I tried to resolve this problem I found that probably there is no walkaroud of this bug unless you give up using namespaces.

So these are the problems I met when compiling some of my c++ code. When I find something more I will make a new post. Now I think it will be nice these bugs will be fixed in the next releases of EE, so the more advanced code using templates will compile.
01-19-2016 10:23 AM
Find all posts by this user Quote this message in a reply
Esenthel Online
Administrator

Post: #2
RE: Problems with some c++ templates compilation
Many thanks for reporting the issues!
I will investigate this soon.
01-19-2016 10:51 AM
Find all posts by this user Quote this message in a reply
Esenthel Online
Administrator

Post: #3
RE: Problems with some c++ templates compilation
Thank you,

I've just fixed both issues in the source code "Beta" branch, this will be available in the next release.
02-22-2016 07:04 AM
Find all posts by this user Quote this message in a reply
Post Reply