summaryrefslogtreecommitdiff
path: root/libstdc++-v3/testsuite/19_diagnostics/stacktrace/entry.cc
blob: a222c425b20a4e5ca30999f70f60b6a4dc810fbd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// { dg-options "-std=gnu++23 -lstdc++_libbacktrace" }
// { dg-do run { target c++23 } }
// { dg-require-effective-target stacktrace }

#include <stacktrace>
#include "testsuite_hooks.h"

static_assert( std::regular<std::stacktrace_entry> );
static_assert( std::three_way_comparable<std::stacktrace_entry> );

constexpr bool
test_constexpr()
{
  std::stacktrace_entry empty;
  VERIFY( !empty );
  VERIFY( empty == empty );
  VERIFY( std::is_eq(empty <=> empty) );

  std::stacktrace_entry::native_handle_type native  = empty.native_handle();
  VERIFY( empty.native_handle() == native );

  return true;
}
static_assert( test_constexpr() );

void
test_members()
{
  std::stacktrace_entry empty;
  VERIFY( empty.description().size() == 0 );
  VERIFY( empty.source_file().size() == 0 );
  VERIFY( empty.source_line() == 0 );

  std::stacktrace_entry e1 = std::stacktrace::current().at(0);
  std::stacktrace_entry e2 = std::stacktrace::current().at(0);
  VERIFY( e1 != e2 );
  VERIFY( e1.description() == e2.description() );
  VERIFY( e1.source_file() == e2.source_file() );
  VERIFY( e1.source_line() == (__LINE__ - 5) );
  VERIFY( e2.source_line() == (__LINE__ - 5) );

  std::stacktrace_entry e3 = []{
    return std::stacktrace::current().at(0);
  }();
  VERIFY( e1 != e3 );
  VERIFY( e1.description() != e3.description() );
  VERIFY( e1.source_file() == e3.source_file() );
  VERIFY( e3.source_line() == (__LINE__ - 5) );
}

int main()
{
  test_members();
}