You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
C++ constant string fields are emitted as constexpr std::string, which fails to compile once the value is longer than 15 characters #101
Two places in Coder/Languages/CppGenerator.cs write constexpr without checking the type:
:794 (SpellStorage for FieldDeclaration)
:616 (GenerateField for a constant VariableDeclaration)
string maps to std::string (line 48). A constant string field therefore comes out as static constexpr std::string / inline constexpr std::string.
Failure scenario
newFieldDeclaration("Name","string"){IsStatic=true,IsConstant=true,InitialValue=Literal.Text("a string longer than fifteen chars")}
Inside a struct this generates:
staticconstexpr std::string Name = "a string longer than fifteen chars";
g++ 13.3 with -std=c++20 rejects it: "is not a constant expression because it refers to a result of 'operator new'".
Short strings compile only because libstdc++'s small-string buffer holds them. Whether the output builds depends on the literal's length, and it also varies by standard library. Under C++17, constexpr std::string is never valid.
I reproduced this with the built ktsu.Coder.dll and g++ 13.3.
Suggested fix / acceptance criteria
For a type that isn't a literal type (at least std::string), write one of:
Priority: Medium. The generated C++ fails to compile for any constant string longer than the SSO buffer (and for every one under C++17). The failure is loud, not silent, but it depends on the length of the value, so it is easy to miss in tests.
Area / suggested assignee: C++ generator, CppGenerator.cs (SpellStorage and the constant path in GenerateField). Owner: @matt-edmondson
Next step: emit static inline const std::string or constexpr std::string_view for non-literal types, and add a long-string case to CppGeneratedSourceCompilesTests.
Activity
matt-edmondson commentedon Sep 27, 2026
Triage
CppGenerator.cs(SpellStorageand the constant path inGenerateField). Owner: @matt-edmondsonstatic inline const std::stringorconstexpr std::string_viewfor non-literal types, and add a long-string case toCppGeneratedSourceCompilesTests.Generated by Claude Code