From 08eb9b7b0e2d25137a17220a4eaa0c7d53bac222 Mon Sep 17 00:00:00 2001 From: cuz Date: Sat, 5 Jun 2004 12:56:51 +0000 Subject: [PATCH] Check for and warn on statements that don't have an effect git-svn-id: svn://svn.cc65.org/cc65/trunk@3097 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- src/cc65/stmt.c | 9 +++++++++ 1 file changed, 9 insertions(+) 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); } } -- 2.39.5