SDCC currently does not give an error on returning an expression of type void in a function returning void, even though the standard does not allow it ("A return statement with an expression shall not appear in a function whose return type is void." in section 6.8.6.4 of the ISO C17 standard):
static void attr_rtx (char *, char *);
static char *attr_string (char *);
static void
attr_eq (char *name, char *value)
{
return attr_rtx (attr_string (name), attr_string (value));
}
Apparently allowing this is a GCC extension. Unfortunately, SDCC doesn't handle it fully that way either, as it results in a temporary of size zero, which in turn can cause problems in the backends (e.g. a segfault in the pdk14 backend).
IMO, the easiest solution is to just give an error on such a return statement.
Philipp
Looking at SDCCast.c, it seems SDCC intentionally allows this.
So we're back to the question: Fix it, so it is handled like in GCC, or just give an error.
Philipp
Diff:
Looks like this has been fixed since. As of [r13822], we get the error when using --std-cXX, and for --std-sdccXX, we generate working code.
Related
Commit: [r13822]