On mainline I get some bogus warnings about uninitialized variables.
Just compile the following with "g++ -O -Wall":
==================================================
#include<valarray>
void foo(int i, std::valarray<int>& v)
{
v += i*v;
}
void bar()
{
std::valarray<int> v;
for (int j=0; j<2; ++j)
foo(0, v);
}
==================================================
The warning message is:
bug.cc: In function 'void bar()':
bug.cc:13: warning: 'i' may be used uninitialized in this function
A reduced version is here (compile with "-O -Wall"):
==================================================
struct A
{
void foo() const;
};
struct B
{
const int& i;
const A& a;
B(const int& __i, const A& __a) : i(__i), a(__a) {}
static void bar(const B& b) { b.a.foo(); }
};
void baz()
{
A a;
for (int j=0; j<2; ++j)
B::bar(B(0,a));
}
==================================================
The warning message for this case is even weirder (anonymous seems to refer
to the constant 0):
bug.cc: In function 'void baz()':
bug.cc:20: warning: '<anonymous>' may be used uninitialized in this function
Code like this compiled with -Werror will be rejected, so I'll rate
this as a rejects-valid bug.
The 4.0 branch is not affected.
--
Summary: [4.1 regression] bogus "may be used uninitialized"
warning
Product: gcc
Version: 4.1.0
Status: UNCONFIRMED
Keywords: rejects-valid, monitored
Severity: normal
Priority: P2
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: reichelt at gcc dot gnu dot org
CC: gcc-bugs at gcc dot gnu dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21124