Christoph Groth <cwg@xxxxxxxx> writes: > when I compile the attached program with > > g++ -Wall -Wextra -O2 test.cc > > I get the following output: > > test.cc: In function ‘int main()’: > test.cc:198: warning: ‘point.Tiny_vector<double, 1>::x[0u]’ may be used uninitialized in this function > test.cc:198: note: ‘point.Tiny_vector<double, 1>::x[0u]’ was declared here > > That's with gcc 4.4.4. > > Is this warning unjustified or am I missing some subtlety? It's weird that the > warning is only given for foo<1>. > template <int D> > Tiny_vector<double, D> foo() > { > Tiny_vector<double, D> point; > do { > for (int i = 0; i < D; ++i) point[i] = double(rand()) / RAND_MAX; > } while(dot(point, point) > 1); > return point; > } As far as I can see the warning is unjustified. The compiler was smart enough to see that i == 0 is always true within the loop, and used that to promote the only array element into a local variables. However it wasn't smart enough to unwind the nested control structure to see that the value is always set before it is used. In effect the compiler sees that the inner loop could exit, and doesn't see that by the time it exits point[0] must always be set. The warning doesn't happen for foo<2> because in that case the compiler does not promote the If you can, please file a bug report about this, following the directions at http://gcc.gnu.org/bugs/ . Thanks. Ian