Main Content

MISRA C++:2008 Rule 1-0-1

All code shall conform to ISO/IEC 14882:2003 "The C++ Standard Incorporating Technical Corrigendum 1"

Description

Rule Definition

All code shall conform to ISO/IEC 14882:2003 "The C++ Standard Incorporating Technical Corrigendum 1".

Rationale

The MISRA™.C++:2008 guidelines are based on the C++03 standard (ISO/IEC 14882:2003). Language extensions outside the standard are not covered by these guidelines. If you follow the MISRA C++:2008 guidelines as safe coding practices, you must stay within the C++03 standard for the guidelines to cover your code.

Polyspace Implementation

The rule checker reports language extensions that are not strictly part of the C++03 Standard. The extensions could be part of a later standard or part of a specific dialect such as GCC or Microsoft® Visual C++®. The rule violations are reported as compilation errors as a strict C++03 compiler would report them.

For effective use of this rule, make sure to enable the C++03 standard for the Polyspace® Bug Finder™ analysis. For more information, see C++ standard version (-cpp-version).

Troubleshooting

If you expect a rule violation but Polyspace does not report it, see Diagnose Why Coding Standard Violations Do Not Appear as Expected.

Examples

expand all

class A
{
  public:
    virtual int foo(int x) = 0; 
};

class B: public A
{
   public:
     int foo(double x) override {  }; // Noncompliant
};

This example uses the override specifier, which is supported only since C++11. The rule violation is reported as a compilation error:

Expected a ";"
Which indicates that the compiler expected a semicolon following the closing parenthesis in the declaration void foo(double x).

void AccessMemory() {
    int* ptr = nullptr; // Intentionally creating a null pointer

    __try {  // Noncompliant 
        *ptr = 42; // This line will cause an access violation exception
    }
    __finally {
        // Code here is executed whether an exception occurred or not
        if (AbnormalTermination()) {
            // Code here is executed if the try block threw an exception
        } else {
            // Code here is executed on success
        }
    }
}

This example uses the Microsoft Visual C++ language extensions __try and __finally, which violate the rule. Instead, the standard C++ try-catch mechanism can be used for catching exceptions and the C++ RAII idiom can be used for freeing of resources even in the presence of exceptions.

Check Information

Group: General
Category: Required

Version History

Introduced in R2013b