| 1 | // { dg-options "-funwind-tables -lstdc++exp" } |
| 2 | // { dg-do run { target c++23 } } |
| 3 | // { dg-require-cpp-feature-test __cpp_lib_stacktrace } |
| 4 | |
| 5 | #include <stacktrace> |
| 6 | #include "testsuite_hooks.h" |
| 7 | |
| 8 | static_assert( std::regular<std::stacktrace_entry> ); |
| 9 | static_assert( std::three_way_comparable<std::stacktrace_entry> ); |
| 10 | |
| 11 | constexpr bool |
| 12 | test_constexpr() |
| 13 | { |
| 14 | std::stacktrace_entry empty; |
| 15 | VERIFY( !empty ); |
| 16 | VERIFY( empty == empty ); |
| 17 | VERIFY( std::is_eq(empty <=> empty) ); |
| 18 | |
| 19 | std::stacktrace_entry::native_handle_type native = empty.native_handle(); |
| 20 | VERIFY( empty.native_handle() == native ); |
| 21 | |
| 22 | return true; |
| 23 | } |
| 24 | static_assert( test_constexpr() ); |
| 25 | |
| 26 | void |
| 27 | test_members() |
| 28 | { |
| 29 | std::stacktrace_entry empty; |
| 30 | VERIFY( empty.description().size() == 0 ); |
| 31 | VERIFY( empty.source_file().size() == 0 ); |
| 32 | VERIFY( empty.source_line() == 0 ); |
| 33 | |
| 34 | std::stacktrace_entry e1 = std::stacktrace::current().at(0); |
| 35 | std::stacktrace_entry e2 = std::stacktrace::current().at(0); |
| 36 | VERIFY( e1 != e2 ); |
| 37 | VERIFY( e1.description() == e2.description() ); |
| 38 | VERIFY( e1.source_file() == e2.source_file() ); |
| 39 | VERIFY( e1.source_line() == (__LINE__ - 5) ); |
| 40 | VERIFY( e2.source_line() == (__LINE__ - 5) ); |
| 41 | |
| 42 | std::stacktrace_entry e3 = []{ |
| 43 | return std::stacktrace::current().at(0); |
| 44 | }(); |
| 45 | VERIFY( e1 != e3 ); |
| 46 | VERIFY( e1.description() != e3.description() ); |
| 47 | VERIFY( e1.source_file() == e3.source_file() ); |
| 48 | VERIFY( e3.source_line() == (__LINE__ - 5) ); |
| 49 | } |
| 50 | |
| 51 | int main() |
| 52 | { |
| 53 | test_members(); |
| 54 | } |