Menu

#3955 Inconsistent production of warnings about optional-qualified return types

open
nobody
None
Front-end
5
2026-03-23
2026-03-23
No

1: Sample code that reproduces the problem.

// invalid: qualified type is not a referenced type
_Optional int froi (float); // types other than the referenced type of a
                            // pointer type shall not be optional-qualified
_Optional int (*pfroi) (float); // no warning

2: Exact command used to run SDCC on this sample code

sdcc --std=c23 -c /work/bug4.c

3: SDCC version tested (type "sdcc -v" to find it)

SDCC : mcs51/z80/z180/r2k/r2ka/r3ka/r4k/r5k/r6k/sm83/tlcs90/ez80/z80n/r800/ds390/pic16/pic14/TININative/ds400/hc08/s08/stm8/pdk13/pdk14/pdk15/mos6502/mos65c02/f8/f8l TD- 4.5.21 #16327 (Linux)

4: Copy of the error message or incorrect output, or a clear description of the observed versus expected behavior.

/work/bug4.c:2: error 351: types other than the referenced type of a pointer type shall not be optional-qualified

The current draft of the _Optional technical specification states the following constraint in the subsection on "Function declarators" (6.5.3.3):

A function declarator shall not specify a return type that is optional-qualified.

I guess it's open to debate whether that should be a constraint or merely recommended practice, given that Clang and GCC report "warning: 'const' type qualifier on return type has no effect" or "warning: type qualifiers ignored on function return type" respectively when invoked with -Wextra (or equivalent). It might therefore be more useful for users of SDCC to produce a warning for any of const, volatile or _Optional qualified return type (which would also satisfy the current wording of the TS if the warning were enabled by default).

However, what does not seem debatable is that froi and *pfroi have the same return type, therefore I would expect a diagnostic message for both declarations or for neither.

Discussion


Log in to post a comment.

MongoDB Logo MongoDB