From 500887ec23e57cd2c4d2db88f3996530eb97ed4f Mon Sep 17 00:00:00 2001 From: Kugel Fuhr <98353208+kugelfuhr@users.noreply.github.com> Date: Sat, 17 May 2025 17:18:05 +0200 Subject: [PATCH] Fix #2599. The compiler handled all functions returning an int but without a "return" statement by silently adding "return 0" instead of emitting a warning. This is the desired behavior for the "main" function in C99 and above, but the compiler applied it to all functions. --- src/cc65/function.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/cc65/function.c b/src/cc65/function.c index fed0349dd..3123079d3 100644 --- a/src/cc65/function.c +++ b/src/cc65/function.c @@ -636,7 +636,9 @@ void NewFunc (SymEntry* Func, FuncDesc* D) /* If this is the main function in a C99 environment returning an int, ** let it always return zero. Otherwise output a warning. */ - if (IS_Get (&Standard) >= STD_C99 && GetUnqualRawTypeCode (ReturnType) == T_INT) { + if (F_IsMainFunc (CurrentFunc) && + IS_Get (&Standard) >= STD_C99 && + GetUnqualRawTypeCode (ReturnType) == T_INT) { g_getimmed (CF_INT | CF_CONST, 0, 0); } else if (IS_Get (&WarnReturnType)) { Warning ("Control reaches end of non-void function [-Wreturn-type]");