https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99536
Bug ID: 99536
Summary: unexplained warning on "uninitialized value"
Product: gcc
Version: 5.3.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: wuz73 at hotmail dot com
Target Milestone: ---
Although the example in
http://www.cplusplus.com/reference/random/normal_distribution/ compiled fine, I
got a warning on uninitialized value in a similar code below.
#include <random>
void foo(double);
int main()
{
std::default_random_engine generator;
std::normal_distribution<double> norm_dist(0,1);
for(int i=0; i<3; i++)
foo(norm_dist(generator));
return 0;
}
When compiled with "g++ -std=c++11 -Wall -ffast-math -O -c foo.cpp" using
gcc5.3.1 on CentOS7.2, I got:
foo.cpp:8:30: warning: ‘norm_dist.std::normal_distribution::_M_saved’ may be
used uninitialized in this function [-Wmaybe-uninitialized]
foo(norm_dist(generator));
Note that without -O, -ffast-math, or the for-loop, the code compiled fine
without any warning.