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

"extern" shouldn't be used on member definitions

    XMLWordPrintable

    Details

    • Type: Bug Detection
    • Status: Active
    • Resolution: Unresolved
    • Labels:
    • Message:
      Remove this "extern" keyword, which is ignored by the compiler.
    • Highlighting:
      Hide

      extern

      Show
      extern
    • Default Severity:
      Major
    • Impact:
      Low
    • Likelihood:
      High
    • Default Quality Profiles:
      Sonar way, MISRA C++ 2008 recommended
    • Covered Languages:
      C, C++
    • Remediation Function:
      Constant/Issue
    • Constant Cost:
      1min
    • Analysis Scope:
      Main Sources, Test Sources

      Description

      Data members and member functions cannot be defined as external, although entire objects can. When a member is declared as extern, the compiler simply ignores the keyword, making it both extraneous and confusing.

      Noncompliant Code Example

      class C {
        void fun();
      };
      
      extern void C::fun() { // Noncompliant
      }
      

      Compliant Solution

      class C {
        void fun();
      };
      
      void C::fun() {
      }
      

        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: