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

Keywords introduced in later specifications should not be used as identifiers

    Details

    • Type: Code Smell Detection
    • Status: Active
    • Resolution: Unresolved
    • Labels:
    • Message:
      Rename the "xxx" identifier
    • Default Severity:
      Blocker
    • Impact:
      High
    • Likelihood:
      High
    • Default Quality Profiles:
      Sonar way, MISRA C++ 2008 recommended
    • Targeted languages:
      Objective-C
    • Covered Languages:
      C, C++
    • Remediation Function:
      Constant/Issue
    • Constant Cost:
      5min

      Description

      While keywords introduced in later standards can legally be used as identifiers in code compiled to earlier standards, doing so will eventually cause problems. Such code will cause compile errors if (when) the compiler is upgraded, and fixing those errors could be difficult and painful.

      Additionally, such misuse of keywords has the potential to thoroughly confuse people who are unfamiliar with the code base, possibly leading them to introduce additional errors.

      For these reasons, the earlier this practice is stopped, the better.

      This rule flags instances of the following keywords used as identifiers:
      C99
      inline, restrict, _Bool, _Complex, _Noreturn, _Static_assert, _Thread_local
      C11
      _Alignas, _Alignof, _Atomic, _Generic, _Imaginary
      C++11
      alignas, alignof, char16_t, char32_t, constexpr, decltype, noexcept, nullptr, static_assert, thread_local
      C++20
      concept, requires

      Noncompliant Code Example

      int inline = 0;
      

      Compliant Solution

      int inline_count = 0;
      

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                ann.campbell.2 Ann Campbell
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated: