Uploaded image for project: 'Rules Repository'
  1. Rules Repository
  2. RSPEC-6235

"const" qualifier should be placed consistently

    XMLWordPrintable

    Details

    • List of parameters:
      • key = eastConst
      • description = Determines if the "const" qualifier should be placed after type
      • default = false
      • type = BOOLEAN
    • Default Severity:
      Minor
    • Impact:
      Low
    • Likelihood:
      Low
    • Targeted languages:
      C++
    • Remediation Function:
      Constant/Issue
    • Constant Cost:
      2min
    • Analysis Level:
      Lexical Analysis
    • Analysis Scope:
      Main Sources, Test Sources
    • CppCoreGuidelines:
      NL.26

      Description

      C++ language is highly elastic regarding the placement of type specifiers on type declarations. This makes it possible to place a const qualifier before the type ("west const") or after it ("east const").

      Mixing both const placement in a single project or, even worse, in a single file, makes the code harder to understand. It will require more effort to notice that the object cannot be modified.

      This rule checks if the const qualifier placement matches the configuration.

      Noncompliant Code Example

      With default value of "eastConst" parameter.

      long double const tau = 6.28L; // Noncompliant
      

      Compliant Solution

      const long double tau = 6.28L;
      

      See

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              Unassigned Unassigned
              Reporter:
              tomasz.kaminski Tomasz KamiƄski
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated: