docs: correct assertion conditions and remove stale diagnostic locations (#6131)

Signed-off-by: Niels Lohmann <mail@nlohmann.me>
This commit is contained in:
Aditya Singh Bakawat authored and GitHub committed 2026-11-18 08:56:51 +01:00
1 parent 0ac14610d6
commit 8c3335d41f
2 files changed
+11 -25

No files matched your search

+3 -5
View File
@@ -47,11 +47,9 @@ Therefore, assertions can be switched off by defining `NDEBUG`.
}
```
Output:
```
Assertion failed: (m_value.object->find(key) != m_value.object->end()), function operator[], file json.hpp, line 2144.
```
The assertion `#!cpp it != m_data.m_value.object->end()` fails in `#!cpp operator[]`.
The exact diagnostic format, source filename, and line number depend on the platform,
library version, and whether the single-header or multi-header version is used.
??? example "Example: user-defined behavior"
+8 -20
View File
@@ -18,6 +18,10 @@ before including the `json.hpp` header.
## Function with runtime assertions
The examples below identify the failing assertion and the function containing it.
The exact diagnostic format, source filename, and line number depend on the platform,
library version, and whether the single-header or multi-header version is used.
### Unchecked access to a const value
Function [`operator[]`](../api/basic_json/operator%5B%5D.md) implements unchecked access for arrays and objects. Whereas
@@ -46,11 +50,7 @@ See also the documentation on [element access](element_access/index.md).
}
```
Output:
```
Assertion failed: (it != m_data.m_value.object->end()), function operator[], file json.hpp, line 28795.
```
The assertion `#!cpp it != m_data.m_value.object->end()` fails in `#!cpp operator[]`.
??? example "Example 2: Invalid array index in a JSON pointer"
@@ -69,11 +69,7 @@ See also the documentation on [element access](element_access/index.md).
}
```
Output:
```
Assertion failed: (idx < m_data.m_value.array->size()), function operator[], file json.hpp, line 28758.
```
The assertion `#!cpp idx < ptr->m_data.m_value.array->size()` fails in `#!cpp get_unchecked`.
### Constructing from an uninitialized iterator range
@@ -96,11 +92,7 @@ uninitialized iterator is undefined behavior and yields a runtime assertion.
}
```
Output:
```
Assertion failed: (m_object != nullptr), function operator++, file iter_impl.hpp, line 368.
```
The assertion `#!cpp first.m_object != nullptr` fails in `#!cpp basic_json`.
### Operations on uninitialized iterators
@@ -123,11 +115,7 @@ behavior and yields a runtime assertion.
}
```
Output:
```
Assertion failed: (m_object != nullptr), function operator++, file iter_impl.hpp, line 368.
```
The assertion `#!cpp m_object != nullptr` fails in `#!cpp operator++`.
## Changes