Skip to content

Spell a mutable static C++ field inline static inside a type - #88

Merged
matt-edmondson merged 1 commit into
mainfrom
fix/80-cpp-inline-static-fields
Sep 27, 2026
Merged

matt-edmondson merged 1 commit into
mainfrom
fix/80-cpp-inline-static-fields

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Fixes #80

What changed

  • CppGenerator.SpellStorage now writes inline static for a non-const static field declared inside a type. At namespace scope it still writes static. The generator always gives a field an initialiser (its value, or {}), and C++ allows an in-class initialiser on a non-const static member only when the member is inline.
  • Added CppGeneratedSourceCompilesTests.AMutableStaticFieldCompilesInsideAClass. It compiles a struct with two mutable static fields, one initialised and one not, using the C++ compiler found on PATH, and has a driver that reads and writes both.

Verification

  • Without the fix, the new test fails with g++: ISO C++ forbids in-class initialization of non-const static member 'Cfg::limit'. With the fix, it passes.
  • Full suite: 906/906 pass.

🤖 Generated with Claude Code

https://claude.ai/code/session_012B4b6sZaZ7tFJzNvax1B89


Generated by Claude Code

Every field is written with an initialiser, and ISO C++ forbids one on a
non-const static data member unless it is inline, so a class with a mutable
static field never compiled. Fixes #80.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012B4b6sZaZ7tFJzNvax1B89
@sonarqubecloud

Copy link
Copy Markdown

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++ generator emits non-const static data members with in-class initializers (static int count = 0;), which doesn't compile

2 participants