https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86485
Bug ID: 86485 Summary: [ 7 regression] "anonymous" maybe-uninitialized false positive with ternary operator Product: gcc Version: 7.3.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: thomas.o...@pdv-fs.de Target Milestone: --- Created attachment 44382 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=44382&action=edit Minimal example for maybe-uninitialized false positive regression The following minimal code example triggers the maybe-uninitialized warning on gcc 8.1 and 7.3, but not on 5.3 or 6.2. Only shows up when optimizations are enabled, and removing seemingly unrelated code "fixes" it again. // compile with g++ 7.3 or 8.1 and optimizations enabled (not 5.3 or 6.2) // g++ -O1 -c maybe_uninitialized_false_positive.cpp -o /dev/null -Werror=maybe-uninitialized // minimal working example created with creduce struct empty_but_important {}; struct in_ternary_op { in_ternary_op() noexcept {} empty_but_important e; // REMOVE (or replace with int) // and the error disappears }; struct M { M(in_ternary_op) noexcept; }; struct MustInheritBase { virtual M get_a(bool b) noexcept; }; struct ZZ : MustInheritBase { M get_a(bool b) noexcept { // b = true; // ADD and the error disappears return M( b ? in_ternary_op{} : in_ternary_op{} ); // ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // error: '<anonymous>' may be used uninitialized in // this function [-Werror=maybe-uninitialized] // -------------------------------------------------- } }; ZZ zz_fn() { // REMOVE and the error disappears ZZ z; return z; }