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::breakpoint - cpprefjp C++日本語リファレンス

  1. リファレンス
  2. debugging
  3. breakpoint

最終更新日時: 2026年10月09日 14時24分38秒 (JST)
Akira Takahashi が更新

履歴 編集

function
<debugging>

std::breakpoint(C++26)

namespace std {
  void breakpoint() noexcept; // (1) C++26
}

概要

ブレークポイントを設置する。

この関数は無条件のブレークポイントであり、デバッガの存在を検出できない状況でもプログラムの一時停止 (ブレーク) を試みる。

プログラムコードでブレークポイントを指定できると、複雑な実行時条件でプログラムを一時停止させることができる。

効果

標準規格としては、この関数の意味論は実装定義である。

実際の動作としては、この関数が呼び出されるとプログラムの実行が一時停止され、以下のいずれかの時点までデバッガに制御が渡される:

  • デバッガによってプログラムが終了される、または
  • デバッガが、この関数が呼び出されなかったかのようにプログラムの実行を再開する

例外

投げない

備考

  • 実装としては、生成されるコードがプラットフォームに対して可能な限り最小になるように最適化することが期待される。例として、x86ターゲット環境ではINT3命令をひとつだけ生成することが期待される
  • デバッガがプログラムを監視していない状況でこの関数が呼び出された場合、プログラムが異常終了する可能性がある。製品のコードに残す場合は、breakpoint_if_debugging()を使用する

例

#include <print>
#include <debugging>
#include <cmath>

// なんらかの処理
double g(double a, double b) {
  return a / b;
}

double f(double a, double b) {
  double ret = g(a, b);
  if (std::isnan(ret) || std::isinf(ret)) {
    // 演算結果でNaNかinfが発生したらブレークし、
    // デバッガでパラメータ (ローカル変数) などを確認する
    std::breakpoint();
  }
  return ret;
}

int main() {
  double ret = f(2.0, 0.0);
  std::println("{}", ret);
}

出力例

inf

バージョン

言語

  • C++26

処理系

  • Clang: 24 ✅
  • GCC: 16.1 (-lstdc++expオプション指定) ✅
  • Visual C++: 2026 Update 2 ❌

参照

  • P2546R5 Debugging Support
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.