title: CRTP Singleton Incomplete type or Non-literal type
body: <p>I'm trying to make a CRTP Singleton. There's a couple examples on here already. I'm not sure how mine is different or why it fails to compile. First attempt:</p>
  
  <pre><code>template&lt;class Impl&gt;
  class Base
  {
  public:
    static const Impl&amp; getInstance();
    static int foo(int x);
  private:
    static const Impl impl{};
  };
  template&lt;class Impl&gt; inline
  const Impl&amp; Base&lt;Impl&gt;::getInstance()
  {
    return impl;
  }
  template&lt;class Impl&gt; inline
  int Base&lt;Impl&gt;::foo(int x)
  {
    return impl.foo_impl(x);
  }
  
  class Derived1 : public Base&lt;Derived1&gt;
  {
  public:
    int foo_impl(int x) const;
  };
  int Derived1::foo_impl(int x) const
  {
    return x + 3;
  }
  
  int main(int argc, char** argv)
  {
    const Derived1&amp; d = Derived1::getInstance();
    std::cout &lt;&lt; Derived1::foo(3) &lt;&lt; std::endl;
    return 0;
  }
  </code></pre>
  
  <p>g++ 7.4.0 tells me: <code>error: in-class initialization of static data member ‘const Derived1 Base&lt;Derived1&gt;::impl’ of incomplete type</code>.</p>
  
  <p>Well. Ok then. Not sure why that type isn't complete. Try:</p>
  
  <pre><code> . . .
   private:
     static constexpr Impl impl{};
   };
  </code></pre>
  
  <p>Now we fail at link time: <code>undefined reference to 'Base&lt;Derived1&gt;::impl'</code>
  Really?! Looks defined and initialized to me... But even if it did link I have a Derived with a non-trivial destructor so then the compiler is going to bomb at compiletime complaining about a non-literal type used in constexpr.</p>
  
  <p>Why isn't Derived1 complete? How can I build this?</p>