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/C++: long.MinValue is written as -9223372036854775808LL, which gcc rejects, and int.MinValue becomes a long #247
CFamilyGenerator.FormatLong appends LL to the decimal digits (CFamilyGenerator.cs#L215). C and C++ have no negative integer literals. -9223372036854775808LL is unary minus applied to 9223372036854775808LL, and that does not fit in long long. gcc reports "integer constant is so large that it is unsigned". The diagnostic is an error under -std=c11 -pedantic-errors, and under -Werror for C++. Those are the flags the CGeneratedSourceCompilesTests / CppGeneratedSourceCompilesTests harnesses already use. The literal reaches FormatLong from LanguageGeneratorBase.cs#L180-L182.
int.MinValue has a related problem. It is written as a bare -2147483648 (LanguageGeneratorBase.cs#L164-L166). In C and C++, 2147483648 is a long, so the negated value is a long, not an int. An inferred C++ local (auto y = -2147483648;) then deduces long. That is the same width drift #151 fixed for other literals.
C#, Rust, Go, Python and JavaScript all handle the minimum values. LongLiteralTests covers long.MinValue only for JavaScript (#168).
varf=newFunctionDeclaration("lowest"){ReturnType="long"};f.Body.Add(newVariableDeclaration("v","long",newLiteralExpression<long>(long.MinValue)));f.Body.Add(newReturnStatement(newVariableReference("v")));newCGenerator().Generate(f);// long long v = -9223372036854775808LL;newCppGenerator().Generate(f);// long long v = -9223372036854775808LL;
gcc -std=c11 -Wall -Wextra -pedantic-errors -c gen.c
gen.c:3:20: error: integer constant is so large that it is unsigned
g++ -std=c++20 -Wall -Wextra -pedantic -Werror -c gen.cpp
gen.cpp:3:20: error: integer constant is so large that it is unsigned [-Werror]
Suggested fix / acceptance criteria
C and C++ write long.MinValue as (-9223372036854775807LL - 1), or as LLONG_MIN/INT64_MIN with the header added through RequiredImports.
C and C++ write int.MinValue as (-2147483647 - 1), or INT_MIN, so it stays an int.
LongLiteralTests gains C and C++ cases for long.MinValue and int.MinValue, and the generated source compiles under the existing harness flags.
Priority: Medium. A long.MinValue literal makes the generated C/C++ fail to compile under the flags the compile harnesses already use, and int.MinValue silently widens to long. Both come from boundary values only, and the fix is a few lines in CFamilyGenerator plus tests.
Area / suggested assignment: C-family generators (CFamilyGenerator.FormatLong, and int literal formatting in LanguageGeneratorBase). Tests go in LongLiteralTests and the C/CppGeneratedSourceCompilesTests harnesses.
Activity
matt-edmondson commentedon Oct 18, 2026
Triage
long.MinValueliteral makes the generated C/C++ fail to compile under the flags the compile harnesses already use, andint.MinValuesilently widens tolong. Both come from boundary values only, and the fix is a few lines inCFamilyGeneratorplus tests.CFamilyGenerator.FormatLong, and int literal formatting inLanguageGeneratorBase). Tests go inLongLiteralTestsand theC/CppGeneratedSourceCompilesTestsharnesses.long.MinValuefor JavaScript).Generated by Claude Code