主要内容

本页翻译不是最新的。点击此处可查看最新英文版本。

MISRA C++:2023 规则和指令

MISRA C++:2023 规则和指令的列表和描述

Polyspace® Bug Finder™ 可以检查您的代码以查找违反 MISRA™ C++:2023 标准的情况。MISRA C++:2023 标准以 ISO/IEC 14882:2017 为目标,通常称为 C++17。此新标准是对 MISRA C++:2008 规则 的更新,并纳入了 AUTOSAR C++14 规则

使用检查 MISRA C++:2023 (-misra-cpp-2023) 分析选项来检查是否违反了此新标准。当违反了 MISRA C++:2023 规则时,Polyspace Bug Finder 会报告违规,并指出导致违规的事件。

Polyspace Bug Finder 支持 MISRA C++:2023 标准中的所有规则。有关 Polyspace 涵盖的 MISRA C++:2023 的详细信息,请参阅 Polyspace Support for Coding Standards

Polyspace 结果

全部展开

MISRA C++:2023 Rule 0.0.1A function shall not contain unreachable statements (自 R2024b 起)
MISRA C++:2023 Rule 0.0.2Controlling expressions should not be invariant (自 R2024b 起)
MISRA C++:2023 Rule 0.1.1A value should not be unnecessarily written to a local object (自 R2024b 起)
MISRA C++:2023 Rule 0.1.2The value returned by a function shall be used (自 R2024b 起)
MISRA C++:2023 Rule 0.2.1Variables with limited visibility should be used at least once (自 R2024b 起)
MISRA C++:2023 Rule 0.2.2A named function parameter shall be used at least once (自 R2024b 起)
MISRA C++:2023 Rule 0.2.3Types with limited visibility should be used at least once (自 R2024b 起)
MISRA C++:2023 Rule 0.2.4Functions with limited visibility should be used at least once (自 R2024b 起)
MISRA C++:2023 Dir 0.3.1Floating-point arithmetic should be used appropriately (自 R2024b 起)
MISRA C++:2023 Dir 0.3.2A function call shall not violate the function's preconditions (自 R2024b 起)
MISRA C++:2023 Rule 4.1.1A program shall conform to ISO/IEC 14882:2017 (C++17) (自 R2024b 起)
MISRA C++:2023 Rule 4.1.2Deprecated features should not be used (自 R2024b 起)
MISRA C++:2023 Rule 4.1.3There shall be no occurrence of undefined or critical unspecified behaviour (自 R2024b 起)
MISRA C++:2023 Rule 4.6.1Operations on a memory location shall be sequenced appropriately (自 R2024b 起)
MISRA C++:2023 Rule 5.0.1Trigraph-like sequences should not be used (自 R2024b 起)
MISRA C++:2023 Rule 5.7.1The character sequence /* shall not be used within a C-style comment (自 R2024b 起)
MISRA C++:2023 Dir 5.7.2Sections of code should not be "commented out" (自 R2024b 起)
MISRA C++:2023 Rule 5.7.3Line-splicing shall not be used in // comments (自 R2024b 起)
MISRA C++:2023 Rule 5.10.1User-defined identifiers shall have an appropriate form (自 R2024b 起)
MISRA C++:2023 Rule 5.13.1Within character literals and non raw-string literals, \ shall only be used to form a defined escape sequence or universal character name (自 R2024b 起)
MISRA C++:2023 Rule 5.13.2Octal escape sequences, hexadecimal escape sequences and universal character names shall be terminated (自 R2024b 起)
MISRA C++:2023 Rule 5.13.3Octal constants shall not be used (自 R2024b 起)
MISRA C++:2023 Rule 5.13.4Unsigned integer literals shall be appropriately suffixed (自 R2024b 起)
MISRA C++:2023 Rule 5.13.5The lowercase form of L shall not be used as the first character in a literal suffix (自 R2024b 起)
MISRA C++:2023 Rule 5.13.6An integer-literal of type long long shall not use a single L or l in any suffix (自 R2024b 起)
MISRA C++:2023 Rule 5.13.7String literals with different encoding prefixes shall not be concatenated (自 R2024b 起)
MISRA C++:2023 Rule 6.0.1Block scope declarations shall not be visually ambiguous (自 R2024b 起)
MISRA C++:2023 Rule 6.0.2When an array with external linkage is declared, its size should be explicitly specified (自 R2024b 起)
MISRA C++:2023 Rule 6.0.3The only declarations in the global namespace should be main, namespace declarations and extern "C" declarations (自 R2024b 起)
MISRA C++:2023 Rule 6.0.4The identifier main shall not be used for a function other than the global function main (自 R2024b 起)
MISRA C++:2023 Rule 6.2.1The one-definition rule shall not be violated (自 R2024b 起)
MISRA C++:2023 Rule 6.2.2All declarations of a variable or function shall have the same type (自 R2024b 起)
MISRA C++:2023 Rule 6.2.3The source code used to implement an entity shall appear only once (自 R2024b 起)
MISRA C++:2023 Rule 6.2.4A header file shall not contain definitions of functions or objects that are non-inline and have external linkage (自 R2024b 起)
MISRA C++:2023 Rule 6.4.1A variable declared in an inner scope shall not hide a variable declared in an outer scope (自 R2024b 起)
MISRA C++:2023 Rule 6.4.2Derived classes shall not conceal functions that are inherited from their bases (自 R2024b 起)
MISRA C++:2023 Rule 6.4.3A name that is present in a dependent base shall not be resolved by unqualified lookup (自 R2024b 起)
MISRA C++:2023 Rule 6.5.1A function or object with external linkage should be introduced in a header file (自 R2024b 起)
MISRA C++:2023 Rule 6.5.2Internal linkage should be specified appropriately (自 R2024b 起)
MISRA C++:2023 Rule 6.7.1Local variables shall not have static storage duration (自 R2024b 起)
MISRA C++:2023 Rule 6.7.2Global variables shall not be used (自 R2024b 起)
MISRA C++:2023 Rule 6.8.1An object shall not be accessed outside of its lifetime (自 R2024b 起)
MISRA C++:2023 Rule 6.8.2A function must not return a reference or a pointer to a local variable with automatic storage duration (自 R2024b 起)
MISRA C++:2023 Rule 6.8.3An assignment operator shall not assign the address of an object with automatic storage duration to an object with a greater lifetime (自 R2024b 起)
MISRA C++:2023 Rule 6.8.4Member functions returning references to their object should be ref-qualified appropriately (自 R2024b 起)
MISRA C++:2023 Rule 6.9.1The same type aliases shall be used in all declarations of the same entity (自 R2024b 起)
MISRA C++:2023 Rule 6.9.2The names of the standard signed integer types and standard unsigned integer types should not be used (自 R2024b 起)
MISRA C++:2023 Rule 7.0.1There shall be no conversion from type bool (自 R2024b 起)
MISRA C++:2023 Rule 7.0.2There shall be no conversion to type bool (自 R2024b 起)
MISRA C++:2023 Rule 7.0.3The numerical value of a character shall not be used (自 R2024b 起)
MISRA C++:2023 Rule 7.0.4The operands of bitwise operators and shift operators shall be appropriate (自 R2024b 起)
MISRA C++:2023 Rule 7.0.5Integral promotion and the usual arithmetic conversions shall not change the signedness or the type category of an operand (自 R2024b 起)
MISRA C++:2023 Rule 7.0.6Assignment between numeric types shall be appropriate (自 R2024b 起)
MISRA C++:2023 Rule 7.11.1nullptr shall be the only form of the null-pointer-constant (自 R2024b 起)
MISRA C++:2023 Rule 7.11.2An array passed as a function argument shall not decay to a pointer (自 R2024b 起)
MISRA C++:2023 Rule 7.11.3A conversion from function type to pointer-to-function type shall only occur in appropriate contexts (自 R2024b 起)
MISRA C++:2023 Rule 8.0.1Parentheses should be used to make the meaning of an expression appropriately explicit (自 R2024b 起)
MISRA C++:2023 Rule 8.1.1A non-transient lambda shall not implicitly capture this (自 R2024b 起)
MISRA C++:2023 Rule 8.1.2Variables should be captured explicitly in a non-transient lambda (自 R2024b 起)
MISRA C++:2023 Rule 8.2.1A virtual base class shall only be cast to a derived class by means of dynamic_cast (自 R2024b 起)
MISRA C++:2023 Rule 8.2.2C-style casts and functional notation casts shall not be used (自 R2024b 起)
MISRA C++:2023 Rule 8.2.3A cast shall not remove any const or volatile qualification from the type accessed via a pointer or by reference (自 R2024b 起)
MISRA C++:2023 Rule 8.2.4Casts shall not be performed between a pointer to function and any other type (自 R2024b 起)
MISRA C++:2023 Rule 8.2.5reinterpret_cast shall not be used (自 R2024b 起)
MISRA C++:2023 Rule 8.2.6An object with integral, enumerated, or pointer to void type shall not be cast to a pointer type (自 R2024b 起)
MISRA C++:2023 Rule 8.2.7A cast should not convert a pointer type to an integral type (自 R2024b 起)
MISRA C++:2023 Rule 8.2.8An object pointer type shall not be cast to an integral type other than std::uintptr_t or std::intptr_t (自 R2024b 起)
MISRA C++:2023 Rule 8.2.9The operand to typeid shall not be an expression of polymorphic class type (自 R2024b 起)
MISRA C++:2023 Rule 8.2.10Functions shall not call themselves, either directly or indirectly (自 R2024b 起)
MISRA C++:2023 Rule 8.2.11An argument passed via ellipsis shall have an appropriate type (自 R2024b 起)
MISRA C++:2023 Rule 8.3.1The built-in unary - operator should not be applied to an expression of unsigned type (自 R2024b 起)
MISRA C++:2023 Rule 8.3.2The built-in unary + operator should not be used (自 R2024b 起)
MISRA C++:2023 Rule 8.7.1Pointer arithmetic shall not form an invalid pointer (自 R2024b 起)
MISRA C++:2023 Rule 8.7.2Subtraction between pointers shall only be applied to pointers that address elements of the same array (自 R2024b 起)
MISRA C++:2023 Rule 8.9.1The built-in relational operators >, >=, < and <= shall not be applied to objects of pointer type, except where they point to elements of the same array (自 R2024b 起)
MISRA C++:2023 Rule 8.14.1The right-hand operand of a logical && or || operator should not contain persistent side effects (自 R2024b 起)
MISRA C++:2023 Rule 8.18.1An object or subobject must not be copied to an overlapping object (自 R2024b 起)
MISRA C++:2023 Rule 8.18.2The result of an assignment operator should not be used (自 R2024b 起)
MISRA C++:2023 Rule 8.19.1The comma operator should not be used (自 R2024b 起)
MISRA C++:2023 Rule 8.20.1An unsigned arithmetic operation with constant operands should not wrap (自 R2024b 起)
MISRA C++:2023 Rule 9.2.1An explicit type conversion shall not be an expression statement (自 R2024b 起)
MISRA C++:2023 Rule 9.3.1The body of an iteration-statement or a selection-statement shall be a compound-statement (自 R2024b 起)
MISRA C++:2023 Rule 9.4.1All if ... else if constructs shall be terminated with an else statement (自 R2024b 起)
MISRA C++:2023 Rule 9.4.2The structure of a switch statement shall be appropriate (自 R2024b 起)
MISRA C++:2023 Rule 9.5.1Legacy for statements should be simple (自 R2024b 起)
MISRA C++:2023 Rule 9.5.2A for-range-initializer shall contain at most one function call (自 R2024b 起)
MISRA C++:2023 Rule 9.6.1The goto statement should not be used (自 R2024b 起)
MISRA C++:2023 Rule 9.6.2A goto statement shall reference a label in a surrounding block (自 R2024b 起)
MISRA C++:2023 Rule 9.6.3 The goto statement shall jump to a label declared later in the function body (自 R2024b 起)
MISRA C++:2023 Rule 9.6.4A function declared with the [[noreturn]] attribute shall not return (自 R2024b 起)
MISRA C++:2023 Rule 9.6.5A function with non-void return type shall return a value on all paths (自 R2024b 起)
MISRA C++:2023 Rule 10.0.1A declaration should not declare more than one variable or member variable (自 R2024b 起)
MISRA C++:2023 Rule 10.1.1The target type of a pointer or lvalue reference parameter should be const-qualified appropriately (自 R2024b 起)
MISRA C++:2023 Rule 10.1.2The volatile qualifier shall be used appropriately (自 R2024b 起)
MISRA C++:2023 Rule 10.2.1An enumeration shall be defined with an explicit underlying type (自 R2024b 起)
MISRA C++:2023 Rule 10.2.2Unscoped enumerations should not be declared (自 R2024b 起)
MISRA C++:2023 Rule 10.2.3The numeric value of an unscoped enumeration with no fixed underlying type shall not be used (自 R2024b 起)
MISRA C++:2023 Rule 10.3.1There should be no unnamed namespaces in header files (自 R2024b 起)
MISRA C++:2023 Rule 10.4.1The asm declaration shall not be used (自 R2024b 起)
MISRA C++:2023 Rule 11.3.1Variables of array type should not be declared (自 R2024b 起)
MISRA C++:2023 Rule 11.3.2The declaration of an object should contain no more than two levels of pointer indirection (自 R2024b 起)
MISRA C++:2023 Rule 11.6.1All variables should be initialized (自 R2024b 起)
MISRA C++:2023 Rule 11.6.2The value of an object must not be read before it has been set (自 R2024b 起)
MISRA C++:2023 Rule 11.6.3Within an enumerator list, the value of an implicitly-specified enumeration constant shall be unique (自 R2024b 起)
MISRA C++:2023 Rule 12.2.1Bit-fields should not be declared (自 R2024b 起)
MISRA C++:2023 Rule 12.2.2A bit-field shall have an appropriate type (自 R2024b 起)
MISRA C++:2023 Rule 12.2.3A named bit-field with signed integer type shall not have a length of one bit (自 R2024b 起)
MISRA C++:2023 Rule 12.3.1The union keyword shall not be used (自 R2024b 起)
MISRA C++:2023 Rule 12.3.1The union keyword shall not be used (自 R2024b 起)
MISRA C++:2023 Rule 13.1.1Classes should not be inherited virtually (自 R2024b 起)
MISRA C++:2023 Rule 13.1.2An accessible base class shall not be both virtual and non-virtual in the same hierarchy (自 R2024b 起)
MISRA C++:2023 Rule 13.3.1User-declared member functions shall use the virtual, override and final specifiers appropriately (自 R2024b 起)
MISRA C++:2023 Rule 13.3.2Parameters in an overriding virtual function shall not specify different default arguments (自 R2024b 起)
MISRA C++:2023 Rule 13.3.3The parameters in all declarations or overrides of a function shall either be unnamed or have identical names (自 R2024b 起)
MISRA C++:2023 Rule 13.3.4A comparison of a potentially virtual pointer to member function shall only be with nullptr (自 R2024b 起)
MISRA C++:2023 Rule 14.1.1Non-static data members should be either all private or all public (自 R2024b 起)
MISRA C++:2023 Rule 15.0.1Special member functions shall be provided appropriately (自 R2024b 起)
MISRA C++:2023 Rule 15.0.2User-provided copy and move member functions of a class should have appropriate signatures (自 R2024b 起)
MISRA C++:2023 Rule 15.1.1An object's dynamic type shall not be used from within its constructor or destructor (自 R2024b 起)
MISRA C++:2023 Rule 15.1.2All constructors of a class should explicitly initialize all of its virtual base classes and immediate base classes (自 R2024b 起)
MISRA C++:2023 Rule 15.1.3Conversion operators and constructors that are callable with a single argument shall be explicit (自 R2024b 起)
MISRA C++:2023 Rule 15.1.4All direct, non-static data members of a class should be initialized before the class object is accessible (自 R2024b 起)
MISRA C++:2023 Rule 15.1.5A class shall only define an initializer-list constructor when it is the only constructor (自 R2024b 起)
MISRA C++:2023 Dir 15.8.1User-provided copy assignment operators and move assignment operators shall handle self-assignment (自 R2024b 起)
MISRA C++:2023 Rule 16.5.1The logical AND and logical OR operators shall not be overloaded (自 R2024b 起)
MISRA C++:2023 Rule 16.5.2The address-of operator shall not be overloaded (自 R2024b 起)
MISRA C++:2023 Rule 16.6.1Symmetrical operators should only be implemented as non-member functions (自 R2024b 起)
MISRA C++:2023 Rule 17.8.1Function templates shall not be explicitly specialized (自 R2024b 起)
MISRA C++:2023 Rule 18.1.1An exception object shall not have pointer type (自 R2024b 起)
MISRA C++:2023 Rule 18.1.2An empty throw shall only occur within the compound-statement of a catch handler (自 R2024b 起)
MISRA C++:2023 Rule 18.3.1There should be at least one exception handler to catch all otherwise unhandled exceptions (自 R2024b 起)
MISRA C++:2023 Rule 18.3.2An exception of class type shall be caught by const reference or reference (自 R2024b 起)
MISRA C++:2023 Rule 18.3.3Handlers for a function-try-block of a constructor or destructor shall not refer to non-static members from their class or its bases (自 R2024b 起)
MISRA C++:2023 Rule 18.4.1Exception-unfriendly functions shall be noexcept (自 R2024b 起)
MISRA C++:2023 Rule 18.5.1A noexcept function should not attempt to propagate an exception to the calling function (自 R2024b 起)
MISRA C++:2023 Rule 18.5.2Program-terminating functions should not be used (自 R2024b 起)
MISRA C++:2023 Rule 19.0.1A line whose first token is # shall be a valid preprocessing directive (自 R2024b 起)
MISRA C++:2023 Rule 19.0.2Function-like macros shall not be defined (自 R2024b 起)
MISRA C++:2023 Rule 19.0.3#include directives should only be preceded by preprocessor directives or comments (自 R2024b 起)
MISRA C++:2023 Rule 19.0.4#undef should only be used for macros defined previously in the same file (自 R2024b 起)
MISRA C++:2023 Rule 19.1.1The defined preprocessor operator shall be used appropriately (自 R2024b 起)
MISRA C++:2023 Rule 19.1.2All #else, #elif and #endif preprocessor directives shall reside in the same file as the #if, #ifdef or #ifndef directive to which they are related (自 R2024b 起)
MISRA C++:2023 Rule 19.1.3All identifiers used in the controlling expression of #if or #elif preprocessing directives shall be defined prior to evaluation (自 R2024b 起)
MISRA C++:2023 Rule 19.2.1Precautions shall be taken in order to prevent the contents of a header file being included more than once (自 R2024b 起)
MISRA C++:2023 Rule 19.2.2The #include directive shall be followed by either a <filename> or "filename" sequence (自 R2024b 起)
MISRA C++:2023 Rule 19.2.3The ' or " or \ characters and the /* or // character sequences shall not occur in a header file name (自 R2024b 起)
MISRA C++:2023 Rule 19.3.1The # and ## preprocessor operators should not be used (自 R2024b 起)
MISRA C++:2023 Rule 19.3.2A macro parameter immediately following a # operator shall not be immediately followed by a ## operator (自 R2024b 起)
MISRA C++:2023 Rule 19.3.3The argument to a mixed-use macro parameter shall not be subject to further expansion (自 R2024b 起)
MISRA C++:2023 Rule 19.3.4Parentheses shall be used to ensure macro arguments are expanded appropriately (自 R2024b 起)
MISRA C++:2023 Rule 19.3.5Tokens that look like a preprocessing directive shall not occur within a macro argument (自 R2024b 起)
MISRA C++:2023 Rule 19.6.1The #pragma directive and the _Pragma operator should not be used (自 R2024b 起)
MISRA C++:2023 Rule 21.2.1The library functions atof, atoi, atol and atoll from <cstdlib> shall not be used (自 R2024b 起)
MISRA C++:2023 Rule 21.2.2The string handling functions from <cstring>, <cstdlib>, <cwchar> and <cinttypes> shall not be used (自 R2024b 起)
MISRA C++:2023 Rule 21.2.3The library function system from <cstdlib> shall not be used (自 R2024b 起)
MISRA C++:2023 Rule 21.2.4The macro offsetof shall not be used (自 R2024b 起)
MISRA C++:2023 Rule 21.6.1Dynamic memory should not be used (自 R2024b 起)
MISRA C++:2023 Rule 21.6.2Dynamic memory shall be managed automatically (自 R2024b 起)
MISRA C++:2023 Rule 21.6.3Advanced memory management shall not be used (自 R2024b 起)
MISRA C++:2023 Rule 21.6.4If a project defines either a sized or unsized version of a global operator delete, then both shall be defined (自 R2024b 起)
MISRA C++:2023 Rule 21.6.5A pointer to an incomplete class type shall not be deleted (自 R2024b 起)
MISRA C++:2023 Rule 21.10.1The features of <cstdarg> shall not be used (自 R2024b 起)
MISRA C++:2023 Rule 21.10.2The standard header file <csetjmp> shall not be used (自 R2024b 起)
MISRA C++:2023 Rule 21.10.3The facilities provided by the standard header file <csignal> shall not be used (自 R2024b 起)
MISRA C++:2023 Rule 22.3.1The assert macro shall not be used with a constant-expression (自 R2024b 起)
MISRA C++:2023 Rule 22.4.1The literal value zero shall be the only value assigned to errno (自 R2024b 起)
MISRA C++:2023 Rule 23.11.1The raw pointer constructors of std::shared_ptr and std::unique_ptr should not be used (自 R2024b 起)
MISRA C++:2023 Rule 24.5.1The character handling functions from <cctype> and <cwctype> shall not be used (自 R2024b 起)
MISRA C++:2023 Rule 24.5.2The C++ Standard Library functions memcpy, memmove, memcmp from <cstring> shall not be used (自 R2024b 起)
MISRA C++:2023 Rule 25.5.1The setlocale and std::locale::global functions shall not be called (自 R2024b 起)
MISRA C++:2023 Rule 25.5.2The pointers returned by the C++ Standard Library functions localeconv, getenv, setlocale or strerror must only be used as if they have pointer to const-qualified type (自 R2024b 起)
MISRA C++:2023 Rule 25.5.3The pointer returned by the C++ Standard Library functions asctime, ctime, gmtime, localtime, localeconv, getenv, setlocale or strerror must not be used following a subsequent call to the same function (自 R2024b 起)
MISRA C++:2023 Rule 26.3.1std::vector should not be specialized with bool (自 R2024b 起)
MISRA C++:2023 Rule 28.3.1Predicates shall not have persistent side effects (自 R2024b 起)
MISRA C++:2023 Rule 28.6.1The argument to std::move shall be a non-const lvalue (自 R2024b 起)
MISRA C++:2023 Rule 28.6.2Forwarding references and std::forward shall be used together (自 R2024b 起)
MISRA C++:2023 Rule 28.6.3An object shall not be used while in a potentially moved-from state (自 R2024b 起)
MISRA C++:2023 Rule 28.6.4The result of std::remove, std::remove_if, std::unique and empty shall be used (自 R2024b 起)
MISRA C++:2023 Rule 30.0.1The C Library input/output functions shall not be used (自 R2024b 起)
MISRA C++:2023 Rule 30.0.2Reads and writes on the same file stream shall be separated by a positioning operation (自 R2024b 起)

主题