| 1 |
// { dg-do compile } |
| 2 |
// { dg-require-effective-target c++17 } |
| 3 |
// { dg-options "-O2 -Wall" } |
| 4 |
// { dg-skip-if "requires hosted libstdc++ for stdexcept" { ! hostedlib } } |
| 5 |
|
| 6 |
#include <optional> |
| 7 |
#include <stdexcept> |
| 8 |
|
| 9 |
std::optional<int> foo() |
| 10 |
{ |
| 11 |
volatile int x = 1; |
| 12 |
if (x) |
| 13 |
throw std::runtime_error("haha"); |
| 14 |
return 42; |
| 15 |
} |
| 16 |
|
| 17 |
int main() |
| 18 |
{ |
| 19 |
std::optional<int> optInt; |
| 20 |
try { |
| 21 |
// We falsely DSEd the LHS of the call even though foo throws |
| 22 |
// which results in an uninitialized diagnostic |
| 23 |
optInt = foo(); |
| 24 |
} catch (...) { |
| 25 |
return optInt.has_value(); |
| 26 |
} |
| 27 |
std::optional<double> optDbl{optInt}; |
| 28 |
return optDbl ? optDbl.value () : 2.0; |
| 29 |
} |