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

"#pragma warning (default: ...)" should not be used

    Details

    • Type: Code Smell Detection
    • Status: Active
    • Resolution: Unresolved
    • Labels:
    • Message:
      Remove this use of "#pragma warning (default: ...)"
    • Default Severity:
      Minor
    • Impact:
      Low
    • Likelihood:
      Low
    • Default Quality Profiles:
      Sonar way, MISRA C++ 2008 recommended
    • Covered Languages:
      C, C++, Objective-C
    • Remediation Function:
      Constant/Issue
    • Constant Cost:
      5min
    • CERT:
      MSC00-C.

      Description

      Using "#pragma warning (default: ...)" resets the warning in question to its default settings, which may not be what the compiler was initially invoked with. Typically, this usage is seen after a warning is turned off, in preparation for code that is known to cause warnings. Instead, the warning's current state should be saved, and then restored after the code in question.

      Noncompliant Code Example

      #pragma warning (disable: TheWarning)
      #include problem_code.h
      #pragma warning (default: TheWarning)
      

      Compliant Solution

      #pragma warning (push)
      #include problem_code.h
      #pragma warning (pop)
      

      See

        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: