Opened 13 years ago

Closed 12 years ago

#4085 closed Bugs (fixed)

GCC warnings in normal_distribution.hpp

Reported by: bluescarni@… Owned by: No-Maintainer
Milestone: Boost 1.43.0 Component: random
Version: Boost 1.42.0 Severity: Problem
Keywords: Cc:

Description

GCC 4.4.3 with '-Wall -Wextra' compilation flags produce the following warning when compiling code using normal_distribution.hpp:

warning: ‘delta.boost::variate_generator<boost::lagged_fibonacci607&, boost::normal_distribution<double> >::_dist.boost::normal_distribution<double>::_r1’ may be used uninitialized in this function

Indeed, both constructor of normal_distribution.hpp do not initialise the _r1, _r2 and _cached_rho members. It seems to me this has no consequences, because the logic of operator() initialises them as needed, but probably GCC is unable to detect this.

The proposed patch (against 1.42.0) initialises to zero the _r1, _r2 and _cached_rho data members in both constructors.

Attachments (1)

shut_off_gcc_warning_normal_distribution.diff (891 bytes ) - added by bluescarni@… 13 years ago.
Proposed patch to initialise to zero the _r1, _r2 and _cached_rho data members of normal_distribution.hpp

Download all attachments as: .zip

Change History (3)

by bluescarni@…, 13 years ago

Proposed patch to initialise to zero the _r1, _r2 and _cached_rho data members of normal_distribution.hpp

comment:1 by Steven Watanabe, 13 years ago

Severity: CosmeticProblem

As a matter of fact, the stream operators can use _r1 and _cached_rho before they are initialized, so this is a real problem.

comment:2 by Steven Watanabe, 12 years ago

Resolution: fixed
Status: newclosed

(In [62545]) Make sure that all members are initialized. Fixes #4085

Note: See TracTickets for help on using tickets.