https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100115
Bug ID: 100115
Summary: Bogus -Wmaybe-uninitialized warning with -O3
Product: gcc
Version: 11.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: boris at kolpackov dot net
Target Milestone: ---
Created attachment 50615
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=50615&action=edit
Reproducer
The attached translation unit produces a bogus "may be used uninitialized"
warning:
$ g++-10 -Wmaybe-uninitialized -O3 -std=c++2a -fdirectives-only -c driver.ii
In file included from
/tmp/dist2/libbutl-0.14.0-a.0.20210415102025.fc5599e0a51a/libbutl/utility.mxx:550,
from driver.cxx:32:
/tmp/dist2/libbutl-0.14.0-a.0.20210415102025.fc5599e0a51a/libbutl/utility.ixx:
In function ‘int main(int, const char**)’:
/tmp/dist2/libbutl-0.14.0-a.0.20210415102025.fc5599e0a51a/libbutl/utility.ixx:345:17:
warning: ‘ate’ may be used uninitialized in this function
[-Wmaybe-uninitialized]
345 | thread_env_ = v;
| ~~~~~~~~~~~~^~~
driver.cxx:392:19: note: ‘ate’ was declared here
392 | auto_thread_env ate (tevars);
| ^~~
The same with GCC 11:
$ g++-11 -Wmaybe-uninitialized -O3 -std=c++2a -fdirectives-only -c driver.ii
In file included from
/tmp/dist2/libbutl-0.14.0-a.0.20210415102025.fc5599e0a51a/libbutl/utility.mxx:550,
from driver.cxx:32:
/tmp/dist2/libbutl-0.14.0-a.0.20210415102025.fc5599e0a51a/libbutl/utility.ixx:
In function ‘int main(int, const char**)’:
/tmp/dist2/libbutl-0.14.0-a.0.20210415102025.fc5599e0a51a/libbutl/utility.ixx:345:17:
warning: ‘*(const char* const**)((char*)&ate + offsetof(butl::auto_thread_env,
butl::auto_thread_env::prev_env.std::optional<const char*
const*>::<unnamed>.std::_Optional_base<const char* const*, true,
true>::<unnamed>))’ may be used uninitialized in this function
[-Wmaybe-uninitialized]
345 | thread_env_ = v;
| ~~~~~~~~~~~~^~~
driver.cxx:392:19: note: ‘*(const char* const**)((char*)&ate +
offsetof(butl::auto_thread_env,
butl::auto_thread_env::prev_env.std::optional<const char*
const*>::<unnamed>.std::_Optional_base<const char* const*, true,
true>::<unnamed>))’ was declared here
392 | auto_thread_env ate (tevars);
| ^~~
In fact, I get a variant of this warning going all the way to GCC 4.9. The
driver.ii file was prepared on Linux (with -fdirectives-only).