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:
@@ -519,6 +519,7 @@ int Statement (int* PendingToken)
|
|||||||
{
|
{
|
||||||
ExprDesc Expr;
|
ExprDesc Expr;
|
||||||
int GotBreak;
|
int GotBreak;
|
||||||
|
CodeMark Start;
|
||||||
|
|
||||||
/* Assume no pending token */
|
/* Assume no pending token */
|
||||||
if (PendingToken) {
|
if (PendingToken) {
|
||||||
@@ -590,6 +591,8 @@ int Statement (int* PendingToken)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
/* Remember the current code position */
|
||||||
|
Start = GetCodePos ();
|
||||||
/* Actual statement */
|
/* Actual statement */
|
||||||
ExprWithCheck (hie0, &Expr);
|
ExprWithCheck (hie0, &Expr);
|
||||||
/* Load the result only if it is an lvalue and the type is
|
/* 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)) {
|
if (ED_IsLVal (&Expr) && IsQualVolatile (Expr.Type)) {
|
||||||
ExprLoad (CF_NONE, &Expr);
|
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);
|
CheckSemi (PendingToken);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user