Use of throwing methods in CETL core
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 70/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Activo
- Stack tecnológico
- cpp
- Área
- embedded-iot
Línea de trabajo
Empieza en include/cetl/pf17/variant.hpp:104, donde cetl::pf17::visit indexa la tabla de búsqueda con lut.at(index). Lee los ayudantes de fallo de detail circundantes, o el hook de terminación del issue complementario, para elegir la ruta de comprobación de límites, y luego reemplaza .at(index) por esa comprobación más operator[]. Actualiza el comentario de documentación de chronomorphize y añade un job de CI que compile con -fno-exceptions y verifique que no se referencien símbolos std::__throw_*; está hecho cuando el reproductor enlace sin los ayudantes de throw de libstdc++ y pasen las pruebas existentes.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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.
- Lenguaje dominante
- C++
- Estrellas
- 18
- Forks
- 4
- Merge medio
- 7 d 16 h
- PR fusionados (30 d)
- 7
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Sin plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de OpenCyphal/CETL
-
accepted
Dificultad 3/5 1-2 días Aptitud para principiantes 70/100
OpenCyphal/CETL#270 ·
-
documentation
Dificultad 3/5 1-2 días Aptitud para principiantes 45/100
OpenCyphal/CETL#262 ·
-
under consideration
Dificultad 4/5 3-5 días Aptitud para principiantes 35/100
OpenCyphal/CETL#252 ·
-
tracking
Dificultad 3/5 1-2 días Aptitud para principiantes 35/100
OpenCyphal/CETL#194 ·
-
under consideration
Dificultad 5/5 Más de una semana Aptitud para principiantes 25/100
OpenCyphal/CETL#176 · 1 comentario ·
Todos los issues de OpenCyphal/CETL
Issues similares
-
good first issue hardware-report help wanted
Dificultad 1/5 Menos de una hora Aptitud para principiantes 66/100
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
-
launcher: settings are never saved on macOS — QSettings SystemScope points to /Library/PreferencesAbierto
Dificultad 1/5 Menos de una hora Aptitud para principiantes 85/100
Los mantenedores suelen responder en 1 día
-
documentation ready
Dificultad 1/5 Menos de una hora Aptitud para principiantes 80/100
MartinPTielemans/ilo#3806 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 80/100