[Bug c++/86465] C++17 triggers: ‘’ may be used uninitialized in this function
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86465 Jonathan Wakely changed: What|Removed |Added Status|UNCONFIRMED |NEW Last reconfirmed||2019-06-12 See Also||https://gcc.gnu.org/bugzill ||a/show_bug.cgi?id=84299 Ever confirmed|0 |1 --- Comment #4 from Jonathan Wakely --- This is taken from the libstdc++ testsuite: #include #include int f1() { return 1; } struct { int operator()() { return 2; } } f2; void test01() { typedef std::function function; function fo(f1); function fo1; fo1 = (std::move(fo)); assert( static_cast(fo1) ); assert( fo1() == 1 ); fo = function(f2); function fo2; fo2 = (std::move(fo)); assert( static_cast(fo2) ); assert( fo2() == 2 ); } int main() { test01(); } Since GCC 7 this gives warnings when -Wsystem-headers -Wuninitialized -O1 is used: In file included from /xhome/jwakely/gcc/10/include/c++/10.0.0/bits/stl_function.h:60, from /xhome/jwakely/gcc/10/include/c++/10.0.0/functional:49, from uninit.cc:1: /xhome/jwakely/gcc/10/include/c++/10.0.0/bits/move.h: In function 'void test01()': /xhome/jwakely/gcc/10/include/c++/10.0.0/bits/move.h:193:7: warning: '' is used uninitialized in this function [-Wuninitialized] 193 | __a = _GLIBCXX_MOVE(__b); | ^~~ /xhome/jwakely/gcc/10/include/c++/10.0.0/bits/move.h:192:11: warning: '' may be used uninitialized in this function [-Wmaybe-uninitialized] 192 | _Tp __tmp = _GLIBCXX_MOVE(__a); | ^ /xhome/jwakely/gcc/10/include/c++/10.0.0/bits/move.h:193:7: warning: '' may be used uninitialized in this function [-Wmaybe-uninitialized] 193 | __a = _GLIBCXX_MOVE(__b); | ^~~ /xhome/jwakely/gcc/10/include/c++/10.0.0/bits/move.h:193:7: warning: '*((void*)& +24)' may be used uninitialized in this function [-Wmaybe-uninitialized] 193 | __a = _GLIBCXX_MOVE(__b); | ^~~ /xhome/jwakely/gcc/10/include/c++/10.0.0/bits/move.h:193:7: warning: '' may be used uninitialized in this function [-Wmaybe-uninitialized] 193 | __a = _GLIBCXX_MOVE(__b); | ^~~ valgrind and UBsan don't report any problems though.
[Bug c++/86465] C++17 triggers: ‘’ may be used uninitialized in this function
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86465 --- Comment #3 from Pavel Roskin --- Created attachment 44770 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=44770=edit Futher reduced example I was able to reduce the example to just 55 lines, removing almost all the code that came from the standard headers. The code complies with C++ standards all the way back to C++03. As I suspected, the implementation of std::optional in libstdc++ uses a trick to avoid initializing the payload when the optional value default initialized, and that code turns out to be essential for reproducing the issue. Try uncommenting _empty_char, and the warning goes away.
[Bug c++/86465] C++17 triggers: ‘’ may be used uninitialized in this function
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86465 --- Comment #2 from Pavel Roskin --- Created attachment 44761 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=44761=edit Heavily simplified example, g++-5 compatible I'm attaching a dumbed down version of the previous example, which compiles with gcc 5.5.0 and newer. gcc 5.5.0 and gcc 6.4.0 don't produce any warning. gcc 7.3.0, 8.1.0 and the today's gcc from the git master branch all produce the warning. That suggests that the issue is indeed related to the one described in bug #86485. The implementation of optional in libstdc++ 7 doesn't trigger a warning, it's the changes in libstdc++ 8 that started triggering it. However, gcc 7 appears to have the same compiler issue.
[Bug c++/86465] C++17 triggers: ‘’ may be used uninitialized in this function
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86465 --- Comment #1 from Jonathan Wakely --- Possibly related to PR 86485 (just a guess, I haven't investigated).