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

        "if consteval" should be used instead of "if (std::is_constant_evaluated())"

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

        Why is this an issue?

        How can I fix it?

        More Info

        Since C++20, a call to std::is_constant_evaluated() can be used to determine whether the call occurs within a constant-evaluated context.

        Typically, this function is called in the condition of an if statement to optimize code: It allows different actions to be performed depending on whether an expression is evaluated at compile-time or runtime. However, writing if (std::is_constant_evaluated()) comes with a few caveats.

        1. It can be error-prone: One may be tempted to write if constexpr instead of if but doing this always results in the condition being true. S6169 explains this and other similar problems in greater depth.
        2. Because it looks like any regular if statement with a function call, it does not stand out as something semantically different and important.
        3. Immediate functions (see again S6169) cannot be invoked from such if statements, which is counterintuitive and overly restrictive.

        For these reasons, C++23 introduced the if consteval control-flow statement. There is also a negated form: if not consteval (or if ! consteval). These versions should be preferred since they are not error-prone, stand out with their different and concise syntax, and do not require including <type_traits>.

        This rule raises an issue when if (std::is_constant_evaluated()) or if (!std::is_constant_evaluated()) are used.

          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