Skip to content

fix(cpp): silence unused-parameter warnings for empty objects#2982

Merged
schani merged 1 commit into
masterfrom
agent/fix-issue-2362
Jul 21, 2026
Merged

fix(cpp): silence unused-parameter warnings for empty objects#2982
schani merged 1 commit into
masterfrom
agent/fix-issue-2362

Conversation

@schani

@schani schani commented Jul 20, 2026

Copy link
Copy Markdown
Member

What was broken

For a JSON Schema empty object ({"type": "object", "additionalProperties": false}), quicktype's C++ target generated from_json/to_json free functions that don't reference all their parameters:

inline void from_json(const json & j, Out& x) {
}

inline void to_json(json & j, const Out & x) {
    j = json::object();
}

from_json uses neither j nor x; to_json doesn't use x. Compiling with -Wextra -Wunused-parameter -Werror (a common strict build configuration) turns these into hard errors, breaking consumer builds.

Root cause

CPlusPlusRenderer.emitClassFunctions (in packages/quicktype-core/src/language/CPlusPlus/CPlusPlusRenderer.ts) always names both parameters when emitting from_json/to_json, but for a class with zero properties nothing in the body ever touches them.

Fix

In emitClassFunctions, when a class has no properties, emit (void)j; (void)x; at the top of from_json's body and (void)x; after j = json::object(); in to_json's body — the standard idiom for silencing unused-parameter warnings while keeping the parameter names (needed to match the function signature) intact.

Test coverage

The existing schema fixture test/inputs/schema/constructor.schema already generates a nested empty class (additionalProperties: false, no properties) via a oneOf union member. The C++ fixture's compile command in test/languages.ts now passes -Werror=unused-parameter, so this fixture fails to compile on unfixed code (reproducing the reported warnings) and compiles cleanly after the fix.

Verification

  • Reproduced the bug locally: node dist/index.js --lang cpp --src-lang schema empty.schema.json -o out.hpp, then compiled the output with g++ -std=c++17 -Wextra -Wunused-parameter -Werror — reproduced all three reported errors (unused j and x in from_json, unused x in to_json) before the fix; no unused-parameter errors after.
  • npm run build passes.
  • Ran the full schema-cplusplus fixture suite locally (QUICKTEST=true FIXTURE=schema-cplusplus script/test) to confirm no regressions across the many C++ renderer option combinations.
  • CI will additionally validate the broader JSON/JSON Schema fixture matrix.

Fixes #2362

🤖 Generated with Claude Code

Empty JSON Schema objects generate C++ from_json/to_json functions
whose j and/or x parameters go unreferenced, tripping
-Wunused-parameter under -Werror. Emit (void)j;/(void)x; for
classes with no properties.

Co-Authored-By: gpt-5.6-sol via pi <noreply@openai.com>
@schani
schani merged commit 24b5c45 into master Jul 21, 2026
28 checks passed
@schani
schani deleted the agent/fix-issue-2362 branch July 21, 2026 00:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

c++ warning unused parameter ‘j’ for empty object

1 participant