Movatterモバイル変換


[0]ホーム

URL:


CodeQL documentation
CodeQL resources

Use of goto

ID: cpp/use-of-gotoKind: problemSecurity severity: Severity: warningPrecision: highTags:   - maintainability   - readability   - language-featuresQuery suites:   - cpp-security-and-quality.qls

Click to see the query in the CodeQL repository

Use ofgoto statements makes code more difficult to understand and maintain. Consequently, the use ofgoto statements is deprecated except as a mechanism for breaking out of multiple nested loops, or jumping to error-handling code at the end of a function. This rule identifies complex (and therefore hard to understand) uses ofgoto statements. Function bodies that include multiplegoto statements that jump forward and multiplegoto statements that jump backwards are highlighted.

Recommendation

In most cases the code can be rewritten and/or rearranged by:

  • using structured control flow constructs, such asif,while, andfor;

  • usingbreak orcontinue to stop a loop iteration early; or

  • usingreturn to exit a function earlyThegoto statement may be the best solution for breaking out of deeply nested loops, or for jumping to error handling code, without adversely affecting the readability of the function. Such uses will not be flagged by this rule.

References


[8]ページ先頭

©2009-2025 Movatter.jp