title: Can I use the data() pointer from an std::array member variable before it is initialized? Gives warning
body: <p>I am initializing a base class (<strong>Matrix&lt;3,3&gt;</strong> in example) using the pointer to data stored in an std::array member of derived class <strong>SelfContained</strong>, being warned that &quot;<em>Field 'vdata' is uninitialized when used here</em>&quot; on doing so.</p>
  <p>The warning makes sense, but I'm not sure the best way to avoid it... the code seems to work anyway, but I don't like to see warnings so I'm attempting to fix it.</p>
  <p>I might be totally wrong, but it seems like std:array vdata is  allocated when used here, so the data() pointer should already be valid even though the array is uninitialized. Since I'm initializing it immediately afterwards, I'm tempted to just ignore the warning... but I'm hopeful that there's a more &quot;correct&quot; way...</p>
  <p>I've iterated through this a couple times... previously the std::array was a C-style array and grabbing the pointer to it did not cause a problem.</p>
  <pre><code>#include &lt;iostream&gt;
  #include &lt;array&gt;
  
  template&lt;class ContainedType&gt;
  class SelfContained: public ContainedType{
  public:
      typedef ContainedType Type;
      
      static constexpr size_t numel()     {   return Type::numel();}
      
      typedef std::array&lt;double, numel()&gt; DataArray;   //  Data Array Type
      DataArray vdata;
      
      SelfContained(DataArray arry_in): ContainedType(vdata.data()), vdata{arry_in} {} // WARNING: Field 'vdata' is uninitialized when used here
      
  };
  
  
  template &lt;size_t m, size_t n&gt;
  class Matrix{
  public:
      typedef double DoubleArray[n][m];   //  Data Array Type
      
      DoubleArray* pdata = NULL;        //  Pointer to data array: to be assigned on instantiation to let instance be a specified sub-array of something else.
      
      static constexpr size_t height() {return m;}
      static constexpr size_t width()  {return n;}
      static constexpr size_t numel()  {return m*n;}
      
      Matrix(double* p) noexcept : pdata{(DoubleArray*)p}{}
  
      // Element reference getters (mostly for internal convenience)
      template&lt;typename ...Args&gt;
      double&amp; data(Args... vals){
          return get_data(*this, vals...);
      }
      template&lt;typename ...Args&gt;
      const double&amp; data(Args... vals) const{
          return get_data(*this, vals...);
      }
      
      // Print Matrix
      void print() const {
          for (size_t j=0; j&lt;height(); j++){
              for(size_t k=0;k&lt;width(); k++){
                  std::printf(&quot;%+15.7f &quot;,data(j,k));
                  //std::printf(&quot;%+4.1f &quot;,data(j,k));
              } std::printf(&quot;\n&quot;);
          } std::printf(&quot;\n&quot;);
      }
      
  private:
      
      // Helper functions for public element-reference getters ...
      // weird, but minimizes code dupication (const/non-const) by putting the guts here
      template&lt;typename InstanceType&gt;
      static auto get_data(InstanceType&amp; instance, size_t row) -&gt; decltype(instance.data(row)) {
          assert(row &gt;= 0 &amp;&amp; row &lt; instance.numel());
          return (*(instance.pdata))[0][row];
      }
      template&lt;typename InstanceType&gt;
      static auto get_data(InstanceType&amp; instance, size_t row, size_t col) -&gt; decltype(instance.data(row,col)) {
          assert(col &gt;= 0 &amp;&amp; col &lt; instance.width());
          assert(row &gt;= 0 &amp;&amp; row &lt; instance.height());
          return (*(instance.pdata))[col][row];
      }
  };
  
  constexpr std::array&lt;double,9&gt; x0 = {1,0,0,0,2,0,0,0,3};
  
  int main(int argc, const char * argv[]) {
  
      
      SelfContained&lt;Matrix&lt;3,3&gt;&gt;(x0).print();
      
      return 0;
  }
  </code></pre>
  <p>Gives warning:
  <em>Field 'vdata' is uninitialized when used here</em></p>
  <p>Output:</p>
  <pre><code>     +1.0000000      +0.0000000      +0.0000000 
       +0.0000000      +2.0000000      +0.0000000 
       +0.0000000      +0.0000000      +3.0000000 
  </code></pre>
  <p>Any assistance is greatly appreciated. Thank you!</p>