SonarSource Rules
  • Products

    In-IDE

    Code Quality and Security in your IDE with SonarQube Ide

    IDE extension that lets you fix coding issues before they exist!

    Discover SonarQube for IDE

    SaaS

    Code Quality and Security in the cloud with SonarQube Cloud

    Setup is effortless and analysis is automatic for most languages

    Discover SonarQube Cloud

    Self-Hosted

    Code Quality and Security Self-Hosted with SonarQube Server

    Fast, accurate analysis; enterprise scalability

    Discover SonarQube Server
  • SecretsSecrets
  • ABAPABAP
  • AnsibleAnsible
  • ApexApex
  • AzureResourceManagerAzureResourceManager
  • CC
  • C#C#
  • C++C++
  • CloudFormationCloudFormation
  • COBOLCOBOL
  • CSSCSS
  • DartDart
  • DockerDocker
  • FlexFlex
  • GitHub ActionsGitHub Actions
  • GoGo
  • HTMLHTML
  • JavaJava
  • JavaScriptJavaScript
  • JSONJSON
  • JCLJCL
  • KotlinKotlin
  • KubernetesKubernetes
  • Objective CObjective C
  • PHPPHP
  • PL/IPL/I
  • PL/SQLPL/SQL
  • PythonPython
  • RPGRPG
  • RubyRuby
  • RustRust
  • ScalaScala
  • ShellShell
  • SwiftSwift
  • TerraformTerraform
  • TextText
  • TypeScriptTypeScript
  • T-SQLT-SQL
  • VB.NETVB.NET
  • VB6VB6
  • XMLXML
  • YAMLYAML
C++

C++ static code analysis

Unique rules to find Bugs, Vulnerabilities, Security Hotspots, and Code Smells in your C++ code

  • All rules 674
  • Vulnerability13
  • Bug139
  • Security Hotspot19
  • Code Smell503

  • Quick Fix 91
Filtered: 118 rules found
based-on-misra
    Impact
      Clean code attribute
        1. "goto" should jump to labels declared later in the same function

           Code Smell
        2. The global namespace should only contain "main", namespace declarations, and "extern" C declarations

           Code Smell
        3. "<time.h>" should not be used

           Code Smell
        4. "atof", "atoi" and "atol" from <stdlib.h> should not be used

           Bug
        5. "<stdio.h>" should not be used in production code

           Code Smell
        6. "<signal.h>" should not be used

           Bug
        7. "errno" should not be used

           Code Smell
        8. Dynamic heap memory allocation should not be used

           Bug
        9. "setjmp" and "longjmp" should not be used

           Code Smell
        10. Reserved identifiers should not be defined or declared

           Code Smell
        11. Lines starting with "#" should contain valid preprocessing directives

           Bug
        12. Only standard forms of the "defined" directive should be used

           Code Smell
        13. Preprocessor operators "#" and "##" should not be used

           Code Smell
        14. Macros used in preprocessor directives should be defined before use

           Bug
        15. Function-like macros should not be invoked without all of their arguments

           Bug
        16. Function-like macros should not be used

           Code Smell
        17. "#undef" should be used with caution

           Code Smell
        18. Macros should not be #define'd or #undef'd within a block

           Code Smell
        19. "#include" directives should be followed by either <filename> or "filename" sequences

           Bug
        20. Non-standard characters should not occur in header file names in "#include" directives

           Bug
        21. Unions should not be used

           Code Smell
        22. The address of an automatic object should not be assigned to another object that may persist after the first object has ceased to exist

           Bug
        23. Array type function arguments should not decay to pointers

           Code Smell
        24. Object declarations should contain no more than 2 levels of pointer indirection

           Code Smell
        25. Function names should be used either as a call with a parameter list or with the "&" operator

           Code Smell
        26. Function exit paths should have appropriate return values

           Bug
        27. Parameters in a function prototype should be named

           Code Smell
        28. Recursion should not be used

           Code Smell
        29. Loops should not have more than one "break" or "goto" statement

           Code Smell
        30. The right-hand operands of && and || should not contain side effects

           Code Smell
        31. "continue" should not be used

           Code Smell
        32. "goto" statement should not be used

           Code Smell
        33. Non-empty statements should change control flow or have at least one side-effect

           Bug
        34. Unused type declarations should be removed

           Code Smell
        35. The three expressions of a "for" statement should only be concerned with loop control

           Code Smell
        36. Increment (++) and decrement (--) operators should not be used in a method call or mixed with other operators in an expression

           Code Smell
        37. Comma operator should not be used

           Code Smell
        38. Unary minus should not be applied to an unsigned expression

           Bug
        39. Bitwise operators should not be applied to signed operands

           Bug
        40. "enum" values should not be used as operands to built-in operators other than [ ], =, ==, !=, unary &, and the relational operators <, <=, >, >=

           Code Smell
        41. "bool" expressions should not be used as operands to built-in operators other than =, &&, ||, !, ==, !=, unary &, and the conditional operator

           Code Smell
        42. C-style and functional notation casts should not be used

           Code Smell
        43. Operands of "&&" and "||" should be primary (C) or postfix (C++) expressions

           Code Smell
        44. Boolean operations should not have numeric operands, and vice versa

           Bug
        45. Objects with integer type should not be converted to objects with pointer type

           Bug
        46. Pointer conversions should be restricted to a safe subset

           Bug
        47. Function pointers should not be converted to any other type

           Bug
        48. Constants of unsigned type should have a "U" suffix

           Code Smell
        49. Results of ~ and << operations on operands of underlying types unsigned char and unsigned short should immediately be cast to the operand's underlying type

           Bug
        50. Signed and unsigned types should not be mixed in expressions

           Code Smell
        51. "enum" members with implicit values should not collide with other enumerators

           Code Smell
        52. Variables should be initialized before use

           Bug
        53. Braces should be used to indicate and match the structure in the non-zero initialization of arrays and structures

           Code Smell
        54. Array declarations should include an explicit size specification

           Code Smell
        55. Literal suffix "L" for long integers shall be upper case

           Code Smell
        56. String literals with different prefixes should not be concatenated

           Bug
        57. Bit fields should be declared with appropriate types

           Code Smell
        58. typedefs that indicate size and signedness should be used in place of the basic types

           Code Smell
        59. Appropriate char types should be used for character and integer values

           Code Smell
        60. Identifiers should not be longer than 31 characters

           Code Smell
        61. Digraphs should not be used

           Code Smell
        62. Trigraphs should not be used

           Code Smell
        63. Only escape sequences defined in the ISO C standard should be used

           Bug
        64. All uses of the #pragma directive should be documented

           Code Smell
        65. Source code should only use /* ... */ style comments

           Code Smell
        66. Macro arguments should not contain preprocessing directives

           Bug
        67. Names of well-known C standard library macros and functions should not be used as identifiers

           Code Smell
        68. Relational and subtraction operators should not be used with pointers to different arrays

           Bug
        69. Pointer and reference local variables should be "const" if the corresponding object is not modified

           Code Smell
        70. Unevaluated operands should not have side effects

           Code Smell
        71. User-defined types should not be passed as variadic arguments

           Bug
        72. Keywords shall not be used as macros identifiers

           Code Smell
        73. "void *" should not be used in typedefs, member variables, function parameters or return type

           Code Smell
        74. "default" clauses should be first or last

           Code Smell
        75. Integral operations should not overflow

           Bug
        76. Non-exception types should not be thrown

           Code Smell
        77. Member variables should not be "protected"

           Code Smell
        78. Conditionally executed code should be reachable

           Bug
        79. Octal and hexadecimal escape sequences should be terminated

           Code Smell
        80. Flexible array members should not be declared

           Code Smell
        81. Line-splicing should not be used in "//" comments

           Bug
        82. Single-bit named bit fields should not be of a signed type

           Bug
        83. "for" loop counters should not have essentially floating type

           Bug
        84. "goto" statements should not be used to jump into blocks

           Code Smell
        85. Pointers should not be cast to integral types

           Bug
        86. All code should be reachable

           Bug
        87. Pre-defined macros should not be defined, redefined or undefined

           Code Smell
        88. "explicit" should be used on single-parameter constructors and conversion operators

           Code Smell
        89. Multiple variables should not be declared on the same line

           Code Smell
        90. Octal values should not be used

           Code Smell
        91. "switch" statements should have "default" clauses

           Code Smell
        92. "if" statements should be preferred over "switch" when simpler

           Code Smell
        93. Switch cases should end with an unconditional "break" statement

           Code Smell
        94. "for" loop stop conditions should be invariant

           Code Smell
        95. "operator delete" should be written along with "operator new"

           Bug
        96. "if ... else if" constructs should end with "else" clauses

           Code Smell
        97. Sections of code should not be commented out

           Code Smell
        98. Floating point numbers should not be tested for equality

           Bug
        99. "switch" statements should not contain non-case labels

           Code Smell
        100. Control structures should use curly braces

           Code Smell
        101. Unused function parameters should be removed

           Code Smell
        102. Unused functions and methods should be removed

           Code Smell
        103. Assignments should not be made from within conditions

           Code Smell
        104. Variables should not be shadowed

           Code Smell
        105. Empty statements should be removed

           Code Smell
        106. "/*" and "//" should not be used within comments

           Code Smell
        107. Unused labels should be removed

           Code Smell
        108. "<cstdio>" should not be used

           Code Smell
        109. "<ctime>" should not be used

           Code Smell
        110. Empty throws ("throw;") should only be used in the compound statements of catch handlers

           Bug
        111. Function templates should not be specialized

           Code Smell
        112. Pure "virtual" functions should not override non-pure "virtual" functions

           Code Smell
        113. Virtual functions should be declared with the "virtual" keyword

           Code Smell
        114. Accessible base classes should not be both "virtual" and non-virtual in the same hierarchy

           Bug
        115. Classes should not be derived from virtual bases

           Code Smell
        116. A function should have a single point of exit at the end of the function

           Code Smell
        117. "using namespace" directives should not be used in header files

           Code Smell
        118. "using-directives" should not be used

           Code Smell

        Non-empty statements should change control flow or have at least one side-effect

        intentionality - clear
        reliability
        Bug
        • cwe
        • based-on-misra
        • unused

        Statements with no side effects and no change of control flow do not contribute to the functionality of the code and can indicate a programming error.

        Why is this an issue?

        How can I fix it?

        More Info

        When writing code, it is important to ensure that each statement serves a purpose and contributes to the overall functionality of the program. When they have no side effects or do not change the control flow, they can either indicate a programming error or be redundant:

        1. The code does not behave as intended: The statements are expected to have an effect but they do not. This can be caused by mistyping, copy-and-paste errors, etc.
        2. The statements are residual after a refactoring.

        Exceptions

        The rule does not raise an issue on statements containing only a semicolon (;).

          Available In:
        • SonarQube IdeCatch issues on the fly,
          in your IDE
        • SonarQube CloudDetect issues in your GitHub, Azure DevOps Services, Bitbucket Cloud, GitLab repositories
        • SonarQube ServerAnalyze code in your
          on-premise CI
          Developer Edition
          Available Since
          9.1

        © 2008-2025 SonarSource SA. All rights reserved.

        Privacy Policy | Cookie Policy | Terms of Use