Use of throwing methods in CETL core
まだ誰も着手していません。
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 70/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- cpp
- 領域
- embedded-iot
調査の方向性
include/cetl/pf17/variant.hpp:104 から始めてください。ここでは cetl::pf17::visit が lut.at(index) でルックアップテーブルをインデックスします。周囲の detail 失敗ヘルパー、または関連 issue の終了フックを読み、境界チェックの経路を選んでから、.at(index) をそのチェックと operator[] に置き換えてください。chronomorphize の doc コメントを更新し、-fno-exceptions でコンパイルし、std::__throw_* シンボルが参照されていないことを検証する CI ジョブを追加してください。再現プログラムが libstdc++ の throw ヘルパーなしでリンクし、既存のテストが通れば完了です。
索引モデルが issue の本文から書いたものです。
説明
cetl::pf17::visit (via chronomorphize) calls std::array::at(), which makes CETL depend on libstdc++'s out-of-line throw helpers even when the user builds with -fno-exceptions. On targets that link no C++ runtime library (for example NuttX-based flight controllers), this produces an unresolvable reference to std::__throw_out_of_range_fmt.
Where
include/cetl/pf17/variant.hpp:104 (main @ bf1e5f3, also v2.1.0):
return lut.at(index)(std::forward<Fun>(fun), std::forward<Args>(ar)...);
Why -fno-exceptions doesn't help
In a hosted libstdc++, std::array::at() calls std::__throw_out_of_range_fmt(), declared in bits/functexcept.h and defined in libstdc++ itself. The header calls it unconditionally; what it does (throw or abort) is decided by how libstdc++ was built, not by the user's flags. Only a freestanding build (_GLIBCXX_HOSTED == 0) makes these helpers inline std::__terminate() calls.
Minimal reproduction with Arm GNU Toolchain 13.3.rel1:
#include <array>
int f(unsigned i) { static constexpr std::array<int, 3> a{1, 2, 3}; return a.at(i); }
| Flags | Undefined reference |
|---|---|
-std=c++23 -Os -mcpu=cortex-m7 -mthumb -fno-exceptions -fno-rtti |
std::__throw_out_of_range_fmt(char const*, ...) |
same + -ffreestanding |
std::terminate() |
Any use of cetl::pf17::visit therefore pulls in the helper at -Os as well as -O0.
Proposal
Replace .at() with an explicit bounds check that uses CETL's own failure path, then index with operator[]:
detail::bad_access_unless(index < sizeof...(Is)); // or the termination hook from the companion issue
return lut[index](std::forward<Fun>(fun), std::forward<Args>(ar)...);
This keeps the documented behaviour ("if index >= N, behaves like std::array<...,N>::at(index)") for exception-enabled builds if bad_access_unless throws, and removes the libstdc++ dependency for -fno-exceptions builds. The doc comment on chronomorphize would need updating to match.
It would also help to add a CI check that compiles the headers with -fno-exceptions and asserts the object files reference no std::__throw_* symbols, so this doesn't regress.
Patch
A patch implementing this against PR #266 (f4d8b79) is attached.
- 主要言語
- C++
- スター
- 18
- フォーク
- 4
- 平均マージ
- 7日 16時間
- マージ済み PR(30日)
- 7
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
OpenCyphal/CETL のほかの issue
-
accepted
難易度 3/5 1〜2日 初心者へのやさしさ 70/100
OpenCyphal/CETL#270 ·
-
documentation
難易度 3/5 1〜2日 初心者へのやさしさ 45/100
OpenCyphal/CETL#262 ·
-
under consideration
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
OpenCyphal/CETL#252 ·
-
tracking
難易度 3/5 1〜2日 初心者へのやさしさ 35/100
OpenCyphal/CETL#194 ·
-
under consideration
難易度 5/5 1週間以上 初心者へのやさしさ 25/100
OpenCyphal/CETL#176 · コメント 1 件 ·
OpenCyphal/CETL の issue をすべて見る
似ている issue
-
good first issue hardware-report help wanted
難易度 1/5 1時間未満 初心者へのやさしさ 66/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
-
launcher: settings are never saved on macOS — QSettings SystemScope points to /Library/Preferencesオープン
難易度 1/5 1時間未満 初心者へのやさしさ 85/100
メンテナーはふだん 1 日以内に返信
-
documentation ready
難易度 1/5 1時間未満 初心者へのやさしさ 80/100
MartinPTielemans/ilo#3806 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 80/100