Make error code types nodiscard
This commit is contained in:
@@ -18,7 +18,7 @@ public:
|
||||
/**
|
||||
* @brief Status returned by streaming parse operations.
|
||||
*/
|
||||
enum class ParseStatus {
|
||||
enum class [[nodiscard]] ParseStatus {
|
||||
Incomplete, ///< Parser needs more data to complete parsing
|
||||
Complete, ///< Successfully parsed a complete commit request
|
||||
Error ///< Parse error occurred (check get_parse_error() for details)
|
||||
@@ -27,7 +27,7 @@ public:
|
||||
/**
|
||||
* @brief Result type for one-shot parsing operations.
|
||||
*/
|
||||
enum class ParseResult {
|
||||
enum class [[nodiscard]] ParseResult {
|
||||
Success, ///< Parsing completed successfully
|
||||
InvalidJson, ///< Invalid JSON format or structure
|
||||
MissingField, ///< Required field missing from input
|
||||
|
||||
3
style.md
3
style.md
@@ -344,9 +344,10 @@ arena_allocator.reset(); // Reset arena memory
|
||||
- **Error messages are human-readable only** - never parse message strings
|
||||
- **Consistent error boundaries** - each component defines what it can/cannot recover from
|
||||
- **Interface precondition violations are undefined behavior** - acceptable to skip checks for performance in hot paths
|
||||
- **Error code types must be nodiscard** - mark error code enums with `[[nodiscard]]` to prevent silent failures
|
||||
|
||||
```cpp
|
||||
enum class ParseResult { Success, InvalidJson, MissingField };
|
||||
enum class [[nodiscard]] ParseResult { Success, InvalidJson, MissingField };
|
||||
|
||||
// System failure - abort immediately
|
||||
void* memory = std::malloc(size);
|
||||
|
||||
Reference in New Issue
Block a user