1: Sample code that reproduces the problem.
constexpr int object = 1.0;
2: Exact command used to run SDCC on this sample code.
sdcc -mz80 --std=c2y --nostdinc -S bug.c -o bug.asm
3: SDCC version tested.
SDCC 4.6.4 #17064 (Linux), tested 21 October 2026.
4: Observed and expected behaviour.
SDCC exits successfully and emits no diagnostic. A diagnostic is required by
WG14 N3886,
6.7.2 paragraph 6.
An explicit initialiser for a constexpr integer object or sub-object must be an integer constant expression. SDCC accepts 1.0, 1.5 and a floating expression initialising an integer member. The 1.0 example isolates this requirement from representability: its numerical value fits int exactly, but its expression is not an integer constant expression. The integer expression 1 is a valid case.
5: Additional checks.
The sample is silently accepted on Z80, MCS51 default, STM8 default, PDK14 and MOS65C02 in C2Y mode. These are translation and diagnostic checks; no runtime result is claimed.
Compiler Explorer: SDCC 4.6.0, SDCC trunk and GCC 16.2. All three panes use the sample above. The saved source, compiler selections and options were round-trip verified on 21 October 2026. Both SDCC panes use -mz80 --std=c2y; GCC uses -std=c2y -pedantic-errors -fsyntax-only. The public trunk build is r17013, distinct from the local r17064 retest.
| CE compiler | Observed result |
|---|---|
| SDCC 4.6.0 | Accepted silently |
| SDCC trunk r17013 | Accepted silently |
| GCC 16.2 | Rejected with diagnostics |
| Case | Expected | Current SDCC results |
|---|---|---|
constexpr-integer-control.c |
Valid | Accepted silently on all five targets |
constexpr-integer-fraction.c |
Diagnostic required | Accepted silently on all five targets |
constexpr-integer-integral-float.c |
Diagnostic required | Accepted silently on all five targets |
constexpr-integer-member.c |
Diagnostic required | Accepted silently on all five targets |
Please consider the attached candidate bugfix patch authored with Codex. It introduces a new diagnostic message: E_CONSTEXPR_INTEGER: "initialiser for constexpr integer object is not an integer constant expression".
The neighbouring TODO about loss of range or precision in
constExprValueappears to be more closely related to [bugs:#4191] than this bug."warning 158: overflow in implicit constant conversion" is already emitted for integer constant expressions that exceed the range of the
constexprbeing initialised. Missing diagnostics forconstexprinitialisers forbooltype were reported separately as [bugs:#4230].Related
Bugs: #4191
Bugs: #4230
Last edit: Maarten Brock 3 days ago