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

"auto" should not be used to deduce raw pointers

    XMLWordPrintable

    Details

    • Message:
      Change this declaration specifying the "pointer" part outside of auto.
    • Highlighting:
      Hide

      the auto declaration

      Show
      the auto declaration
    • Default Severity:
      Minor
    • Impact:
      Low
    • Likelihood:
      Low
    • Covered Languages:
      C, C++
    • Irrelevant for Languages:
      ABAP, C#, C, Cobol, CSS, Flex, HTML, Java, JavaScript, Objective-C, PHP, PL/I, PL/SQL, Python, RPG, Swift, T-SQL, TypeScript, VB.Net, VB6, XML
    • Remediation Function:
      Constant/Issue
    • Constant Cost:
      2min
    • Analysis Scope:
      Main Sources, Test Sources

      Description

      Using auto when the type that would be deduced is a pointer type can cause confusion. It is much better to specify the pointer part outside of auto.

      Noncompliant Code Example

      auto item = new Item(); // Noncompliant
      

      Compliant Solution

      auto* item = new Item(); 
      

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              Unassigned Unassigned
              Reporter:
              jeanchristophe.collet Jean-Christophe Collet (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated: