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 

Reply via email to