This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/80635] std::optional and bogus -Wmaybe-uninitilized
- From: "palves at redhat dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Thu, 04 May 2017 22:31:46 +0000
- Subject: [Bug c++/80635] std::optional and bogus -Wmaybe-uninitilized
- Auto-submitted: auto-generated
- References: <bug-80635-4@http.gcc.gnu.org/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80635
--- Comment #1 from Pedro Alves <palves at redhat dot com> ---
If you uncomment the lines to use std::optional instead, you get:
$ /opt/gcc/bin/g++ optional.cc -g3 -O2 -Wall -std=gnu++17 -c
optional.cc: In function ‘void func()’:
optional.cc:28:15: warning: ‘maybe_a.A::m’ may be used uninitialized in this
function [-Wmaybe-uninitialized]
~A () { set (m); }
~~~~^~~
optional.cc:41:15: note: ‘maybe_a.A::m’ was declared here
Optional<A> maybe_a;
^~~~~~~
This warns at a different location from the reproducer in the OP.
If you revert back to use the self-contained optional, and change the
optional::m_dummy field to be of empty struct type, similarly to
std::optional:
union
{
struct {} m_dummy;
T m_item;
};
then you get the exact same warning you get with std::optional.
I suspect that the "maybe_a.A::m" location is a bug of its own and a red
herring here, but I can't be sure.