| 1 |
// { dg-do run { target c++11 } } |
| 2 |
// { dg-skip-if "requires hosted libstdc++ for string/memory" { ! hostedlib } } |
| 3 |
// PR tree-optimization/120987 |
| 4 |
|
| 5 |
#include <memory> |
| 6 |
#include <string> |
| 7 |
#include <cstdlib> |
| 8 |
|
| 9 |
#define ERROR_STRING "012345678901234567" |
| 10 |
|
| 11 |
struct gdb_exception |
| 12 |
{ |
| 13 |
gdb_exception (const char *s) |
| 14 |
: message (std::make_shared<std::string> (s)) |
| 15 |
{} |
| 16 |
|
| 17 |
explicit gdb_exception (gdb_exception &&other) noexcept |
| 18 |
: message (std::move (other.message)) |
| 19 |
{ |
| 20 |
volatile int a = 1; |
| 21 |
if (a != 1) |
| 22 |
abort (); |
| 23 |
} |
| 24 |
|
| 25 |
|
| 26 |
std::shared_ptr<std::string> message; |
| 27 |
}; |
| 28 |
|
| 29 |
void __attribute__((noinline, noclone)) |
| 30 |
throw_exception (gdb_exception &&exception) |
| 31 |
{ |
| 32 |
throw gdb_exception (std::move (exception)); |
| 33 |
} |
| 34 |
|
| 35 |
static void __attribute__((noinline, noclone)) |
| 36 |
parse_linespec (void) |
| 37 |
{ |
| 38 |
struct gdb_exception file_exception (ERROR_STRING); |
| 39 |
throw_exception (std::move (file_exception)); |
| 40 |
} |
| 41 |
|
| 42 |
int |
| 43 |
main (void) |
| 44 |
{ |
| 45 |
try |
| 46 |
{ |
| 47 |
parse_linespec (); |
| 48 |
} |
| 49 |
catch (const gdb_exception &e) |
| 50 |
{ |
| 51 |
if (*e.message != ERROR_STRING) |
| 52 |
__builtin_abort(); |
| 53 |
return 0; |
| 54 |
} |
| 55 |
|
| 56 |
__builtin_abort(); |
| 57 |
} |