title: Cannot access member functions of constexpr CRTP Class after casting
body: <p>Building on the answer I got to my question <a href="https://stackoverflow.com/questions/57545503/constexpr-class-taking-const-references-not-compiling">Constexpr Class taking const references not compiling</a>, I was trying go further (playing around with expression templates).</p>
  
  <p>So as the answer suggested, I now use <code>static</code> variables as inputs, and everything compiles correctly (on MSVC 2019).</p>
  
  <p>However, upon adding <code>constexpr static auto val = expr[0]</code> I get error <code>C2131: expression did not evaluate to a constant</code>. The issue seems to be with <code>m_lhs[idx]</code> and <code>m_rhs[idx]</code> as those do not seem to evaluate to a constant, despite the fact that i've marked all <code>operator[]</code> as <code>constexpr</code>.</p>
  
  <p>Is it possible to fix this?</p>
  
  <pre class="lang-cpp prettyprint-override"><code>#include &lt;cstddef&gt;
  
  template&lt;class VecType&gt;
  struct Vector
  {
      constexpr const VecType&amp; get() const noexcept
      {
          return static_cast&lt;const VecType&amp;&gt;(*this);
      }
  };
  
  template&lt;size_t Size&gt;
  class FixedSizeVector : public Vector&lt;FixedSizeVector&lt;Size&gt;&gt;
  {
  public:
      constexpr explicit FixedSizeVector(const int(&amp;array)[Size]) noexcept
          : m_vector()
      {
          for (size_t i = 0; i &lt; Size; ++i)
              m_vector[i] = array[i];
      }
  
      constexpr const int&amp; operator[](size_t idx) const noexcept {
          return m_vector[idx];
      }
  
  private:
      int m_vector[Size];
  };
  
  template&lt;class VecType1, class VecType2&gt;
  class ExpressionAdd : public Vector&lt;ExpressionAdd&lt;VecType1, VecType2&gt;&gt;
  {
  public:
      constexpr ExpressionAdd(const VecType1&amp; lhs, const VecType2&amp; rhs) noexcept
          : m_lhs(lhs), m_rhs(rhs) { }
  
      constexpr int operator[](size_t idx) const noexcept {
          return m_lhs[idx] + m_rhs[idx];
      }
  
  private:
      const VecType1&amp; m_lhs;
      const VecType2&amp; m_rhs;
  };
  
  template&lt;class VecType1, class VecType2&gt;
  constexpr auto operator+(const Vector&lt;VecType1&gt;&amp; lhs, const Vector&lt;VecType2&gt;&amp; rhs)
  {
      return ExpressionAdd(lhs.get(), rhs.get());
  }
  
  
  int main()
  {
      constexpr static int arr[]{ 4,2,9 };
      constexpr static FixedSizeVector a(arr);
  
      constexpr static auto expr = a + a;
      constexpr static auto val  = expr[0];  /* &lt;--- this line causes an error */
  
      return 0;
  }
  
  </code></pre>