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
 
Tags
    Impact
      Clean code attribute
        1. "goto" should jump to labels declared later in the same function

           Code Smell
        2. The name "main" should not be used for any function other than the global "main" function

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

           Code Smell
        4. Pointer and reference parameters should be "const" if the corresponding object is not modified

           Code Smell
        5. A variable which is not modified shall be const qualified

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

           Code Smell
        7. "<stdio.h>" should not be used in production code

           Code Smell
        8. "offsetof" macro should not be used

           Code Smell
        9. "errno" should not be used

           Code Smell
        10. "setjmp" and "longjmp" should not be used

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

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

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

           Code Smell
        14. There shall be at most one occurrence of the # or ## operators in a single macro definition

           Code Smell
        15. In the definition of a function-like macro, each instance of a parameter shall be enclosed in parentheses, unless it is used as the operand of # or ##

           Code Smell
        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 in a file should only be preceded by other preprocessor directives or comments

           Code Smell
        20. Unions should not be used

           Code Smell
        21. Array type function arguments should not decay to pointers

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

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

           Code Smell
        24. Parameters in a function prototype should be named

           Code Smell
        25. Recursion should not be used

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

           Code Smell
        27. Functions should not be defined with a variable number of arguments

           Code Smell
        28. Switch statement conditions should not have essentially boolean type

           Code Smell
        29. The comma operator, "&&", and "||" should not be overloaded

           Code Smell
        30. Switch labels should not be nested inside non-switch blocks

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

           Code Smell
        32. "continue" should not be used

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

           Code Smell
        34. Unused type declarations should be removed

           Code Smell
        35. A loop-control-variable other than the loop-counter which is modified in statement shall have type bool

           Code Smell
        36. The loop-counter should be modified by one of: --, ++, -=n, or +=n; where n remains constant for the duration of the loop

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

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

           Code Smell
        39. Comma operator should not be used

           Code Smell
        40. The unary "&" operator should not be overloaded

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

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

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

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

           Code Smell
        45. Limited dependence should be placed on operator precedence

           Code Smell
        46. A cast shall not remove any const or volatile qualification from the type of a pointer or reference

           Code Smell
        47. Constants of unsigned type should have a "U" suffix

           Code Smell
        48. Signed and unsigned types should not be mixed in expressions

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

           Code Smell
        50. Braces should be used to indicate and match the structure in the non-zero initialization of arrays and structures

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

           Code Smell
        52. If a function has internal linkage then all re-declarations shall include the static storage class specifer

           Code Smell
        53. Objects or functions with external linkage shall be declared in a header file

           Code Smell
        54. Functions should not be declared at block scope

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

           Code Smell
        56. Bit fields should be declared with appropriate types

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

           Code Smell
        58. The first operand of a conditional operator should have type bool

           Code Smell
        59. The condition of an if-statement and the condition of an iteration-statement shall have type bool

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

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

           Code Smell
        62. Digraphs should not be used

           Code Smell
        63. Trigraphs should not be used

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

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

           Code Smell
        66. Assembly language should be encapsulated and isolated

           Code Smell
        67. Named methods should be used to avoid confusion between testing an optional or an expected and testing the wrapped value

           Code Smell
        68. std::string_view::data() should not be passed to API expecting C-style strings

           Code Smell
        69. String literals should not be assigned to mutable char pointers

           Code Smell
        70. "std::size" should be used to determine the size of arrays

           Code Smell
        71. Calls to c_str() should not implicitly recreate strings or string_views

           Code Smell
        72. Globals should not depend on possibly not yet initialized variables

           Code Smell
        73. String methods should be used to query content instead of C apis

           Code Smell
        74. The first element of an array should not be accessed implicitly

           Code Smell
        75. "std::views::as_const" should be used to prevent modifying range elements

           Code Smell
        76. Escape sequences should use the delimited form (\u{}, \o{}, \x{})

           Code Smell
        77. "std::stringstream" or "std::spanstream" should be used instead of "std::strstream"

           Code Smell
        78. The underlying value of an enum should be accessed through "to_underlying"

           Code Smell
        79. "contains" should be used to test whether a substring is part of a string

           Code Smell
        80. "if consteval" should be used instead of "if (std::is_constant_evaluated())"

           Code Smell
        81. The optional init-statement in a control statements should only be used to declare variables

           Code Smell
        82. The condition of "assert" should not be trivially true

           Code Smell
        83. A single L in a literal suffix should only be used for long values

           Code Smell
        84. "static_assert" should be preferred to assert when the argument is a compile-time constant

           Code Smell
        85. Names of well-known C standard library macros and functions should not be used as identifiers

           Code Smell
        86. Aggregates should be initialized with braces in non-generic code

           Code Smell
        87. All the elements of an aggregate should be provided with an initial value

           Code Smell
        88. "constexpr" literal operators should be "consteval".

           Code Smell
        89. "std::format" should be used instead of standard output manipulators

           Code Smell
        90. C++ formatting functions should be used instead of C printf-like functions

           Code Smell
        91. Use "std::format" rather than "std::vformat" when the format string is known at compile time

           Code Smell
        92. Calls to "std::format" with a locale should use the "L" flag

           Code Smell
        93. "std::format" should not have unused arguments

           Code Smell
        94. Concatenated "std::format" outputs should be replaced by a single invocation

           Code Smell
        95. Width, alignment, and padding format options should be used consistently

           Code Smell
        96. Explicit argument indexing in "std::format" should be used only for non-trivial ordering

           Code Smell
        97. Generic iterator-based algorithms should be constrained

           Code Smell
        98. "std::declval" should not be used within requires-expression

           Code Smell
        99. Template should not be constrained with ad-hoc requires-expression

           Code Smell
        100. Coroutines should not take const references as parameters

           Code Smell
        101. Use type-erased "coroutine_handle" when applicable

           Code Smell
        102. Thread local variables should not be used in coroutines

           Code Smell
        103. Use conditional suspension to resume current coroutine

           Code Smell
        104. Use symmetric transfer to switch execution between coroutines

           Code Smell
        105. The return value of "std::move" should be used in a function

           Code Smell
        106. rvalue reference members should not be copied accidentally

           Code Smell
        107. "auto" should be used to store a result of functions that conventionally return an iterator or a range

           Code Smell
        108. "std::string_view" and "std::span" parameters should be directly constructed from sequences

           Code Smell
        109. Comparision operators ("<=>", "==") should be defaulted unless non-default behavior is required

           Code Smell
        110. "std::chrono" components should be used to operate on time

           Code Smell
        111. "std::has_single_bit" should be used to test if an integer is a power of two

           Code Smell
        112. Empty class members should be marked as "[[no_unique_address]]"

           Code Smell
        113. "std::to_address" should be used to convert iterators to raw pointers

           Code Smell
        114. "[[nodiscard]]" attributes on types should include explanations

           Code Smell
        115. Concept names should comply with a naming convention

           Code Smell
        116. STL constrained algorithms with range parameter should be used when iterating over the entire range

           Code Smell
        117. "std::enable_if" should not be used

           Code Smell
        118. Cognitive Complexity of coroutines should not be too high

           Code Smell
        119. Coroutine names should comply with a naming convention

           Code Smell
        120. Cyclomatic Complexity of coroutines should not be too high

           Code Smell
        121. "std::source_location" should be used instead of "__FILE__", "__LINE__", and "__func__" macros

           Code Smell
        122. Function template parameters should be named if reused

           Code Smell
        123. "std::span" should be used for a uniform sequence of elements contiguous in memory

           Code Smell
        124. Operator spaceship "<=>" should be used to define comparable types

           Code Smell
        125. Redundant comparison operators should not be defined

           Code Smell
        126. "std::format" should be used instead of string concatenation and "std::to_string"

           Code Smell
        127. Coroutines should not have too many lines of code

           Code Smell
        128. "std::cmp_*" functions should be used to compare signed and unsigned values

           Code Smell
        129. "std::bit_cast" should be used to reinterpret binary representation instead of "std::memcpy"

           Code Smell
        130. "[[likely]]" and "[[unlikely]]" should be used instead of compiler built-ins

           Code Smell
        131. "std::midpoint" and "std::lerp" should be used for midpoint computation and linear interpolation

           Code Smell
        132. "starts_with" and "ends_with" should be used for prefix and postfix checks

           Code Smell
        133. "using enum" should be used in scopes with high concentration of "enum" constants

           Code Smell
        134. Designated initializers should be used in their C++ compliant form

           Code Smell
        135. "contains" should be used to check if a key exists in a container

           Code Smell
        136. "std::jthread" should be used instead of "std::thread"

           Code Smell
        137. "nodiscard" attributes on functions should include explanations

           Code Smell
        138. Elements in a container should be erased with "std::erase" or "std::erase_if"

           Code Smell
        139. Mathematical constants should not be hardcoded

           Code Smell
        140. Use discriminated unions or "std::variant"

           Code Smell
        141. Transparent function objects should be used with associative "std::string" containers

           Code Smell
        142. "emplace" should be prefered over "insert" with "std::set" and "std::unordered_set"

           Code Smell
        143. Unnecessary expensive copy should be avoided when using auto as a placeholder type

           Code Smell
        144. The right template argument should be specified for std::forward

           Code Smell
        145. "try_emplace" should be used with "std::map" and "std::unordered_map"

           Code Smell
        146. Exception specifications should be treated as part of the type

           Code Smell
        147. "auto" should be used for non-type template parameter

           Code Smell
        148. Use "std::variant" instead of unions with non-trivial types.

           Code Smell
        149. Free functions should be preferred to member functions when accessing a container in a generic context

           Code Smell
        150. "std::optional" member function "value_or" should be used

           Code Smell
        151. "std::byte" should be used when you need byte-oriented memory access

           Code Smell
        152. The "_t" and "_v" version of type traits should be used instead of "::type" and "::value"

           Code Smell
        153. Inline variables should be used to declare global variables in header files

           Code Smell
        154. "if constexpr" should be preferred to overloading for metaprogramming

           Code Smell
        155. "[*this]" should be used to capture the current object by copy

           Code Smell
        156. "std::uncaught_exception" should not be used

           Code Smell
        157. "static_assert" with no message should be used over "static_assert" with empty or redundant message

           Code Smell
        158. Redundant class template arguments should not be used

           Code Smell
        159. Objects should not be created solely to be passed as arguments to functions that perform delegated object creation

           Code Smell
        160. "std::filesystem::path" should be used to represent a file path

           Code Smell
        161. "std::string_view" should be used to pass a read-only string to a function

           Code Smell
        162. Fold expressions should be used instead of recursive template instantiations

           Code Smell
        163. [[nodiscard]] should be used when the return value of a function should not be ignored

           Code Smell
        164. "as_const" should be used to make a value constant

           Code Smell
        165. Structured binding should be used

           Code Smell
        166. "if" and "switch" initializer should be used to reduce scope of variables

           Code Smell
        167. Emplacement should be preferred when insertion creates a temporary with sequence containers

           Code Smell
        168. "std::visit" should be used to switch on the type of the current value in a "std::variant"

           Code Smell
        169. "std::scoped_lock" should be used instead of "std::lock_guard"

           Code Smell
        170. "bind" should not be used

           Code Smell
        171. "dynamic_cast" should be used for downcasting

           Code Smell
        172. Multicharacter literals should not be used

           Code Smell
        173. Struct should explicitly specify the access level when specifying base classes

           Code Smell
        174. Classes should explicitly specify the access level when specifying base classes

           Code Smell
        175. "std::initializer_list" constructor should not overlap with other constructors

           Code Smell
        176. Threads should not be detached

           Code Smell
        177. Loop variables should be declared in the minimal possible scope

           Code Smell
        178. "shared_ptr" should not be taken by rvalue reference

           Code Smell
        179. Inheriting constructors should be used

           Code Smell
        180. Return type of functions shouldn't be const qualified value

           Code Smell
        181. "make_unique" and "make_shared" should be used to construct "unique_ptr" and "shared_ptr"

           Code Smell
        182. "std::endl" should not be used

           Code Smell
        183. C-style array should not be used

           Code Smell
        184. "auto" should be used to avoid repetition of types

           Code Smell
        185. Macros should not be used as replacements for "typedef" and "using"

           Code Smell
        186. Integer literals should not be cast to bool

           Code Smell
        187. Member functions that don't mutate their objects should be declared "const"

           Code Smell
        188. Concise syntax should be used for concatenatable namespaces

           Code Smell
        189. Track comments matching a regular expression

           Code Smell
        190. STL algorithms and range-based for loops should be preferred to traditional for loops

           Code Smell
        191. Functions that are not used in a project should be removed

           Code Smell
        192. Multiple mutexes should not be acquired with individual locks

           Code Smell
        193. Local variables should be initialized immediately

           Code Smell
        194. Pointers or references obtained from aliased smart pointers should not be used as function parameters

           Code Smell
        195. "try_lock", "lock" and "unlock" should not be directly used for mutexes

           Code Smell
        196. A single statement should not have more than one resource allocation

           Code Smell
        197. Function parameters that are rvalue references should be moved

           Code Smell
        198. Capture by reference in lambdas used locally

           Code Smell
        199. Size of bit fields should not exceed the size of their types

           Code Smell
        200. Only valid arguments should be passed to UNIX/POSIX functions

           Code Smell
        201. Only valid arguments should be passed to stream functions

           Code Smell
        202. "Forwarding references" parameters should be used only to forward parameters

           Code Smell
        203. Functions should not have more than one argument of type "bool"

           Code Smell
        204. Non-const global variables should not be used

           Code Smell
        205. The order for arguments of the same type in a function call should be obvious

           Code Smell
        206. "using" should be preferred for type aliasing

           Code Smell
        207. "std::move" should only be used where moving can happen

           Code Smell
        208. Classes should not contain both public and private data members

           Code Smell
        209. Functions that throw exceptions should not be used as hash functions

           Code Smell
        210. "constexpr" functions should not be declared "inline"

           Code Smell
        211. "^" should not be confused with exponentiation

           Code Smell
        212. A cast should not convert a pointer type to an integral type

           Code Smell
        213. An object with integral type or pointer to void type shall not be converted to an object with pointer type

           Code Smell
        214. An object with pointer type shall not be converted to an unrelated pointer type, either directly or indirectly

           Code Smell
        215. Pointer and reference local variables should be "const" if the corresponding object is not modified

           Code Smell
        216. The identifiers used for the parameters in a re-declaration or override of a function shall be identical to those in the declaration

           Code Smell
        217. using-directives and using-declarations (excluding class scope or function scope using-declarations) shall not be used in header files

           Code Smell
        218. A loop-control-variable other than the loop-counter shall not be modified within condition or expression

           Code Smell
        219. Blocking functions should not be called inside critical sections

           Code Smell
        220. The loop-counter shall not be modified within condition or statement

           Code Smell
        221. If loop-counter is not modified by -- or ++, then, within condition, the loop-counter shall only be used as an operand to <=, <, > or >=

           Code Smell
        222. A for loop shall contain a single loop-counter which shall not have floating type

           Code Smell
        223. Every switch statement shall have at least one case-clause

           Code Smell
        224. Return value of "setuid" family of functions should always be checked

           Code Smell
        225. All "if ... else if" constructs shall be terminated with an "else "clause

           Code Smell
        226. An `if ( condition )` construct shall be followed by a compound statement. The else keyword shall be followed by either a compound statement, or another if statement

           Code Smell
        227. The statement forming the body of a "switch", "while", "do {...} while" or "for" statement shall be a compound statement

           Code Smell
        228. C-style casts (other than void casts) and functional notation casts (other than explicit constructor calls) shall not be used

           Code Smell
        229. GNU attributes should be used correctly

           Code Smell
        230. Format strings should comply with ISO standards

           Code Smell
        231. Size of variable length arrays should be greater than zero

           Code Smell
        232. Argument of "printf" should be a format string

           Code Smell
        233. "mktemp" family of functions templates should have at least six trailing "X"s

           Code Smell
        234. Unevaluated operands should not have side effects

           Code Smell
        235. Size argument of memory functions should be consistent

           Code Smell
        236. Return value of "nodiscard" functions should not be ignored

           Code Smell
        237. Implicit casts should not lower precision

           Code Smell
        238. "std::move" should not inhibit optimizations

           Code Smell
        239. Appropriate size arguments should be passed to "strncat" and "strlcpy"

           Code Smell
        240. Moved-from objects should not be relied upon

           Code Smell
        241. Functions which do not return should be declared as "noreturn"

           Code Smell
        242. Keywords shall not be used as macros identifiers

           Code Smell
        243. Incomplete types should not be deleted

           Code Smell
        244. Logical operators should not be confused with bitwise operators

           Code Smell
        245. Dereferenced null pointers should not be bound to references

           Code Smell
        246. "else" statements should be clearly matched with an "if"

           Code Smell
        247. Header guards should be followed by a matching "#define" macro

           Code Smell
        248. Template parameters should be preferred to "std::function" when configuring behavior at compile time

           Code Smell
        249. Function pointers should not be used as function parameters

           Code Smell
        250. The addresses of standard library functions should not be taken

           Code Smell
        251. Macros should not be used to define constants

           Code Smell
        252. Memory should not be managed manually

           Code Smell
        253. Facilities in <random> should be used instead of "srand", "rand" and "random_shuffle"

           Code Smell
        254. Lambdas that capture "this" should capture everything explicitly

           Code Smell
        255. Move and swap operations should be "noexcept"

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

           Code Smell
        257. Function parameters should not be of type "std::unique_ptr<T> const &"

           Code Smell
        258. The "Rule-of-Zero" should be followed

           Code Smell
        259. "nullptr" should be used to denote the null pointer

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

           Code Smell
        261. "auto" should not be used to deduce raw pointers

           Code Smell
        262. Include directives should not rely on non-portable search strategy

           Code Smell
        263. Methods should not have identical implementations

           Code Smell
        264. Method overloads should be grouped together in the interface

           Code Smell
        265. A conditionally executed single line should be denoted by indentation

           Code Smell
        266. Conditionals should start on new lines

           Code Smell
        267. "case" ranges should cover multiple values

           Code Smell
        268. "#include" paths should be portable

           Code Smell
        269. "#import" should not be used

           Code Smell
        270. Cognitive Complexity of functions should not be too high

           Code Smell
        271. Macros should not be redefined

           Code Smell
        272. Exceptions should not be thrown in "noexcept" functions

           Code Smell
        273. 'extern "C"' should not be used with namespaces

           Code Smell
        274. "auto" should not be used as a storage class specifier

           Code Smell
        275. "#include_next" should not be used

           Code Smell
        276. Array indices should be placed between brackets

           Code Smell
        277. String literals should not be concatenated implicitly

           Code Smell
        278. Virtual functions should not have default arguments

           Code Smell
        279. GNU extensions should not be used

           Code Smell
        280. Reference types should not be qualified with "const" or "volatile"

           Code Smell
        281. Non-exception types should not be caught

           Code Smell
        282. Non-exception types should not be thrown

           Code Smell
        283. Comparison operators should not be virtual

           Code Smell
        284. Partial specialization syntax should not be used for function templates

           Code Smell
        285. Local variables and member data should not be volatile

           Code Smell
        286. String literals should not be immediately followed by macros

           Code Smell
        287. Alternative operators should not be used

           Code Smell
        288. Assignment operators should not be "virtual"

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

           Code Smell
        290. Types and variables should be declared in separate statements

           Code Smell
        291. Scoped enumerations should be used

           Code Smell
        292. "const" and "volatile" should not be used in "enum" declarations

           Code Smell
        293. "reinterpret_cast" should not be used

           Code Smell
        294. Raw string literals should be used

           Code Smell
        295. Classes should have regular copy and move semantic

           Code Smell
        296. "static" should not be used in unnamed namespaces

           Code Smell
        297. Default capture should not be used

           Code Smell
        298. "final" classes should not have "virtual" functions

           Code Smell
        299. Redundant lambda return types should be omitted

           Code Smell
        300. "switch" statements should cover all cases

           Code Smell
        301. "inline" should not be used redundantly

           Code Smell
        302. Declarations of functions defined outside of the class should not be marked as "inline"

           Code Smell
        303. Standard groupings should be used with digit separators

           Code Smell
        304. Digit separators should be used

           Code Smell
        305. Allocation and deallocation functions should not be explicitly declared "static"

           Code Smell
        306. Base class access specifiers should not be redundant

           Code Smell
        307. Access specifiers should not be redundant

           Code Smell
        308. The "register" storage class specifier should not be used

           Code Smell
        309. Redundant pointer operator sequences should be removed

           Code Smell
        310. Special member function should not be defined unless a non standard behavior is required

           Code Smell
        311. "override" or "final" should be used instead of "virtual"

           Code Smell
        312. Standard namespaces should not be modified

           Code Smell
        313. Inheritance should be "public"

           Code Smell
        314. Empty "case" clauses that fall through to the "default" should be omitted

           Code Smell
        315. Format strings should be used correctly

           Code Smell
        316. Destructors should not be called explicitly

           Code Smell
        317. Conditional operators should not be nested

           Code Smell
        318. Namespaces should not be empty

           Code Smell
        319. "static" base class members should not be accessed via derived types

           Code Smell
        320. Forward declarations should not be redundant

           Code Smell
        321. Member data should be initialized in-class or in a constructor initialization list

           Code Smell
        322. Members should be initialized in the order they are declared

           Code Smell
        323. Label names should comply with a naming convention

           Code Smell
        324. "this" should not be compared with null

           Code Smell
        325. The "delete" operator should only be used for pointers

           Code Smell
        326. Binary operators should be overloaded as hidden friend functions

           Code Smell
        327. Bit fields should not be used

           Code Smell
        328. Declarations should not be empty

           Code Smell
        329. General "catch" clauses should not be used

           Code Smell
        330. "catch" clauses should do more than rethrow

           Code Smell
        331. Multiline blocks should be enclosed in curly braces

           Code Smell
        332. Increment should not be used to set boolean variables to 'true'

           Code Smell
        333. Exceptions should not be ignored

           Code Smell
        334. Control characters should not be used in literals

           Code Smell
        335. Child class fields should not shadow parent class fields

           Code Smell
        336. Enumeration values should comply with a naming convention

           Code Smell
        337. Enumeration names should comply with a naming convention

           Code Smell
        338. Octal and hexadecimal escape sequences should be terminated

           Code Smell
        339. Flexible array members should not be declared

           Code Smell
        340. Standard C++ headers should be used

           Code Smell
        341. Namespace names should comply with a naming convention

           Code Smell
        342. Exception specifications should not be used

           Code Smell
        343. Track parsing failures

           Code Smell
        344. User-specified functions should not be called

           Code Smell
        345. Parameters should be passed in the correct order

           Code Smell
        346. "static" members should be accessed statically

           Code Smell
        347. "final" classes should not have "protected" members

           Code Smell
        348. "final" should not be used redundantly

           Code Smell
        349. Comment styles "//" and "/* ... */" should not be mixed within a file

           Code Smell
        350. Preprocessor directives should not be indented

           Code Smell
        351. Track instances of the "#error" preprocessor directive being reached

           Code Smell
        352. Non-reentrant POSIX functions should be replaced with their reentrant versions

           Code Smell
        353. Obsolete POSIX functions should not be used

           Code Smell
        354. "goto" statements should not be used to jump into blocks

           Code Smell
        355. Redundant casts should not be used

           Code Smell
        356. "union" names should comply with a naming convention

           Code Smell
        357. Code annotated as deprecated should not be used

           Code Smell
        358. Two branches in a conditional structure should not have exactly the same implementation

           Code Smell
        359. Unused assignments should be removed

           Code Smell
        360. "switch" statements should not be nested

           Code Smell
        361. Structures should not have too many fields

           Code Smell
        362. The ternary operator should not be used

           Code Smell
        363. "public", "protected" and "private" sections of a class should be declared in that order

           Code Smell
        364. Constants should come first in equality tests

           Code Smell
        365. A "struct" should not have member functions

           Code Smell
        366. The sign of an unsigned variable should not be tested

           Code Smell
        367. "#pragma warning (default: ...)" should not be used

           Code Smell
        368. Pre-defined macros should not be defined, redefined or undefined

           Code Smell
        369. Keywords introduced in later specifications should not be used as identifiers

           Code Smell
        370. Lambdas should not be used

           Code Smell
        371. Type specifiers should be listed in a standard order

           Code Smell
        372. Default parameters should not be defined

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

           Code Smell
        374. C++ comments should be used

           Code Smell
        375. Track "TODO" and "FIXME" comments that do not contain a reference to a person

           Code Smell
        376. Exceptions should not be used

           Code Smell
        377. The prefix increment/decrement form should be used

           Code Smell
        378. Virtual functions should not be called from constructors or destructors

           Code Smell
        379. Context-sensitive keywords should not be used as identifiers

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

           Code Smell
        381. "struct" names should comply with a naming convention

           Code Smell
        382. File names should comply with a naming convention

           Code Smell
        383. Macro names should comply with a naming convention

           Code Smell
        384. Cyclomatic Complexity of functions should not be too high

           Code Smell
        385. Unused local variables should be removed

           Code Smell
        386. "switch" statements should not have too many "case" clauses

           Code Smell
        387. Track lack of copyright and license headers

           Code Smell
        388. Classes should not have too many methods

           Code Smell
        389. Comments should not be located at the end of lines of code

           Code Smell
        390. Functions/methods should not have too many lines

           Code Smell
        391. Control flow statements "if", "for", "while", "switch" and "try" should not be nested too deeply

           Code Smell
        392. Octal values should not be used

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

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

           Code Smell
        395. Track uses of "NOSONAR" comments

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

           Code Smell
        397. "::" operator should be used to access global variables and functions

           Code Smell
        398. Functions without parameters should not use "(void)"

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

           Code Smell
        400. A "while" loop should be used instead of a "for" loop

           Code Smell
        401. "if ... else if" constructs should end with "else" clauses

           Code Smell
        402. "typedef" should be used for function pointers

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

           Code Smell
        404. Inherited functions should not be hidden

           Code Smell
        405. Pass by reference to const should be used for large input parameters

           Code Smell
        406. Assignment operators should return non-"const" reference to the assigned object

           Code Smell
        407. Polymorphic base class destructor should be either public virtual or protected non-virtual

           Code Smell
        408. C-style memory allocation routines should not be used

           Code Smell
        409. break statements should not be used except for switch cases

           Code Smell
        410. Statements should be on separate lines

           Code Smell
        411. "switch" statements should not contain non-case labels

           Code Smell
        412. Control structures should use curly braces

           Code Smell
        413. Nested code blocks should not be used

           Code Smell
        414. Lambdas should not have too many lines

           Code Smell
        415. Methods should not be empty

           Code Smell
        416. Overriding member functions should do more than simply call the same member in the base class

           Code Smell
        417. Generic exceptions should not be caught

           Code Smell
        418. Unused function parameters should be removed

           Code Smell
        419. Local variable and function parameter names should comply with a naming convention

           Code Smell
        420. Field names should comply with a naming convention

           Code Smell
        421. "empty()" should be used to test for emptiness

           Code Smell
        422. "switch case" clauses should not have too many lines of code

           Code Smell
        423. Unused functions and methods should be removed

           Code Smell
        424. Functions should not contain too many return statements

           Code Smell
        425. Try-catch blocks should not be nested

           Code Smell
        426. Track uses of "TODO" tags

           Code Smell
        427. Track uses of "FIXME" tags

           Code Smell
        428. Deprecated code should be removed

           Code Smell
        429. Lines should not end with trailing whitespaces

           Code Smell
        430. Files should end with a newline

           Code Smell
        431. Deprecated attributes should include explanations

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

           Code Smell
        433. Generic exceptions should never be thrown

           Code Smell
        434. Variables should not be shadowed

           Code Smell
        435. Empty statements should be removed

           Code Smell
        436. Redundant pairs of parentheses should be removed

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

           Code Smell
        438. Inheritance tree of classes should not be too deep

           Code Smell
        439. Magic numbers should not be used

           Code Smell
        440. Nested blocks of code should not be left empty

           Code Smell
        441. Functions should not have too many parameters

           Code Smell
        442. Unused "private" fields should be removed

           Code Smell
        443. Expressions should not be too complex

           Code Smell
        444. Mergeable "if" statements should be combined

           Code Smell
        445. Unused labels should be removed

           Code Smell
        446. Standard outputs should not be used directly to log anything

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

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

           Code Smell
        449. C libraries should not be used

           Code Smell
        450. Tabulation characters should not be used

           Code Smell
        451. Files should not have too many lines of code

           Code Smell
        452. Control should not be transferred into a complex logic block using a "goto" or a "switch" statement

           Code Smell
        453. Function templates should not be specialized

           Code Smell
        454. Lines should not be too long

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

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

           Code Smell
        457. Classes should not be derived from virtual bases

           Code Smell
        458. Class names should comply with a naming convention

           Code Smell
        459. Parameters in an overriding virtual function shall either use the same default arguments as the function they override, or else shall not specify any default arguments

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

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

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

           Code Smell
        463. Header files should not contain unnamed namespaces

           Code Smell
        464. Function names should comply with a naming convention

           Code Smell
        465. The character handling functions from "<cctype>" and "<cwctype>" shall not be used

           Code Smell
        466. The "goto" statement should not be used

           Code Smell
        467. An "integer-literal" of type "long long" shall not use a single "L" or "l" in any suffix

           Code Smell
        468. A non-"transient lambda" shall not implicitly capture "this"

           Code Smell
        469. "Global variables" shall not be used

           Code Smell
        470. "std::vector" should not be specialized with "bool"

           Code Smell
        471. Variables of array type should not be declared

           Code Smell
        472. The "setlocale" and "std::locale::global" functions shall not be called

           Code Smell
        473. "Unscoped enumerations" should not be declared

           Code Smell
        474. Functions with "limited visibility" should be "used" at least once

           Code Smell
        475. "Advanced memory management" shall not be used

           Code Smell
        476. All variables should be initialized

           Code Smell
        477. An object shall not be used while in a "potentially moved-from state"

           Code Smell
        478. "Forwarding references" and "std::forward" shall be used together

           Code Smell
        479. Variables should be captured explicitly in a non-"transient lambda"

           Code Smell
        480. Local variables shall not have static storage duration

           Code Smell
        481. The macro "offsetof" shall not be used

           Code Smell
        482. The standard "header file" "<csetjmp>" shall not be used

           Code Smell
        483. The "#" and "##" preprocessor operators should not be used

           Code Smell
        484. An "empty throw" shall only occur within the "compound-statement" of a "catch handler"

           Code Smell
        485. Classes should not be inherited virtually

           Code Smell
        486. The "union" keyword shall not be used

           Code Smell
        487. A "declaration" should not declare more than one variable or member variable

           Code Smell
        488. There should be no unnamed namespaces in "header files"

           Code Smell
        489. The identifier "main" shall not be used for a function other than the global function "main"

           Code Smell
        490. The "goto" statement shall jump to a label declared later in the function body

           Code Smell
        491. All "if ... else if" constructs shall be terminated with an "else" statement

           Code Smell
        492. The "address-of" operator shall not be overloaded

           Code Smell
        493. A cast should not convert a pointer type to an integral type

           Code Smell
        494. A cast shall not remove any "const" or "volatile" qualification from the type accessed via a pointer or by reference

           Code Smell
        495. C-style casts and "functional notation" casts shall not be used

           Code Smell
        496. The "declaration" of an object should contain no more than two levels of pointer indirection

           Code Smell
        497. "nullptr" shall be the only form of the "null-pointer-constant"

           Code Smell
        498. The names of the "standard signed integer types" and "standard unsigned integer types" should not be used

           Code Smell
        499. Function-like macros shall not be defined

           Code Smell
        500. "#include" directives should only be preceded by preprocessor directives or comments

           Code Smell
        501. Unsigned "integer literals" shall be appropriately suffixed

           Code Smell
        502. The value returned by a function shall be "used"

           Code Smell
        503. Variables with "limited visibility" should be "used" at least once

           Code Smell

        Move and swap operations should be "noexcept"

        intentionality - efficient
        maintainability
        Code Smell
        • cppcoreguidelines
        • error-handling
        • since-c++11

        Why is this an issue?

        More Info

        Move operations (move constructor, move assignment operator) are about efficiently transferring resource ownership. When transferring resources from the source, you don’t have to allocate any memory or perform any other operation that might fail. This is why most people will expect move operations to be non-throwing.

        Additionally, if a move operation fails, the source object can have been partially altered by the move, making recovery very tricky or just impossible. Therefore, to ensure robustness, some functions (for instance, std::move_if_noexcept, used by std::vector) will decide to copy your object if its move operations are not decorated with noexcept. This can significantly slow down your program.

        If you can not implement your move operations so that they never throw, you may only provide copy operations that will be safer to use.

        Swap operations are similar to move operations in that they should be equivalent to moving two objects into each other. So if you add a swap function to your type, it should be noexcept too.

        Note that you should not write your move operations for most classes but rely on the "Rule-of-Zero" (S3624).

        This rule raises an issue when a move or swap operation is not noexcept, which can happen in two cases:

        • The operation is user-defined and is not unconditionally declared as noexcept,
        • The operation is implicitly defined, and one of the class’s base classes or member variables does not have noexcept move operations.

        Noncompliant code example

        struct A {
          A (A const &a);
          A (A && a); // Noncompliant
          ~A();
          A &operator=(A const &a);
          A &operator=(A &&a); // Noncompliant
        };
        
        void swap(A& a1, A& a2); // Noncompliant
        

        Compliant solution

        struct A {
          A (A const &a);
          A (A && a) noexcept;
          ~A();
          A &operator=(A const &a);
          A &operator=(A &&a) noexcept;
        };
        
        void swap(A& a1, A& a2) noexcept;
        
          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