https://bugs.kde.org/show_bug.cgi?id=472329

            Bug ID: 472329
           Summary: std::optional use: "Conditional jump or move depends
                    on uninitialised value(s)"
    Classification: Developer tools
           Product: valgrind
           Version: 3.21.0
          Platform: Other
                OS: Linux
            Status: REPORTED
          Severity: normal
          Priority: NOR
         Component: memcheck
          Assignee: jsew...@acm.org
          Reporter: kde.si...@dralias.com
  Target Milestone: ---

Steps to reproduce with the cpp file:

```cpp
#include <cstdint>
#include <iostream>
#include <map>
#include <optional>
#include <string>
void foo(std::optional<int64_t> f) {
  std::cout << (f ? *f : 0) << std::endl;
  static std::map<bool, std::pair<int64_t, int64_t>> test{[] {
    std::map<bool, std::pair<int64_t, int64_t>> test;
    test.emplace(true, std::pair{0, 0});
    return test;
  }()};
  auto range{test.find(true)};
  while (range != test.end()) {
    auto [a, b]{range->second};
    if (f && *f != a) {
      range++;
      continue;
    }
    std::cout << (a ? std::string{} : std::string{""}) << std::endl;
    range++;
  }
}
```

And then compilation with g++ (clang++ doesn't reproduce):

```
g++ /tmp/a.cpp -O1 -g   -o /tmp/exe && valgrind --quiet /tmp/exe
```

(g++-12.3 needs -O2, and g++-13 needs -O1)

Output:

```
0
==2753084== Conditional jump or move depends on uninitialised value(s)
==2753084==    at 0x4014CB: foo(std::optional<long>) (a.cpp:16)
==2753084==    by 0x401542: main (a.cpp:24)
==2753084==

-- 
You are receiving this mail because:
You are watching all bug changes.

Reply via email to