Menu ▾ ▴

#4215 Decimal floating literal suffixes bypass unsupported-type and hexadecimal-literal diagnostics

open
nobody
None
Front-end
5
2026-10-24
2026-10-24
No

1: Sample code that reproduces the problem.

float x = 0x1p0df;

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 #17068 (Linux), tested 23 October 2026.

4: Observed and expected behaviour.

SDCC exits successfully without emitting a diagnostic. N3886 6.4.5.3 paragraph 2 prohibits df, dd, dl, DF, DD and DL on a hexadecimal floating literal. A diagnostic is required.

The decimal form float x = 1.0df; is also silently accepted. The same paragraph requires a floating suffix to specify a type provided by the implementation. SDCC reports error 276, decimal floating-point numbers are not supported, for _Decimal32 x;, _Decimal64 x; and _Decimal128 x;. It should also diagnose literals whose suffix denotes those unsupported types.

All six suffixes are accepted silently on both decimal and hexadecimal floating literals. The unsupported decimal type declarations are diagnosed on the same targets and in the same language modes.

Reference: N3886, 6.4.5.3 paragraphs 2 and 6.

5: Additional checks.

The twelve literal variants compile silently on Z80, MCS51, STM8, PDK14 and MOS65C02 in C23 and C2Y: 120 invalid checks. Valid 1.0f and 0x1p0f cases compile silently on all five targets.

sdcc -mz80 --std=c2y --nostdinc -E bug.c preserves 1.0df unchanged. This acceptance therefore occurs after preprocessing. For float x = 1.0df;, Z80 assembly initialises x with bytes 00 00 80 3f, the binary float representation of 1.0.

The same suffix handling also permits 1.0df with a standard float operand in multiplication, addition, relational comparison, equality comparison, conditional expressions and compound assignment. constexpr float x = 1.0df; also compiles silently. These seven variants reproduce on all five targets in C2Y (35 checks). They violate the corresponding decimal/standard floating mixing and constexpr constraints, but share the literal-suffix defect; they are not seven proposed independent bugs. Unsupported decimal declarations prevent isolating an independent mixed-type checker from this literal-handling issue.

GCC 13.3.0 with -std=c2x -pedantic-errors -fsyntax-only rejects the hexadecimal df suffix. It accepts 1.0df, because its target provides decimal floating types; that acceptance is not a reference for SDCC's unsupported-type constraint. GCC 16.2 and Clang were not tested.

Discussion


Log in to post a comment.