mirror of
https://github.com/cc65/cc65.git
synced 2024-11-19 06:31:31 +00:00
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
This commit is contained in:
parent
3a0edbff75
commit
08eb9b7b0e
@ -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);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user