| 1 |
// PR tree-optimization/104601 |
| 2 |
// { dg-do run } |
| 3 |
// { dg-options "-std=c++17 -Wno-unused-result" } |
| 4 |
// { dg-skip-if "requires hosted libstdc++ for vector" { ! hostedlib } } |
| 5 |
|
| 6 |
#include <algorithm> |
| 7 |
#include <optional> |
| 8 |
#include <vector> |
| 9 |
|
| 10 |
inline std::optional<int> |
| 11 |
foo (std::vector<int>::iterator b, std::vector<int>::iterator c, |
| 12 |
std::optional<int> h (int)) |
| 13 |
{ |
| 14 |
std::optional<int> d; |
| 15 |
find_if (b, c, [&](auto e) { d = h(e); return d; }); |
| 16 |
return d; |
| 17 |
} |
| 18 |
|
| 19 |
std::optional<int> |
| 20 |
bar (int) |
| 21 |
{ |
| 22 |
return 1; |
| 23 |
} |
| 24 |
|
| 25 |
int |
| 26 |
main () |
| 27 |
{ |
| 28 |
std::vector<int> g(10); |
| 29 |
auto b = g.begin (); |
| 30 |
auto c = g.end (); |
| 31 |
auto e = foo (b, c, bar); |
| 32 |
if (!e) |
| 33 |
__builtin_abort (); |
| 34 |
} |