Spell a mutable static C++ field inline static inside a type - #88
Merged
Merged
Conversation
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
|
This was referenced Sep 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Fixes #80
What changed
CppGenerator.SpellStoragenow writesinline staticfor a non-const static field declared inside a type. At namespace scope it still writesstatic. 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 isinline.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
ISO C++ forbids in-class initialization of non-const static member 'Cfg::limit'. With the fix, it passes.🤖 Generated with Claude Code
https://claude.ai/code/session_012B4b6sZaZ7tFJzNvax1B89
Generated by Claude Code