Movatterモバイル変換


[0]ホーム

URL:


CodeQL documentation
CodeQL resources

Empty branch of conditional

ID: cpp/empty-blockKind: problemSecurity severity: Severity: recommendationPrecision: very-highTags:   - reliability   - readabilityQuery suites:   - cpp-security-and-quality.qls

Click to see the query in the CodeQL repository

This rule finds empty blocks that occur as a branch of a conditional or as a loop body. This may indicate badly maintained code or a defect due to an unhandled case. It is common to find commented-out code in the empty body. Commented-out code is discouraged and is a source of defects and maintainability issues.

Recommendation

If the conditional or loop is useless, remove it.

If only the else-branch of anif statement is empty, omit it. If the then-branch is empty, invert the sense of the condition.

Example

voidf(inti){if(i==10);//empty then block...//won't be part of the if statementif(i==12){...}else{//empty else block, most likely a mistake}}

[8]ページ先頭

©2009-2025 Movatter.jp