https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78044

            Bug ID: 78044
           Summary: -Wmaybe-uninitialized and -O2: false positive with
                    boost::optional
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: romain.geissler at amadeus dot com
  Target Milestone: ---

Created attachment 39843
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=39843&action=edit
test.cpp

Hi,

I am having a false positive when using -O2 and -Wmaybe-uninitialized with the
latest gcc 6 (g++ (GCC) 6.2.1 20160916 (Red Hat 6.2.1-2) from Fedora 24) with
boost::optional. Unfortunately my attempt to reduce the test case by trying to
extract the relevant boost parts failed.

Please find attached the reproducer test.cpp, that includes boost/optional.hpp
(tested with boost 1.60 and 1.61, I have a warning in both cases).

g++ -std=gnu++14 -O2 -Wall -c -o test.o test.cpp
test.cpp: In function 'void someFunction(const void*)':
test.cpp:22:16: warning: '*((void*)& aOptional +4)' may be used uninitialized
in this function [-Wmaybe-uninitialized]
     Optional_t aOptional;
                ^~~~~~~~~

In "someFunction()" the boost::optional value that is being passed and copied
is definitely not uninitialized.

You can also find attached the preprocessor output in test.i

Cheers,
Romain

Reply via email to