schemagen C++ keyword allow-list is missing C++20 keywords #18

Closed
opened 2026-06-21 11:26:05 +00:00 by weaselbot · 0 comments
Member

The _CPP_KEYWORDS set in contrib/schemagen/weaseljson_schemagen.py (line 124) does not include several keywords added in C++20. When a JSON schema uses one of these words as a property name, the generated struct contains a C++ keyword as a member name and fails to compile.

Missing keywords include: concept, consteval, constinit, co_await, co_return, co_yield, requires, module, import.

Reproduction schema:

{
  "type": "object",
  "properties": {
    "concept": { "type": "string" }
  }
}

Actual generated code (fails to compile):

struct Root {
  std::optional<std::string> concept;  // "concept"
};

Compiler error (GCC 16 / C++20):

concept.h:20:30: error: C++20 concept definition syntax is 'concept <name> = <expr>'
   20 |   std::optional<std::string> concept;  // "concept"
      |                              ^~~~~~~

Expected behavior: the generator should treat C++20 keywords the same way it treats older C++ keywords and Python keywords, appending a suffix (e.g. concept_) so the generated code compiles.

Impact: schemas that use ordinary English words such as "concept", "requires", or "import" as JSON keys cannot be turned into compilable C++ structs.

The `_CPP_KEYWORDS` set in `contrib/schemagen/weaseljson_schemagen.py` (line 124) does not include several keywords added in C++20. When a JSON schema uses one of these words as a property name, the generated struct contains a C++ keyword as a member name and fails to compile. **Missing keywords include:** `concept`, `consteval`, `constinit`, `co_await`, `co_return`, `co_yield`, `requires`, `module`, `import`. **Reproduction schema:** ```json { "type": "object", "properties": { "concept": { "type": "string" } } } ``` **Actual generated code (fails to compile):** ```cpp struct Root { std::optional<std::string> concept; // "concept" }; ``` Compiler error (GCC 16 / C++20): ``` concept.h:20:30: error: C++20 concept definition syntax is 'concept <name> = <expr>' 20 | std::optional<std::string> concept; // "concept" | ^~~~~~~ ``` **Expected behavior:** the generator should treat C++20 keywords the same way it treats older C++ keywords and Python keywords, appending a suffix (e.g. `concept_`) so the generated code compiles. **Impact:** schemas that use ordinary English words such as "concept", "requires", or "import" as JSON keys cannot be turned into compilable C++ structs.
weaselbot was assigned by andrew 2026-06-21 15:01:45 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: weaselab/weaseljson#18