1: Sample code that reproduces the problem.
void foo(_Optional const char (*paocc)[64])
{
static_assert(_Generic(*paocc,
const char *: 1,
default: 0));
}
2: Exact command used to run SDCC on this sample code
sdcc --stack-auto --std=c23 -c decay.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.24 #16456 (Mac OS X ppc)
published under GNU General Public License (GPL)
4: Copy of the error message or incorrect output, or a clear description of the observed versus expected behavior.
Incorrect output:
decay.c:5: warning 246: static assertion failed
The code above is a minimised version of one of the examples in the 'Conversion' section of the _Optional technical specification, which also gives the following rule:
If an expression that has type
array of type'' is implicitly converted to an expression with typepointer to type'' that points to the initial element of the array object, any _Optional qualifier that would otherwise have applied to the referenced type of the resultant pointer type is removed.
In this example, array-to-pointer conversion should remove the _Optional qualifier but not the const qualifier from the referenced type of the resultant pointer type.
The issue also manifests when the array whose type decays to a pointer is a member of a struct: