diff --git a/src/cc65/stmt.c b/src/cc65/stmt.c index ad9892707..44a98072d 100644 --- a/src/cc65/stmt.c +++ b/src/cc65/stmt.c @@ -519,6 +519,7 @@ int Statement (int* PendingToken) { ExprDesc Expr; int GotBreak; + CodeMark Start; /* Assume no pending token */ if (PendingToken) { @@ -590,6 +591,8 @@ int Statement (int* PendingToken) break; default: + /* Remember the current code position */ + Start = GetCodePos (); /* Actual statement */ ExprWithCheck (hie0, &Expr); /* Load the result only if it is an lvalue and the type is @@ -598,6 +601,12 @@ int Statement (int* PendingToken) if (ED_IsLVal (&Expr) && IsQualVolatile (Expr.Type)) { ExprLoad (CF_NONE, &Expr); } + /* If the statement didn't generate code, and is not of type + * void, emit a warning + */ + if (GetCodePos () == Start && !IsTypeVoid (Expr.Type)) { + Warning ("Statement has no effect"); + } CheckSemi (PendingToken); } }