src/json_value.h uses uint8_t without including <cstdint> #37

Closed
opened 2026-06-28 23:12:54 +00:00 by weaselbot · 0 comments
Member

src/json_value.h uses uint8_t in escapeAsJsonString but does not include <cstdint>. As a result, any translation unit that includes this header without first including <cstdint> (or another header that happens to define it) fails to compile.

Relevant code

File: src/json_value.h
Line 134 (inside escapeAsJsonString):

  for (uint8_t c : s) {

The file currently includes <cstddef>, <map>, <memory>, <optional>, <string>, <utility>, <variant>, <vector>, and "weaseljson.h", but not <cstdint>.

Reproduction

Create a minimal source file that includes only this header:

#include "json_value.h"
int main() { return 0; }

Compile:

c++ -std=c++20 -Iinclude -Isrc -c repro.cpp

Result:

src/json_value.h:134:8: error: ‘uint8_t’ was not declared in this scope
  134 |   for (uint8_t c : s) {
      |        ^~~~~~~

Expected behavior

Every project header should be self-contained. src/json_value.h should explicitly include <cstdint> so it compiles regardless of include order.

Actual behavior

Compilation fails unless a previously included header has already defined uint8_t. The current build works only because src/fuzz.cpp includes src/callbacks.h before src/json_value.h, and callbacks.h happens to include <cstdint>.

Impact

This makes json_value.h fragile to use in other tools or tests. Any reordering of includes, or any consumer that includes json_value.h directly, will hit a cryptic compile error. The fix is a one-line addition of #include <cstdint>.

`src/json_value.h` uses `uint8_t` in `escapeAsJsonString` but does not include `<cstdint>`. As a result, any translation unit that includes this header without first including `<cstdint>` (or another header that happens to define it) fails to compile. **Relevant code** File: `src/json_value.h` Line 134 (inside `escapeAsJsonString`): ```cpp for (uint8_t c : s) { ``` The file currently includes `<cstddef>`, `<map>`, `<memory>`, `<optional>`, `<string>`, `<utility>`, `<variant>`, `<vector>`, and `"weaseljson.h"`, but not `<cstdint>`. **Reproduction** Create a minimal source file that includes only this header: ```cpp #include "json_value.h" int main() { return 0; } ``` Compile: ```sh c++ -std=c++20 -Iinclude -Isrc -c repro.cpp ``` Result: ``` src/json_value.h:134:8: error: ‘uint8_t’ was not declared in this scope 134 | for (uint8_t c : s) { | ^~~~~~~ ``` **Expected behavior** Every project header should be self-contained. `src/json_value.h` should explicitly include `<cstdint>` so it compiles regardless of include order. **Actual behavior** Compilation fails unless a previously included header has already defined `uint8_t`. The current build works only because `src/fuzz.cpp` includes `src/callbacks.h` before `src/json_value.h`, and `callbacks.h` happens to include `<cstdint>`. **Impact** This makes `json_value.h` fragile to use in other tools or tests. Any reordering of includes, or any consumer that includes `json_value.h` directly, will hit a cryptic compile error. The fix is a one-line addition of `#include <cstdint>`.
weaselbot was assigned by andrew 2026-06-29 17:33:55 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: weaselab/weaseljson#37