| 1 |
// { dg-do compile { target c++17 } } |
| 2 |
// { dg-options "-Wnull-dereference -O2" } |
| 3 |
|
| 4 |
// PR libstdc++/108554 |
| 5 |
// Warning from -Wnull-dereference when extracting a unique_ptr from a map. |
| 6 |
|
| 7 |
// { dg-bogus "null pointer dereference" "PR 108554" { target *-*-* } 0 } |
| 8 |
|
| 9 |
#include <map> |
| 10 |
#include <memory> |
| 11 |
#include <string> |
| 12 |
|
| 13 |
int pop(std::map<std::string, std::unique_ptr<int>>& m) |
| 14 |
{ |
| 15 |
if (auto it = m.find("key"); it != m.end()) |
| 16 |
{ |
| 17 |
auto item = std::move(m.extract(it).mapped()); |
| 18 |
return *item; |
| 19 |
} |
| 20 |
return 0; |
| 21 |
} |