[go: nahoru, domu]

Bug 92194 - [9/10 Regression] maybe-uninitialized false positive with c++2a since r9-84-gcdc184174ce56df1
Summary: [9/10 Regression] maybe-uninitialized false positive with c++2a since r9-84-g...
Status: RESOLVED DUPLICATE of bug 80635
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 9.2.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic
Depends on:
Blocks: Wuninitialized
  Show dependency treegraph
 
Reported: 2019-10-23 12:26 UTC by Malcolm Parsons
Modified: 2020-01-30 18:50 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2020-01-29 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Malcolm Parsons 2019-10-23 12:26:19 UTC
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
Comment 1 Martin Sebor 2019-10-23 14:35:34 UTC
Possible duplicate of pr80635.
Comment 2 Marc Glisse 2019-10-23 15:12:04 UTC
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).
Comment 3 Eric Gallager 2019-10-24 21:44:31 UTC
(In reply to Martin Sebor from comment #1)
> Possible duplicate of pr80635.

Well, related at least...
Comment 4 Martin Liška 2020-01-29 14:14:51 UTC
Confirmed, started with r9-84-gcdc184174ce56df1.
Comment 5 Jason Merrill 2020-01-30 18:50:13 UTC
Yep, same issue.

*** This bug has been marked as a duplicate of bug 80635 ***