title: Member array with size defined by template parameter, but why no warning for zero-size array?
body: <p>I was trying to write a templated base class to store a fixed number of data types, each with varying length. Here is a simplified version of much what I was trying to do:</p>
  
  <pre><code>template&lt; int NINT, int NR0 &gt;
  class EncapsulatedObjectBase
  {
     public:
  
    EncapsulatedObjectBase();
  
    ~EncapsulatedObjectBase();
  
    double m_real[NR0];
    int m_int[NINT];
  }
  </code></pre>
  
  <p>Yeah...so the template parameters can be zero, thus declaring a zero-length array of objects. There will be multiple derived classes for this base, each defining their own number of variables. I have two questions:</p>
  
  <p>1) Is this approach fundamentally flawed?</p>
  
  <p>2) If so...why doesn't icc13 or gcc4.7.2 give me warnings about this when I instantiate a zero-length array? For gcc I use -wall and -wextra -wabi. The lack of warnings made me think that this sort of thing was OK.</p>
  
  <p>EDIT:</p>
  
  <p>Here is the contents of a file that show what I am talking about:</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  template&lt; int NINT, int NR0 &gt;
  class EncapsulatedObjectBase
  {
  public:
    EncapsulatedObjectBase(){}
    ~EncapsulatedObjectBase(){}
  
    double m_real[NR0];
    int m_int[NINT];
  };
  
  
  class DerivedDataObject1 : public EncapsulatedObjectBase&lt;2,0&gt;
  {
     public:
  
     DerivedDataObject1(){}
  
    ~DerivedDataObject1(){}
  
    inline int&amp; intvar1() { return this-&gt;m_int[0]; }
    inline int&amp; intvar2() { return this-&gt;m_int[1]; }
  
  };
  
  
  class DerivedDataObject2 : public EncapsulatedObjectBase&lt;0,2&gt;
  {
     public:
  
     DerivedDataObject2(){}
  
    ~DerivedDataObject2(){}
  
    inline double&amp; realvar1() { return this-&gt;m_real[0]; }
    inline double&amp; realvar2() { return this-&gt;m_real[1]; }
  };
  
  
  
  
  int main()
  {
     DerivedDataObject1 obj1;
     DerivedDataObject2 obj2;
  
     obj1.intvar1() = 12;
     obj1.intvar2() = 5;
  
     obj2.realvar1() = 1.0e5;
     obj2.realvar2() = 1.0e6;
  
     std::cout&lt;&lt;"obj1.intvar1()  = "&lt;&lt;obj1.intvar1()&lt;&lt;std::endl;
     std::cout&lt;&lt;"obj1.intvar2()  = "&lt;&lt;obj1.intvar2()&lt;&lt;std::endl;
     std::cout&lt;&lt;"obj2.realvar1() = "&lt;&lt;obj2.realvar1()&lt;&lt;std::endl;
     std::cout&lt;&lt;"obj2.realvar2() = "&lt;&lt;obj2.realvar2()&lt;&lt;std::endl;
  
  
  }
  </code></pre>
  
  <p>If I compile this with "g++ -Wall -Wextra -Wabi main.cpp" I get no warnings. I have to use the -pedantic flag to get warnings. So I still don't know how unsafe this is. In retrospect, I feel as though it must not be a very good idea...although it would be pretty useful if I could get away with it.</p>