Use of throwing methods in CETL core
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 70/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- cpp
- Ambito
- embedded-iot
Direzione di ricerca
Inizia da include/cetl/pf17/variant.hpp:104, dove cetl::pf17::visit indicizza la tabella di lookup con lut.at(index). Leggi gli helper di errore detail circostanti, o l’hook di terminazione dell’issue correlata, per scegliere il percorso di controllo dei limiti, poi sostituisci .at(index) con quel controllo più operator[]. Aggiorna il commento di documentazione di chronomorphize e aggiungi un job CI che compila con -fno-exceptions e verifica che nessun simbolo std::__throw_* sia referenziato; fatto quando il reproducer linka senza helper di throw di libstdc++ e i test esistenti passano.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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.
- Lingua principale
- C++
- Stelle
- 18
- Fork
- 4
- Merge medio
- 7g 16h
- PR unite (30g)
- 7
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di OpenCyphal/CETL
-
accepted
Difficoltà 3/5 1-2 giorni Idoneità per principianti 70/100
OpenCyphal/CETL#270 ·
-
documentation
Difficoltà 3/5 1-2 giorni Idoneità per principianti 45/100
OpenCyphal/CETL#262 ·
-
under consideration
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
OpenCyphal/CETL#252 ·
-
tracking
Difficoltà 3/5 1-2 giorni Idoneità per principianti 35/100
OpenCyphal/CETL#194 ·
-
under consideration
Difficoltà 5/5 Più di una settimana Idoneità per principianti 25/100
OpenCyphal/CETL#176 · 1 commento ·
Tutte le issue di OpenCyphal/CETL
Issue simili
-
good first issue hardware-report help wanted
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 66/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
-
launcher: settings are never saved on macOS — QSettings SystemScope points to /Library/PreferencesAperta
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 85/100
I maintainer di solito rispondono entro 1 giorno
-
documentation ready
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 80/100
MartinPTielemans/ilo#3806 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 80/100