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

"using" should be preferred for type aliasing

    XMLWordPrintable

    Details

    • Message:
      Use 'using' instead of 'typedef' for this type alias
    • Highlighting:
      Hide

      The typedef statement

      Show
      The typedef statement
    • Default Severity:
      Minor
    • Impact:
      Low
    • Likelihood:
      Low
    • Default Quality Profiles:
      Sonar way
    • Covered Languages:
      C++
    • Irrelevant for Languages:
      ABAP, APEX, C#, C, Cobol, CSS, Flex, Go, HTML, Java, JavaScript, Kotlin, Objective-C, PHP, PL/I, PL/SQL, Python, RPG, Ruby, Rust, Scala, Solidity, Swift, T-SQL, TypeScript, VB.Net, VB6, XML
    • Remediation Function:
      Constant/Issue
    • Constant Cost:
      5min
    • Analysis Level:
      Syntactic Analysis
    • Analysis Scope:
      Main Sources, Test Sources
    • CppCoreGuidelines:
      T.43

      Description

      Since C++11, type aliases can be declared via using or typedef. using should be preferred as more readable because you see the new name/alias first.
      In addition, using can be templated, which makes it applicable to more situations than typedef.

      Noncompliant Code Example

      typedef void (*FunctionPointerType)(int);
      

      Compliant Solution

      using FunctionPointerType = void (*)(int);
      

      See

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              Unassigned Unassigned
              Reporter:
              abbas.sabra Abbas Sabra
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Dates

                Created:
                Updated: