diff --git a/src/cc65/expr.c b/src/cc65/expr.c index f3003507a..afb5e1960 100644 --- a/src/cc65/expr.c +++ b/src/cc65/expr.c @@ -1133,10 +1133,6 @@ static void Primary (ExprDesc* E) /* Enum or some other numeric constant */ E->Flags = E_LOC_NONE | E_RTYPE_RVAL; E->IVal = Sym->V.ConstVal; - } else if ((Sym->Flags & SC_FUNC) == SC_FUNC) { - /* Function */ - E->Flags = E_LOC_GLOBAL | E_RTYPE_LVAL; - E->Name = (uintptr_t) Sym->Name; } else if ((Sym->Flags & SC_AUTO) == SC_AUTO) { /* Local variable. If this is a parameter for a variadic ** function, we have to add some address calculations, and the @@ -1151,6 +1147,10 @@ static void Primary (ExprDesc* E) E->Flags = E_LOC_STACK | E_RTYPE_LVAL; E->IVal = Sym->V.Offs; } + } else if ((Sym->Flags & SC_FUNC) == SC_FUNC) { + /* Function */ + E->Flags = E_LOC_GLOBAL | E_RTYPE_LVAL; + E->Name = (uintptr_t) Sym->Name; } else if ((Sym->Flags & SC_REGISTER) == SC_REGISTER) { /* Register variable, zero page based */ E->Flags = E_LOC_REGISTER | E_RTYPE_LVAL; diff --git a/test/val/bug1838.c b/test/val/bug1838.c new file mode 100644 index 000000000..ba3c1164f --- /dev/null +++ b/test/val/bug1838.c @@ -0,0 +1,35 @@ +/* Bug 1838 - function parameters declared as function types rather than function pointers */ + +#include + +static int failures = 0; + +typedef int fn_t(int); + +int main(void) +{ + void foo(fn_t*); + fn_t bar; + + foo(bar); + return 0; +} + +void foo(int func(int)) +{ + int n = func(42); + + if (n != 12) { + printf("n = %d, expected: 12\n", n); + ++failures; + } +} + +int bar(int a) +{ + if (a != 42) { + printf("a = %d, expected: 42\n", a); + ++failures; + } + return 12; +}