https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112637
Bug ID: 112637 Summary: Bogus -Wmaybe-uninitialized warning Product: gcc Version: 13.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: dangelog at gmail dot com Target Milestone: --- Testcase from Qt: https://gcc.godbolt.org/z/6brn9Knra class QBenchmarkIterationController { public: QBenchmarkIterationController() noexcept; bool isDone() const noexcept; void next() noexcept; }; class QBenchmarkIterationControllerWrapper { QBenchmarkIterationController controller; bool first = true; public: QBenchmarkIterationControllerWrapper() = default; bool isDone() const noexcept { return !first && controller.isDone(); } void next() noexcept { first = false; controller.next(); } }; int f() noexcept; void check(bool); void testcase() { int result; for (QBenchmarkIterationControllerWrapper w; !w.isDone(); w.next()) result = f(); check(result == 42); } With warnings enabled and any level of optimization enabled, results in: <source>: In function 'void testcase()': <source>:31:10: warning: 'result' may be used uninitialized [-Wmaybe-uninitialized] 31 | check(result == 42); | ~~~~~^~~~~~~~~~~~~~ <source>:26:9: note: 'result' was declared here 26 | int result; | ^~~~~~ But this is bogus, as the loop is always entered at least once. Removing the declaration of QBenchmarkIterationController's constructor makes the warning disappear. Upstream Qt patch discussion: https://codereview.qt-project.org/c/qt/qtbase/+/518574