Allow overrides for std::terminate

オープン
#270 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
70/100
issue の種類
機能追加
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
cpp
領域
embedded-iot

調査の方向性

Start in include/cetl/cetl.hpp and copy the existing CETL_DEBUG_ASSERT override pattern, then replace the std::terminate() calls in the five listed headers (optional.hpp line 761, variant.hpp line 227, string_view.hpp 137/244/261, unbounded_variant.hpp 70, pmr/function.hpp 78) inside their !defined(__cpp_exceptions) branches with CETL_TERMINATE(). Read CETL_DEBUG_ASSERT and any docs that describe it to match wording, and drop the now-unneeded <exception> includes from headers that only pulled it in for std::terminate. Done looks like: defining CETL_TERMINATE() to a trap before inclusion makes the library build with -fno-exceptions on a target without libsupc++, and the default still resolves to std::terminate().

索引モデルが issue の本文から書いたものです。

説明

accepted

With -fno-exceptions, CETL's bad-access paths call std::terminate(). On targets that link no C++ runtime library (no libsupc++; for example NuttX-based flight controllers), std::terminate does not exist, so any code that can reach these paths fails to link. Please provide a way for the user to supply a platform-specific termination routine that CETL calls instead of std::terminate() when exceptions are disabled.

Where (main @ bf1e5f3)

File Line Path
include/cetl/pf17/optional.hpp 761 ensure_engaged() (value())
include/cetl/pf17/variant.hpp 227 bad_access_unless() (get, visit)
include/cetl/pf17/string_view.hpp 137, 244, 261 out-of-range access
include/cetl/unbounded_variant.hpp 70 bad access
include/cetl/pmr/function.hpp 78 bad call

Proposal

A single overridable macro in cetl/cetl.hpp, following the existing CETL_DEBUG_ASSERT pattern:

/// @def CETL_TERMINATE
/// Called instead of throwing when exceptions are disabled. Must not return.
/// Define it before including any CETL header to route to a platform handler,
/// e.g. `#define CETL_TERMINATE() ::abort()` or a board-specific panic.
#ifndef CETL_TERMINATE
#    include <exception>
#    define CETL_TERMINATE() std::terminate()
#endif

All of the sites above would call CETL_TERMINATE() in their !defined(__cpp_exceptions) branches. That also lets the headers include <exception> only when the default is used. Several currently include it unconditionally "for std::terminate", which matters for builds that avoid C++ runtime headers.

Notes:

  • A macro (rather than a weak function) works for header-only use and avoids defining any symbol in namespace std.
  • Documenting that the handler must be [[noreturn]] and must not throw would let CETL keep its noexcept guarantees.
  • The upcoming expected polyfill's bad-access path (value() on an error) would naturally use the same hook.
  • A CI configuration that defines CETL_TERMINATE() as __builtin_trap() and checks that objects reference no std::terminate would catch regressions.
主要言語
C++
スター
18
フォーク
4
平均マージ
7日 16時間
マージ済み PR(30日)
7

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

OpenCyphal/CETL のほかの issue

OpenCyphal/CETL の issue をすべて見る

似ている issue

C++ の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。