Niels Lohmann
d11e89471b
Assert on missing array indices in const operator[] and document the JSON pointer case ( #5606 )
...
The const operator[] overloads are unchecked by design, and a missing key
or index is undefined behavior. The key overload guards this with a
runtime assertion, but the index overload did not, although the element
access documentation says an assertion fires in both cases. The const
JSON pointer overload inherits both through json_pointer::get_unchecked(),
so a pointer to a missing array index read out of bounds even in debug
builds, and its documentation promised out_of_range.404 for any pointer
that cannot be resolved.
Add JSON_ASSERT(idx < size()) to const operator[](size_type), which also
covers the index leg of the const JSON pointer overload. Document the
undefined behavior for the const JSON pointer overload in operator[].md
and in the runtime assertions page. Release builds are unchanged.
Signed-off-by: Niels Lohmann <mail@nlohmann.me >
2026-10-04 11:46:18 +02:00
..
2026-10-02 11:32:15 +02:00
2026-10-02 11:32:15 +02:00
2026-10-02 11:32:15 +02:00
2026-07-04 11:13:25 +02:00
2026-10-02 11:32:15 +02:00
2025-04-05 18:54:35 +02:00
2026-10-02 11:32:15 +02:00
2026-10-02 11:32:15 +02:00
2026-10-02 11:32:15 +02:00
2026-10-02 11:32:15 +02:00
2026-10-02 11:32:15 +02:00
2026-10-02 11:32:15 +02:00
2026-10-02 11:32:15 +02:00
2026-10-02 11:32:15 +02:00
2026-10-02 11:32:15 +02:00
2026-10-02 11:32:15 +02:00
2026-09-30 20:07:45 +02:00
2026-10-02 11:32:15 +02:00
2026-10-02 11:32:15 +02:00
2026-10-02 11:32:15 +02:00
2026-06-29 22:15:18 +02:00
2026-07-26 08:29:31 +00:00
2026-10-02 11:32:15 +02:00
2026-10-02 11:32:15 +02:00
2026-10-02 11:32:15 +02:00
2025-01-17 06:53:35 +01:00
2026-10-02 11:32:15 +02:00
2026-07-04 11:13:25 +02:00
2026-10-02 11:32:15 +02:00
2024-12-09 23:02:30 +01:00
2026-09-30 20:07:45 +02:00
2026-10-02 11:32:15 +02:00
2026-07-09 17:24:19 +02:00
2026-09-27 16:56:21 +02:00
2026-09-27 16:56:21 +02:00
2026-10-02 11:32:15 +02:00
2026-10-02 11:32:15 +02:00
2026-10-02 11:32:15 +02:00
2026-10-02 11:32:15 +02:00
2025-04-05 18:54:35 +02:00
2026-10-02 11:32:15 +02:00
2026-06-29 22:15:18 +02:00
2024-12-09 23:02:30 +01:00
2024-12-06 18:38:25 +01:00
2026-10-02 11:32:15 +02:00
2026-10-02 11:32:15 +02:00
2026-09-27 16:56:21 +02:00
2026-10-02 11:32:15 +02:00
2026-10-02 11:32:15 +02:00
2026-06-29 22:15:18 +02:00
2026-10-02 11:32:15 +02:00
2026-10-02 11:32:15 +02:00
2026-10-02 11:32:15 +02:00
2026-10-02 11:32:15 +02:00
2026-10-02 11:32:15 +02:00
2025-04-05 18:54:35 +02:00
2025-04-05 18:54:35 +02:00
2025-04-05 18:54:35 +02:00
2026-06-29 22:15:18 +02:00
2026-10-02 11:32:15 +02:00
2025-04-05 18:54:35 +02:00
2026-10-02 11:32:15 +02:00
2025-04-05 18:54:35 +02:00
2026-10-02 11:32:15 +02:00
2026-10-02 11:32:15 +02:00
2026-10-02 11:32:15 +02:00
2026-10-02 11:32:15 +02:00
2026-10-02 11:32:15 +02:00
2026-06-29 22:15:18 +02:00
2026-10-02 11:32:15 +02:00
2026-10-02 11:32:15 +02:00
2026-10-02 11:32:15 +02:00
2026-10-02 11:32:15 +02:00
2026-10-02 11:32:15 +02:00
2026-07-04 11:13:25 +02:00
2026-10-02 17:25:17 +02:00
2026-10-02 17:25:17 +02:00
2026-10-02 17:25:17 +02:00
2026-10-02 17:25:17 +02:00
2026-10-02 17:25:17 +02:00
2026-10-02 17:25:17 +02:00
2026-10-02 17:25:17 +02:00
2026-10-02 11:32:15 +02:00
2026-10-02 11:32:15 +02:00
2026-10-04 11:46:18 +02:00
2026-10-02 11:32:15 +02:00
2026-06-29 22:15:18 +02:00
2026-06-29 22:15:18 +02:00
2026-06-29 22:15:18 +02:00
2026-09-30 22:15:20 +02:00
2026-10-02 11:32:15 +02:00
2026-10-02 11:32:15 +02:00
2026-10-02 11:32:15 +02:00
2026-10-02 11:32:15 +02:00
2026-10-02 11:32:15 +02:00
2026-10-02 11:32:15 +02:00
2026-10-02 11:32:15 +02:00
2026-10-02 11:32:15 +02:00
2026-10-02 11:32:15 +02:00
2026-10-02 11:32:15 +02:00
2025-01-17 06:53:35 +01:00
2026-07-09 17:24:19 +02:00
2026-10-02 11:32:15 +02:00
2026-06-29 22:15:18 +02:00
2026-10-02 11:32:15 +02:00
2026-10-02 11:32:15 +02:00
2026-10-02 11:32:15 +02:00
2026-10-02 11:32:15 +02:00
2026-10-02 11:32:15 +02:00
2026-09-27 16:56:21 +02:00
2026-10-02 11:32:15 +02:00
2026-10-02 11:32:15 +02:00
2026-10-02 11:32:15 +02:00
2026-06-29 22:15:18 +02:00
2026-10-02 11:32:15 +02:00
2026-10-02 11:32:15 +02:00
2026-10-02 11:32:15 +02:00
2026-10-02 11:32:15 +02:00
2026-10-02 11:32:15 +02:00
2026-10-02 11:32:15 +02:00