title: constexpr for null-initialized constructor in a derived class
body: <p>I have something similar to the following</p>
  
  <pre><code>class Base {
  public:
      explicit Base(int* i) noexcept { type = new int; *type = *i; };
      constexpr Base(std::nullptr_t) : type(nullptr) { };
      ~Base() { cout &lt;&lt; "Destroying!" &lt;&lt; endl; delete type; };
  protected:
      int* type;
  };
  
  
  class Derived : public Base {
  public:
      explicit Derived(int* i) noexcept : Base(i) { };
      //constexpr Derived(std::nullptr_t) : type(nullptr) { };
      //constexpr Derived(std::nullptr_t) : Base(nullptr) { };
      ~Derived() { };
  };
  </code></pre>
  
  <p>I would like to achieve some <code>constexpr</code> null constructor for the derived class, but the compiler complains a lot about the two options and similar tests I have done.</p>
  
  <p>Of course the code is more complex, I have an opaque handler and the destructor should behave in a more complex way. The resource free-ing is always the same (no need for multiple destructors, only the <code>Base</code> one).</p>
  
  <p>I don't know how to achieve this, maybe I am going through a wrong path? Any ideas? I expect to be able to do something like:</p>
  
  <pre><code>Derived a(nullptr);
  Derived b(handler1);
  Base c (nullptr);
  Base d (handler2);
  </code></pre>
  
  <p>and, in cleanup, both <code>handler1</code> and <code>handler2</code> are managed in the some way.</p>
  
  <p>Edit:</p>
  
  <p>Clang (version 3.4) complains:</p>
  
  <pre><code>error: constexpr constructor never produces a constant expression [-Winvalid-constexpr]
  </code></pre>
  
  <p>And gcc (version 4.8 [edit: multiple versions, haven't checked all]) doesn't complain when using </p>
  
  <pre><code>constexpr Derived(std::nullptr_t) : Base(nullptr) { };
  </code></pre>
  
  <p>In fact, <code>gcc</code> seems to do what I wanted to achieve, but I do not understand the <code>constexpr</code> enough to know which compiler is doing right and how I can amend the problem.</p>