For this code: #include <algorithm> #include <optional> #include <string> void f(const std::string& t) { if (std::any_of(t.begin(), t.end(), [](const auto& c) { return c == 0b01000000; })) { std::string s; std::optional<std::string::const_iterator> f; for (auto i = t.begin(); i != t.end(); ++i) { const auto n = *i; if (n == 0b01000000) { f = i; } else if (f) { std::string_view key(&(**f), 2); s += key; f.reset(); } } } } With gcc 9.2.0, g++ -std=c++17 -O3 -Wmaybe-uninitialized reports no warnings. g++ -std=c++2a -O3 -Wmaybe-uninitialized reports: <source>: In function 'void f(const string&)': <source>:12:52: warning: 'f' may be used uninitialized in this function [-Wmaybe-uninitialized] 12 | std::optional<std::string::const_iterator> f; | ^ See https://gcc.godbolt.org/z/ph3l0u With gcc trunk, the warning changes to: <source>: In function 'void f(const string&)': <source>:15:52: warning: 'f.__gnu_cxx::__normal_iterator<const char*, std::__cxx11::basic_string<char> >::_M_current' may be used uninitialized in this function [-Wmaybe-uninitialized] 15 | std::optional<std::string::const_iterator> f; | ^ See https://gcc.godbolt.org/z/8rGDGi
Possible duplicate of pr80635.
With -Wsystem-headers you also get the warning in C++17 (and it is actually a bit more informative, at least it says where it is used).
(In reply to Martin Sebor from comment #1) > Possible duplicate of pr80635. Well, related at least...
Confirmed, started with r9-84-gcdc184174ce56df1.
Yep, same issue. *** This bug has been marked as a duplicate of bug 80635 ***