GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • cpprefjp - C++日本語リファレンス
  • GitHub Project

This view

  • Original page
  • New address

GeezerVison is showing cpprefjp.github.io — std::basic_stacktrace::current - cpprefjp C++日本語リファレンス

  1. リファレンス
  2. stacktrace
  3. basic_stacktrace
  4. current

最終更新日時: 2026年02月26日 13時20分38秒 (JST)
Akira Takahashi が更新

履歴 編集

function
<stacktrace>

std::basic_stacktrace::current(C++23)

static basic_stacktrace
  current(const allocator_type& alloc = allocator_type()) noexcept; // (1) C++23

static basic_stacktrace
  current(size_type skip,
          const allocator_type& alloc = allocator_type()) noexcept; // (2) C++23

static basic_stacktrace
  current(size_type skip,
          size_type max_depth,
          const allocator_type& alloc = allocator_type()) noexcept; // (3) C++23

概要

現在位置からのスタックトレースを取得する。

  • (1) : 現在位置から現在の実行スレッドの初期関数までの全体のスタックトレースを取得する
  • (2) : 現在位置 + skipから実行スレッドの初期関数までのスタックトレースを取得する
  • (3) : 現在位置 + skipから最大でmax_depth個のスタックトレースを取得する

堅牢化された事前条件

  • (3) : skip <= skip + max_depthであること

戻り値

  • (1) :
    • 現在の実行スレッドでの、現在の評価のスタックトレースを保持するbasic_stacktraceオブジェクトを構築する
    • allocはstacktrace_entryオブジェクトの配列を保持するstd::vector型メンバ変数に渡される
  • (2) :
    • basic_stacktrace::current(alloc)で構築されたオブジェクトstのst.size()をnとして、
    • イテレータ範囲[st.begin() + min(n, skip), st.end())とallocを、stacktrace_entryオブジェクトの配列を保持するstd::vector型メンバ変数として保持する。ただし、その初期化に失敗した場合、basic_stacktraceオブジェクトは空になる
  • (3) :
    • basic_stacktrace::current(alloc)で構築されたオブジェクトstのst.size()をnとして、
    • イテレータ範囲[st.begin() + min(n, skip), st.begin() + min(n, skip + max_depth))とallocを、stacktrace_entryオブジェクトの配列を保持するstd::vector型メンバ変数として保持する。ただし、その初期化に失敗した場合、basic_stacktraceオブジェクトは空になる

備考

  • (1) : 正常にスタックトレースを取得できた場合、構築されたbasic_stacktrace型のオブジェクトstの先頭要素st[0]は、現在の評価を表すstacktrace_entryオブジェクトであり、末尾要素st[st.size() - 1]は現在の実行スレッドの初期関数を表すstacktrace_entryオブジェクトである

例

全体のスタックトレースを取得する

#include <iostream>
#include <stacktrace>

void g() {
  std::cout << std::stacktrace::current() << std::endl;
}

void f() {
  g();
}

int main() {
  f();
}

出力例 (GCC)

   0#  g() at /app/example.cpp:5
   1#  f() at /app/example.cpp:9
   2# main at /app/example.cpp:13
   3#      at :0
   4# __libc_start_main at :0
   5# _start at :0
   6# 

現在位置からN個を除いたスタックトレースを取得する

#include <iostream>
#include <stacktrace>

void g() {
  std::cout << std::stacktrace::current(1) << std::endl;
}

void f() {
  g();
}

int main() {
  f();
}

出力例 (GCC)

   0#  f() at /app/example.cpp:9
   1# main at /app/example.cpp:13
   2#      at :0
   3# __libc_start_main at :0
   4# _start at :0
   5# 

指定範囲のスタックトレースを取得する

#include <iostream>
#include <stacktrace>

void g() {
  std::cout << std::stacktrace::current(1, 2) << std::endl;
}

void f() {
  g();
}

int main() {
  f();
}

出力例 (GCC)

   0#  f() at /app/example.cpp:9
   1# main at /app/example.cpp:13

バージョン

言語

  • C++23

処理系

  • Clang: ??
  • GCC: 12 ✅
  • Visual C++: ??

参照

  • P3697R1 Minor additions to C++26 standard library hardening
  • P3878R1 Standard library hardening should not use the 'observe' semantic
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.