title: Error: "incomplete type is not allowed" while porting project
body: <p>I'm porting <a href="http://www.drdobbs.com/embedded-systems/225700666" rel="nofollow">http://www.drdobbs.com/embedded-systems/225700666</a> to <code>Keil MDK</code> for <code>ARM</code> microprocessors. The framework compiles and works fine using <code>gcc</code> on my desktop but using the <code>Keil</code> compiler gives me an error:</p>
  
  <p><code>logging/singleton.h(65): error:  #70: incomplete type is not allowed</code></p>
  
  <p>Following code shows the implementation of a <code>singleton</code>where I get this error. Where does this error come from?</p>
  
  <pre><code>namespace logging {
  
    namespace detail {
  
        template &lt;typename T&gt;
        class singleton
        {
          private:
            struct obj
            {
              obj() { singleton&lt;T&gt;::instance(); }
              inline void empty() const { }
            };
            static obj __obj;
  
            singleton();
  
          public:
            typedef T obj_type;
  
            static obj_type &amp; instance()
            {
              static obj_type obj;  // &lt;-- Here I get this error
  
              __obj.empty();
  
              return obj;
            }
        };
        template &lt;typename T&gt;
        typename singleton&lt;T&gt;::obj
        singleton&lt;T&gt;::__obj;
  
    } /* detail */
  } /* logging */
  </code></pre>
  
  <p>Edit:
  The <code>singleton</code>gets instantiated here</p>
  
  <pre><code>template &lt;typename log_t, typename T&gt;
  struct Obj {
      static return_type&amp; obj () {
          typedef singleton&lt;return_type&gt; log_output;
          return log_output::instance();
      }
  }; 
  </code></pre>
  
  <p>where <code>return_type</code> is a typedef:</p>
  
  <pre><code>typedef R return_type;
  </code></pre>
  
  <p>and that's a parameter of the parent template:</p>
  
  <pre><code>template&lt;typename Level = ::logging::Void, typename R = loggingReturnType&gt;
      class Logger {
         ...
      };
  </code></pre>
  
  <p><code>loggingReturnType</code> is forward declarated above the class definition:</p>
  
  <pre><code>struct loggingReturnType;
  </code></pre>
  
  <p>Edit 2:
  This <code>loggingReturnType</code> gets generated through following makro.</p>
  
  <pre><code>#define LOGGING_DEFINE_OUTPUT(BASE)                                           \
  namespace logging {                                                           \
      struct loggingReturnType : public BASE {                                  \
              /*! \brief The provided typedef is used for compile time          \
               *         selection of different implementation of the           \
               *         %logging framework. Thus, it is necessary              \
               *         that any output type supports this type                \
               *         definition, why it is defined here.                    \
               */                                                               \
              typedef BASE    output_base_type;                                 \
          };                                                                    \
  }
  </code></pre>
  
  <p>This makro gets called in a config header.</p>
  
  <p>Edit 3:
  Her is a link to the preprocessor output: <a href="http://www.pasteall.org/31617/cpp" rel="nofollow">http://www.pasteall.org/31617/cpp</a>. This file compiles pretty using <code>g++</code>. The definition of <code>loggingReturnType</code>is the last before the <code>main</code> - so the singleton doesn't the exact type but nevertheless it works. I also looked at the preprocessor output of the <code>Keil</code> compiler and it's almost the same.</p>
  
  <p>So what went wrong here?</p>