This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
small testcase gcc6 + boost optional + Wmaybe-uninit
- From: Jason Mancini <jayrusman at hotmail dot com>
- To: "gcc at gcc dot gnu dot org" <gcc at gcc dot gnu dot org>
- Date: Thu, 13 Oct 2016 16:45:06 +0000
- Subject: small testcase gcc6 + boost optional + Wmaybe-uninit
- Authentication-results: sourceware.org; auth=none
- Authentication-results: spf=softfail (sender IP is 10.152.90.55) smtp.mailfrom=hotmail.com; gcc.gnu.org; dkim=none (message not signed) header.d=none;gcc.gnu.org; dmarc=fail action=none header.from=hotmail.com;
- Spamdiagnosticmetadata: NSPM
- Spamdiagnosticoutput: 1:99
Web search shows that -Wmaybe-uninitialized is an imprecise check, and that boost::optional is already a known sore spot, but I wanted to pass along this small test case in case the warning's owner wanted to do further improvements. We solved our one grumpy instance with auto x = make_optional(0, ...);. Something about the loop + conditional + O1/O2/O3 optimization triggers the false positive. Thanks! -Jason
//==============================================================================
// g++ -c sample.cc -O2 -Wall -Werror
// gcc 6.1/6.2 and boost 1.61/1.62
#include <stdio.h>
#include <boost/optional/optional.hpp>
int main() {
boost::optional<int> value;
for (int x(0); x < 3; ++x) {
if (random() & 1)
value = x;
}
if (value != boost::none) {
int result = value.get();
printf("%d\n", result); // error: '*((void*)& value +4)' may be used uninitialized
}
}
//==============================================================================