Menu

#3916 Syntax error if a function type name is the operand of typeof

open
nobody
None
other
5
2026-01-08
2026-01-08
No

Function type names cannot be used as the operand of the typeof operator.
Clang and LLVM permit it: https://godbolt.org/z/Txo3Ez3K9
I would expect SDCC to permit it too.
If this is not addressed then this method of declaring pointers to optional-qualified function types will be unavailable to SDCC users, e.g. _Optional typeof (int (int)) *opf;

  1. Sample code that reproduces the problem:
int foo(int);
typeof (int (int)) foo; // syntax error
typeof (int (int)) *pfoo; // syntax error
typeof (int (*)(int)) pfoo; // OK
  1. Exact command used to run SDCC on this sample code:
    sdcc bug.c

  2. SDCC version tested:
    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.15 #15966 (Linux)
    published under GNU General Public License (GPL)

Also tested version 4.5.0 at Compiler Explorer.

  1. Copy of the error message or incorrect output:
    bug.c:2: error 1: Syntax error, declaration ignored at ')'
    bug.c:2: warning 278: return type of function omitted, assuming int
    Internal error: validateLink failed in SPEC_SCLS(sym->etype) @ SDCCmem.c:420: expected SPECIFIER, got null-link

Discussion


Log in to post a comment.