Menu

#3962 Parameter is not taken as having the unqualified version of its declared type in _Generic

open
nobody
None
other
5
6 days ago
7 days ago
No

1: Sample code that reproduces the problem.

int f1(const int);
_Static_assert(_Generic(f1, int (*)(volatile int):1, default: 0));

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

sdcc -c --std=c23

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

SDCC : mcs51/z80/z180/r2k/r2ka/r3ka/sm83/tlcs90/ez80_z80/z80n/r800/ds390/pic16/pic14/TININative/ds400/hc08/s08/stm8/pdk13/pdk14/pdk15/mos6502/mos65c02/f8 TD- 4.5.0 #15242 (Linux)

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

<source>:2: warning 246: static assertion failed

It is incorrect because the ISO C23 standard says (6.5.2.1 "Generic selection"):

If a generic selection has a generic association with a type name that is compatible with the type of the controlling expression, then the result expression of the generic selection is the expression in that generic association

and (6.7.7.4 "Function declarators"):

In the determination of type compatibility and of a composite type, each parameter declared with function or array type is taken as having the adjusted type and each parameter declared with qualified type is taken as having the unqualified version of its declared type.

See https://www.open-std.org/JTC1/SC22/WG14/www/docs/n3220.pdf

Discussion

  • Benedikt Freisen

    (comment copied from a different bug ticket)

    Can you retry with sdcc -c --std=c23 --stack-auto or sdcc -c --std=c23 -mz80?

    The observed behavior can potentially be explained with SDCC's default settings:

    For historical reasons, the default target -mmcs51 generates non-reeantrant function code, unless --stack-auto is specified. It then compares qualified function types, because it must not ignore (explicit or implicit) address space qualifiers. See also [feature-requests:#948], which addresses this unintuitiveness.

     

    Related

    Feature Requests: #948

  • Christopher Bazley

    Can you retry with sdcc -c --std=c23 --stack-auto or sdcc -c --std=c23 -mz80?

    No problem. The static assertion still fails (for both configurations) though: https://godbolt.org/z/144EYqjYq

    I expected that the answer might be something to do with address space qualifiers. There's no need for that to affect treatment of standard qualifiers though (or new qualifiers that have similar semantics to the standard qualifiers, like _Optional).

     

Log in to post a comment.

MongoDB Logo MongoDB