| 1 |
// { dg-do compile { target c++11 } } |
| 2 |
// { dg-options "-O2 -fno-ivopts -fdump-tree-optimized" } |
| 3 |
|
| 4 |
template <class T> |
| 5 |
struct simple_optional { |
| 6 |
bool has_val; |
| 7 |
T val; |
| 8 |
|
| 9 |
auto begin() const -> T const* { return &val; } |
| 10 |
auto end() const -> T const* { return &val + (has_val ? 1 : 0); } |
| 11 |
}; |
| 12 |
|
| 13 |
void f(int); |
| 14 |
|
| 15 |
void call_f(simple_optional<int> const& o) { |
| 16 |
for (int i : o) { |
| 17 |
f(i); |
| 18 |
} |
| 19 |
} |
| 20 |
|
| 21 |
// Only a conditional execution of 'f' should prevail, no loop |
| 22 |
// { dg-final { scan-tree-dump-times "<bb" 5 "optimized" } } |