ESPHome 2026.7.0
Loading...
Searching...
No Matches
throw_stubs.h
Go to the documentation of this file.
1#pragma once
2/*
3 * Inline overrides for std::__throw_* helpers (ESP8266).
4 *
5 * ESP8266 Arduino compiles with -fno-exceptions and ships a libstdc++ whose
6 * std::__throw_* functions already just call abort() -- they never read their
7 * const char* message argument. But the compiler still emits the message load
8 * at every throw site (inside header-instantiated std::string / std::vector
9 * code), so --gc-sections keeps those libstdc++ error strings alive. On
10 * ESP8266 .rodata lives in DRAM, so each one wastes scarce RAM (e.g.
11 * "basic_string::_M_construct null not valid", "basic_string::_M_create",
12 * "cannot create std::vector larger than max_size()", "array::at: ...").
13 *
14 * Providing inline definitions here lets GCC see the message argument is
15 * unused, dead-strip the load, and drop the string entirely -- no LTO needed.
16 * Behavior is identical to today: a bare abort() (the message was never
17 * printed). This header MUST be force-included before <string>, so it is
18 * wired up via build_src_flags "-include ..." in this component's __init__.py.
19 *
20 * Note: this defines functions in namespace std (technically UB). It is safe
21 * here because the definitions match the existing abort() behavior exactly.
22 */
23
24#ifdef __cplusplus
25
26// Empty namespace so the CI namespace check is satisfied; the overrides below
27// must live in namespace std, so they cannot go in the component namespace.
28namespace esphome::esp8266 {} // namespace esphome::esp8266
29
30// NOLINTBEGIN(bugprone-reserved-identifier,bugprone-std-namespace-modification,cert-dcl37-c,cert-dcl51-cpp,cert-dcl58-cpp,readability-identifier-naming)
31namespace std {
32
33__attribute__((__noreturn__)) inline void __throw_logic_error(const char *) { __builtin_abort(); }
34__attribute__((__noreturn__)) inline void __throw_length_error(const char *) { __builtin_abort(); }
35__attribute__((__noreturn__)) inline void __throw_out_of_range(const char *) { __builtin_abort(); }
36__attribute__((__noreturn__)) inline void __throw_out_of_range_fmt(const char *, ...) { __builtin_abort(); }
37
38} // namespace std
39// NOLINTEND(bugprone-reserved-identifier,bugprone-std-namespace-modification,cert-dcl37-c,cert-dcl51-cpp,cert-dcl58-cpp,readability-identifier-naming)
40
41#endif // __cplusplus
struct @65::@66 __attribute__
Wake the main loop task from an ISR. ISR-safe.
Definition main_task.h:32
STL namespace.