Empty statements, i.e. ;, are usually introduced by mistake, for example because:
- It was meant to be replaced by an actual statement, but this was forgotten.
- There was a typo which lead the semicolon to be doubled, i.e.
;;.
Noncompliant Code Example
var x = 1;; // Noncompliant
var foo = function() {
;
};
Compliant Solution
var x = 1;
var foo = function() { };
See
- MISRA C:2004, 14.3 - Before preprocessing, a null statement shall only occur on a line by itself; it may be followed by a comment provided that
the first character following the null statement is a white-space character.
- MISRA C++:2008, 6-2-3 - Before preprocessing, a null statement shall only occur on a line by itself; it may be followed by a comment, provided
that the first character following the null statement is a white-space character.
- CERT, MSC12-C. - Detect and remove code that has no effect or is never
executed
- CERT, MSC12-CPP. - Detect and remove code that has no effect
- CERT, MSC51-J. - Do not place a semicolon immediately following an if, for,
or while condition
- CERT, EXP15-C. - Do not place a semicolon on the same line as an if, for,
or while statement