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: 6 rules found
since-c++23
    Impact
      Clean code attribute
        1. "std::views::as_const" should be used to prevent modifying range elements

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

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

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

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

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

           Code Smell

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

        intentionality - clear
        maintainability
        Code Smell
        Quick FixIDE quick fixes available with SonarQube for IDE
        • since-c++23
        • bad-practice

        C++23 introduced delimited escape sequences like \x{40} that improve readability and are less error-prone. They should be preferred.

        Why is this an issue?

        How can I fix it?

        More Info

        Escape sequences can be used to designate a single character literal or characters in a string literal. Escape sequences followed by a character code are especially handy when the character is non-visible or is not directly representable in the source code encoding. However, before C++23 the way to write them is convoluted. Let’s take, for instance, the character @:

        • In octal, it is written \100. This notation has two main issues: It’s not easy to spot octal literals (it’s just some digits, nothing makes it obvious that they are octal digits), and it’s not easy to say when the escape sequence ends (see S2335). This is so confusing that it is commonly advised to avoid octal escape sequences (see S1314).
        • Hexadecimal sequences are written \x40. While they stand out more prominently, it’s still difficult to say when they end (see also S2335).
        • Universal character names, while not strictly speaking escape sequences, have a very similar visual appearance and are written \u0040(exactly 4 hexadecimal digits) or \U00000040 (exactly 8 hexadecimal digits). The fact that the number of digits depends on the case of the introducing u can be a source of errors.

        C++23 introduces a new way to define those escape sequences, which is more consistent, non-ambiguous, and makes the ending of the literal obvious. It is now possible to write the previous examples respectively \o{100}, \x{40}, \u{40} and \u{40} again (leading zeros are optional).

        This rule raises an issue when a legacy escape sequence can be replaced with an improved version.

          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
          10.7

        © 2008-2025 SonarSource SA. All rights reserved.

        Privacy Policy | Cookie Policy | Terms of Use