Bug Finder Results Found in Fast Analysis Mode
In fast analysis mode, Bug Finder checks for a subset of defects and coding rules. The tables
below list the results that can be found in a fast analysis. See also Use fast analysis mode
for Bug Finder (-fast-analysis)
.
These defects and coding standard violations are either found earlier in the analysis or leverage archived information from a previous analysis. The analysis results are comparatively easier to review and fix because most results can be understood by focusing on two or three lines of code (the line with the defect and one or two previous lines).
Because of the simplified nature of the analysis, you might see fewer defects in the fast analysis mode compared to a regular Bug Finder analysis.
Polyspace Bug Finder Defects
Static Memory
Name | Description |
---|---|
Buffer overflow from incorrect string format specifier ( str_format_buffer_overflow ) | String format specifier causes buffer argument of standard library functions to overflow |
Unreliable cast of function pointer ( func_cast ) | Function pointer cast to another function pointer with different argument or return type |
Unreliable cast of pointer ( ptr_cast ) | Pointer implicitly cast to different data type |
Programming
Name | Description |
---|---|
Copy of overlapping memory ( overlapping_copy ) | Source and destination arguments of a copy function have overlapping memory |
Exception caught by value ( excp_caught_by_value ) |
|
Exception handler hidden by previous handler ( excp_handler_hidden ) |
|
Format string specifiers and arguments mismatch ( string_format ) | String specifiers do not match corresponding arguments |
Improper array initialization ( improper_array_init ) | Incorrect array initialization when using initializers |
Invalid use of == operator ( bad_equal_equal_use ) | Equality operation in assignment statement |
Invalid use of = operator ( bad_equal_use ) | Assignment in conditional statement |
Invalid use of floating point operation ( bad_float_op ) | Imprecise comparison of floating point variables |
Missing null in string array ( missing_null_char ) | String does not terminate with null character |
Overlapping assignment ( overlapping_assign ) | Memory overlap between left and right sides of an assignment |
Possibly unintended evaluation of expression because of operator
precedence rules ( operator_precedence ) | Operator precedence rules cause unexpected evaluation order in arithmetic expression |
Unsafe conversion between pointer and integer ( bad_int_ptr_cast ) | Misaligned or invalid results from conversions between pointer and integer types |
Wrong type used in sizeof ( ptr_sizeof_mismatch ) |
|
Data Flow
Name | Description |
---|---|
Code deactivated by constant false condition ( deactivated_code ) | Code segment deactivated by |
Missing return statement ( missing_return ) | Function does not return value though return type is not void |
Static uncalled function ( uncalled_func ) | Function with static scope not called in file |
Variable shadowing ( var_shadowing ) | Variable hides another variable of same name with nested scope |
Object Oriented
Name | Description |
---|---|
*this not returned in copy assignment operator( return_not_ref_to_this ) | operator= method does not return a pointer to the current object |
Base class assignment operator not called ( missing_base_assign_op_call ) | Copy assignment operator does not call copy assignment operators of base subobjects |
Base class destructor not virtual ( dtor_not_virtual ) | Class cannot behave polymorphically for deletion of derived class objects |
Copy constructor not called in initialization list ( missing_copy_ctor_call ) | Copy constructor does not call copy constructors of some members or base classes |
Incompatible types prevent overriding ( virtual_func_hiding ) | Derived class method hides a virtual base class method instead of overriding it |
Member not initialized in constructor ( non_init_member ) | Constructor does not initialize some members of a class |
Missing explicit keyword ( missing_explicit_keyword ) | Constructor missing the explicit specifier |
Missing virtual inheritance ( missing_virtual_inheritance ) | A base class is inherited virtually and nonvirtually in the same hierarchy |
Object slicing ( object_slicing ) | Derived class object passed by value to function with base class parameter |
Partial override of overloaded virtual functions ( partial_override ) | Class overrides fraction of inherited virtual functions with a given name |
Return of non const handle to encapsulated data member ( breaking_data_encapsulation ) | Method returns pointer or reference to internal member of object |
Self assignment not tested in operator ( missing_self_assign_test ) | Copy assignment operator does not test for self-assignment |
Security
Name | Description |
---|---|
Function pointer assigned with absolute address ( func_ptr_absolute_addr ) | Constant expression is used as function address is vulnerable to code injection |
Good Practice
Name | Description |
---|---|
Bitwise and arithmetic operation on the same data ( bitwise_arith_mix ) | Statement with mixed bitwise and arithmetic operations |
Delete of void pointer ( delete_of_void_ptr ) | delete operates on a |
Hard-coded buffer size ( hard_coded_buffer_size ) | Size of memory buffer is a numerical value instead of symbolic constant |
Hard-coded loop boundary ( hard_coded_loop_boundary ) | Loop boundary is a numerical value instead of symbolic constant |
Large pass-by-value argument ( pass_by_value ) | Large argument passed by value between functions |
Line with more than one statement ( more_than_one_statement ) | Multiple statements on a line |
Missing break of switch case ( missing_switch_break ) | No comments at the end of switch case without a break statement |
Missing reset of a freed pointer ( missing_freed_ptr_reset ) | Pointer free not followed by a reset statement to clear leftover data |
Unused parameter ( unused_parameter ) | Function prototype has parameters not read or written in function body |
MISRA C:2004 and MISRA AC AGC Rules
The software checks the following rules early in the analysis.
Language Extensions
Rule | Description |
---|---|
2.1 | Assembly language shall be encapsulated and isolated. |
2.2 | Source code shall only use |
2.3 | The character sequence |
Documentation
Rule | Description |
---|---|
3.4 | All uses of the |
Character Sets
Rule | Description |
---|---|
4.1 | Only those escape sequences which are defined in the ISO C standard shall be used. |
4.2 | Trigraphs shall not be used. |
Identifiers
Rule | Description |
---|---|
5.2 | Identifiers in an inner scope shall not use the same name as an identifier in an outer scope, and therefore hide that identifier. |
Types
Rule | Description |
---|---|
6.1 | The plain char type shall be used only for the storage and use of character values. |
6.2 | Signed and unsigned char type shall be used only for the storage and use of numeric values. |
6.3 |
|
6.4 | Bit fields shall only be defined to be of type |
6.5 | Bit fields of type |
Constants
Rule | Description |
---|---|
7.1 | Octal constants (other than zero) and octal escape sequences shall not be used. |
Declarations and Definitions
Rule | Description |
---|---|
8.1 | Functions shall have prototype declarations and the prototype shall be visible at both the function definition and call. |
8.2 | Whenever an object or function is declared or defined, its type shall be explicitly stated. |
8.3 | For each function parameter the type given in the declaration and definition shall be identical, and the return types shall also be identical. |
8.5 | There shall be no definitions of objects or functions in a header file. |
8.6 | Functions shall always be declared at file scope. |
8.7 | Objects shall be defined at block scope if they are only accessed from within a single function. |
8.8 |
An external object or function shall be declared in one file and only one file. |
8.9 |
An identifier with external linkage shall have exactly one external definition. |
8.11 | The |
8.12 | When an array is declared with external linkage, its size shall be stated explicitly or defined implicitly by initialization. |
Initialization
Rule | Description |
---|---|
9.2 | Braces shall be used to indicate and match the structure in the nonzero initialization of arrays and structures. |
9.3 | In an enumerator list, the |
Arithmetic Type Conversion
Rule | Description |
---|---|
10.1 | The value of an expression of integer type shall not be implicitly converted to a different underlying type if:
|
10.2 | The value of an expression of floating type shall not be implicitly converted to a different type if
|
10.3 | The value of a complex expression of integer type may only be cast to a type that is narrower and of the same signedness as the underlying type of the expression. |
10.4 | The value of a complex expression of float type may only be cast to narrower floating type. |
10.5 | If the bitwise operator |
10.6 | The "U" suffix shall be applied to all constants of |
Pointer Type Conversion
Rule | Description |
---|---|
11.1 | Conversion shall not be performed between a pointer to a function and any type other than an integral type. |
11.2 | Conversion shall not be performed between a pointer to an object and any type other
than an integral type, another pointer to an object type or a
pointer to |
11.3 | A cast should not be performed between a pointer type and an integral type. |
11.4 | A cast should not be performed between a pointer to object type and a different pointer to object type. |
11.5 | A cast shall not be performed that removes any |
Expressions
Rule | Description |
---|---|
12.1 | Limited dependence should be placed on C's operator precedence rules in expressions. |
12.3 | The |
12.5 | The operands of a logical |
12.6 | Operands of logical operators ( |
12.7 | Bitwise operators shall not be applied to operands whose underlying type is signed. |
12.9 | The unary minus operator shall not be applied to an expression whose underlying type is unsigned. |
12.10 | The comma operator shall not be used. |
12.11 | Evaluation of constant unsigned expression should not lead to wraparound. |
12.12 | The underlying bit representations of floating-point values shall not be used. |
12.13 | The increment ( |
Control Statement Expressions
Rule | Description |
---|---|
13.1 | Assignment operators shall not be used in expressions that yield Boolean values. |
13.2 | Tests of a value against zero should be made explicit, unless the operand is effectively Boolean. |
13.3 | Floating-point expressions shall not be tested for equality or inequality. |
13.4 | The controlling expression of a |
13.5 | The three expressions of a |
13.6 | Numeric variables being used within a |
Control Flow
Rule | Description |
---|---|
14.3 | All non-null statements shall either
|
14.4 | The |
14.5 | The |
14.6 | For any iteration statement, there shall be at most one |
14.7 | A function shall have a single point of exit at the end of the function. |
14.8 | The statement forming the body of a |
14.9 | An |
14.10 | All |
Switch Statements
Rule | Description |
---|---|
15.0 | Unreachable code is detected between |
15.1 | A |
15.2 | An unconditional |
15.3 | The final clause of a |
15.4 | A |
15.5 | Every |
Functions
Rule | Description |
---|---|
16.1 | Functions shall not be defined with variable numbers of arguments. |
16.3 | Identifiers shall be given for all of the parameters in a function prototype declaration. |
16.5 | Functions with no parameters shall be declared with parameter
type |
16.6 | The number of arguments passed to a function shall match the number of parameters. |
16.8 | All exit paths from a function with non- |
16.9 | A function identifier shall only be used with either
a preceding |
Pointers and Arrays
Rule | Description |
---|---|
17.4 | Array indexing shall be the only allowed form of pointer arithmetic. |
17.5 | A type should not contain more than 2 levels of pointer indirection. |
Structures and Unions
Rule | Description |
---|---|
18.1 | All structure or union types shall be complete at the end of a translation unit. |
18.4 | Unions shall not be used. |
Preprocessing Directives
Rule | Description |
---|---|
19.1 |
|
19.2 | Nonstandard characters should not occur in header file
names in |
19.3 | The |
19.4 | C macros shall only expand to a braced initializer, a constant, a parenthesized expression, a type qualifier, a storage class specifier, or a do-while-zero construct. |
19.5 | Macros shall not be |
19.6 |
|
19.7 | A function should be used in preference to a function like-macro. |
19.8 | A function-like macro shall not be invoked without all of its arguments. |
19.9 | Arguments to a function-like macro shall not contain tokens that look like preprocessing directives. |
19.10 | In the definition of a function-like macro, each instance
of a parameter shall be enclosed in parentheses unless it is used
as the operand of |
19.11 | All macro identifiers in preprocessor directives shall
be defined before use, except in |
19.12 | There shall be at most one occurrence of the |
19.13 | The |
19.14 | The defined preprocessor operator shall only be used in one of the two standard forms. |
19.15 | Precautions shall be taken in order to prevent the contents of a header file being included twice. |
19.16 | Preprocessing directives shall be syntactically meaningful even when excluded by the preprocessor. |
19.17 | All |
Standard Libraries
Rule | Description |
---|---|
20.1 | Reserved identifiers, macros and functions in the standard library, shall not be defined, redefined or undefined. |
20.2 | The names of standard library macros, objects and functions shall not be reused. |
20.4 | Dynamic heap memory allocation shall not be used. |
20.5 | The error indicator |
20.6 | The macro |
20.7 | The |
20.8 | The signal handling facilities of |
20.9 | The input/output library |
20.10 | The library functions |
20.11 | The library functions |
20.12 | The time handling functions of library |
MISRA C:2012 Rules
Standard C Environment
Rule | Description |
---|---|
1.1 | The program shall contain no violations of the standard C syntax and constraints, and shall not exceed the implementation's translation limits. |
1.2 | Language extensions should not be used. |
Unused Code
Rule | Description |
---|---|
2.6 | A function should not contain unused label declarations. |
2.7 | There should be no unused parameters in functions. |
Comments
Rule | Description |
---|---|
3.1 | The character sequences |
3.2 | Line-splicing shall not be used in |
Character Sets and Lexical Conventions
Rule | Description |
---|---|
4.1 | Octal and hexadecimal escape sequences shall be terminated. |
4.2 | Trigraphs should not be used. |
Identifiers
Rule | Description |
---|---|
5.2 | Identifiers declared in the same scope and name space shall be distinct. |
5.3 | An identifier declared in an inner scope shall not hide an identifier declared in an outer scope. |
5.4 | Macro identifiers shall be distinct. |
5.5 | Identifiers shall be distinct from macro names. |
Types
Rule | Description |
---|---|
6.1 | Bit-fields shall only be declared with an appropriate type. |
6.2 | Single-bit named bit fields shall not be of a signed type. |
Literals and Constants
Rule | Description |
---|---|
7.1 | Octal constants shall not be used. |
7.2 | A "u" or "U" suffix shall be applied to all integer constants that are represented in an unsigned type. |
7.3 | The lowercase character "l" shall not be used in a literal suffix. |
7.4 | A string literal shall not be assigned to an object unless the object's type is "pointer to const-qualified char". |
Declarations and Definitions
Rule | Description |
---|---|
8.1 | Types shall be explicitly specified. |
8.2 | Function types shall be in prototype form with named parameters. |
8.4 | A compatible declaration shall be visible when an object or function with external linkage is defined. |
8.5 | An external object or function shall be declared once in one and only one file. |
8.6 | An identifier with external linkage shall have exactly one external definition. |
8.8 | The |
8.10 | An inline function shall be declared with the |
8.11 | When an array with external linkage is declared, its size should be explicitly specified. |
8.12 | Within an enumerator list, the value of an implicitly-specified enumeration constant shall be unique. |
8.14 | The |
Initialization
Rule | Description |
---|---|
9.2 | The initializer for an aggregate or union shall be enclosed in braces. |
9.3 | Arrays shall not be partially initialized. |
9.4 | An element of an object shall not be initialized more than once. |
9.5 | Where designated initializers are used to initialize an array object the size of the array shall be specified explicitly. |
The Essential Type Model
Rule | Description |
---|---|
10.1 | Operands shall not be of an inappropriate essential type. |
10.2 | Expressions of essentially character type shall not be used inappropriately in addition and subtraction operations. |
10.3 | The value of an expression shall not be assigned to an object with a narrower essential type or of a different essential type category. |
10.4 | Both operands of an operator in which the usual arithmetic conversions are performed shall have the same essential type category. |
10.5 | The value of an expression should not be cast to an inappropriate essential type. |
10.6 | The value of a composite expression shall not be assigned to an object with wider essential type. |
10.7 | If a composite expression is used as one operand of an operator in which the usual arithmetic conversions are performed then the other operand shall not have wider essential type. |
10.8 | The value of a composite expression shall not be cast to a different essential type category or a wider essential type. |
Pointer Type Conversion
Rule | Description |
---|---|
11.1 | Conversions shall not be performed between a pointer to a function and any other type. |
11.2 | Conversions shall not be performed between a pointer to an incomplete type and any other type. |
11.3 | A cast shall not be performed between a pointer to object type and a pointer to a different object type. |
11.4 | A conversion should not be performed between a pointer to object and an integer type. |
11.5 | A conversion should not be performed from pointer to void into pointer to object. |
11.6 | A cast shall not be performed between pointer to void and an arithmetic type. |
11.7 | A cast shall not be performed between pointer to object and a non-integer arithmetic type. |
11.8 | A cast shall not remove any const or volatile qualification from the type pointed to by a pointer. |
11.9 | The macro |
Expressions
Rule | Description |
---|---|
12.1 | The precedence of operators within expressions should be made explicit. |
12.3 | The comma operator should not be used. |
12.4 | Evaluation of constant expressions should not lead to unsigned integer wrap-around. |
Side Effects
Rule | Description |
---|---|
13.3 | A full expression containing an increment ( |
13.4 | The result of an assignment operator should not be used. |
13.6 | The operand of the |
Control Statement Expressions
Rule | Description |
---|---|
14.4 | The controlling expression of an |
Control Flow
Rule | Description |
---|---|
15.1 | The |
15.2 | The |
15.3 | Any label referenced by a |
15.4 | There should be no more than one |
15.5 | A function should have a single point of exit at the end |
15.6 | The body of an iteration-statement or a selection-statement shall be a compound statement. |
15.7 | All |
Switch Statements
Rule | Description |
---|---|
16.1 | All |
16.2 | A |
16.3 | An unconditional |
16.4 | Every |
16.5 | A |
16.6 | Every |
16.7 | A |
Functions
Rule | Description |
---|---|
17.1 | The features of |
17.3 | A function shall not be declared implicitly. |
17.4 | All exit paths from a function with non- |
17.6 | The declaration of an array parameter shall not contain
the |
17.7 | The value returned by a function having non- |
Pointers and Arrays
Rule | Description |
---|---|
18.4 | The |
18.5 | Declarations should contain no more than two levels of pointer nesting. |
18.7 | Flexible array members shall not be declared. |
18.8 | Variable-length array types shall not be used. |
Overlapping Storage
Rule | Description |
---|---|
19.2 | The |
Preprocessing Directives
Rule | Description |
---|---|
20.1 |
|
20.2 | The |
20.3 | The |
20.4 | A macro shall not be defined with the same name as a keyword. |
20.5 |
|
20.6 | Tokens that look like a preprocessing directive shall not occur within a macro argument. |
20.7 | Expressions resulting from the expansion of macro parameters shall be enclosed in parentheses. |
20.8 | The controlling expression of a |
20.9 | All identifiers used in the controlling expression of |
20.10 | The |
20.11 | A macro parameter immediately following a |
20.12 | A macro parameter used as an operand to the |
20.13 | A line whose first token is |
20.14 | All |
Standard Libraries
Rule | Description |
---|---|
21.1 |
|
21.2 | A reserved identifier or macro name shall not be declared. |
21.3 | The memory allocation and deallocation functions of |
21.4 | The standard header file |
21.5 | The standard header file |
21.6 | The Standard Library input/output functions shall not be used. |
21.7 | The |
21.8 | The library functions |
21.9 | The library functions |
21.10 | The Standard Library time and date functions shall not be used. |
21.11 | The standard header file |
21.12 | The exception handling features of |
MISRA C++ 2008 Rules
Language Independent Issues
Rule | Description |
---|---|
0-1-7 | The value returned by a function having a non-void return type that is not an overloaded operator shall always be used. |
0-1-11 | There shall be no unused parameters (named or unnamed) in non- virtual functions. |
0-1-12 | There shall be no unused parameters (named or unnamed) in the set of parameters for a virtual function and all the functions that override it. |
0-2-1 | An object shall not be assigned to an overlapping object. |
General
Rule | Description |
---|---|
1-0-1 | All code shall conform to ISO/IEC 14882:2003 "The C++ Standard Incorporating Technical Corrigendum 1". |
Lexical Conventions
Rule | Description |
---|---|
2-3-1 | Trigraphs shall not be used. |
2-5-1 | Digraphs should not be used. |
2-7-1 | The character sequence /* shall not be used within a C-style comment. |
2-10-1 | Different identifiers shall be typographically unambiguous. |
2-10-2 | Identifiers declared in an inner scope shall not hide an identifier declared in an outer scope. |
2-10-3 | A typedef name (including qualification, if any) shall be a unique identifier. |
2-10-4 | A class, union or enum name (including qualification, if any) shall be a unique identifier. |
2-10-6 | If an identifier refers to a type, it shall not also refer to an object or a function in the same scope. |
2-13-1 | Only those escape sequences that are defined in ISO/IEC 14882:2003 shall be used. |
2-13-2 | Octal constants (other than zero) and octal escape sequences (other than "\0") shall not be used. |
2-13-3 | A "U" suffix shall be applied to all octal or hexadecimal integer literals of unsigned type. |
2-13-4 | Literal suffixes shall be upper case. |
2-13-5 | Narrow and wide string literals shall not be concatenated. |
Basic Concepts
Rule | Description |
---|---|
3-1-1 | It shall be possible to include any header file in multiple translation units without violating the One Definition Rule. |
3-1-2 | Functions shall not be declared at block scope. |
3-1-3 | When an array is declared, its size shall either be stated explicitly or defined implicitly by initialization. |
3-3-1 | Objects or functions with external linkage shall be declared in a header file. |
3-3-2 | If a function has internal linkage then all re-declarations shall include the static storage class specifier. |
3-4-1 | An identifier declared to be an object or type shall be defined in a block that minimizes its visibility. |
3-9-1 | The types used for an object, a function return type, or a function parameter shall be token-for-token identical in all declarations and re-declarations. |
3-9-2 | Typedefs that indicate size and signedness should be used in place of the basic numerical types. |
3-9-3 | The underlying bit representations of floating-point values shall not be used. |
Standard Conversions
Rule | Description |
---|---|
4-5-1 | Expressions with type bool shall not be used as operands to built-in operators other than the assignment operator =, the logical operators &&, ||, !, the equality operators == and !=, the unary & operator, and the conditional operator. |
4-5-2 | Expressions with type enum shall not be used as operands to built- in operators other than the subscript operator [ ], the assignment operator =, the equality operators == and !=, the unary & operator, and the relational operators <, <=, >, >=. |
4-5-3 | Expressions with type (plain) char and wchar_t shall not be used as operands to built-in operators other than the assignment operator =, the equality operators == and !=, and the unary & operator. |
Expressions
Rule | Description |
---|---|
5-0-1 | The value of an expression shall be the same under any order of evaluation that the standard permits. |
5-0-2 | Limited dependence should be placed on C++ operator precedence rules in expressions. |
5-0-3 | A cvalue expression shall not be implicitly converted to a different underlying type. |
5-0-4 | An implicit integral conversion shall not change the signedness of the underlying type. |
5-0-5 | There shall be no implicit floating-integral conversions. |
5-0-6 | An implicit integral or floating-point conversion shall not reduce the size of the underlying type. |
5-0-7 | There shall be no explicit floating-integral conversions of a cvalue expression. |
5-0-8 | An explicit integral or floating-point conversion shall not increase the size of the underlying type of a cvalue expression. |
5-0-9 | An explicit integral conversion shall not change the signedness of the underlying type of a cvalue expression. |
5-0-10 | If the bitwise operators ~ and << are applied to an operand with an underlying type of unsigned char or unsigned short, the result shall be immediately cast to the underlying type of the operand. |
5-0-11 | The plain char type shall only be used for the storage and use of character values. |
5-0-12 | signed char and unsigned char type shall only be used for the storage and use of numeric values. |
5-0-13 | The condition of an if-statement and the condition of an iteration-statement shall have type bool. |
5-0-14 | The first operand of a conditional-operator shall have type bool. |
5-0-15 | Array indexing shall be the only form of pointer arithmetic. |
5-0-18 | >, >=, <, <= shall not be applied to objects of pointer type, except where they point to the same array. |
5-0-19 | The declaration of objects shall contain no more than two levels of pointer indirection. |
5-0-20 | Non-constant operands to a binary bitwise operator shall have the same underlying type. |
5-0-21 | Bitwise operators shall only be applied to operands of unsigned underlying type. |
5-2-1 | Each operand of a logical && or || shall be a postfix - expression. |
5-2-2 | A pointer to a virtual base class shall only be cast to a pointer to a derived class by means of dynamic_cast. |
5-2-3 | Casts from a base class to a derived class should not be performed on polymorphic types. |
5-2-4 | C-style casts (other than void casts) and functional notation casts (other than explicit constructor calls) shall not be used. |
5-2-5 | A cast shall not remove any const or volatile qualification from the type of a pointer or reference. |
5-2-6 | A cast shall not convert a pointer to a function to any other pointer type, including a pointer to function type. |
5-2-7 | An object with pointer type shall not be converted to an unrelated pointer type, either directly or indirectly. |
5-2-8 | An object with integer type or pointer to void type shall not be converted to an object with pointer type. |
5-2-9 | A cast should not convert a pointer type to an integral type. |
5-2-10 | The increment ( ++ ) and decrement ( -- ) operators should not be mixed with other operators in an expression. |
5-2-11 | The comma operator, && operator and the || operator shall not be overloaded. |
5-2-12 | An identifier with array type passed as a function argument shall not decay to a pointer. |
5-3-1 | Each operand of the ! operator, the logical && or the logical || operators shall have type bool. |
5-3-2 | The unary minus operator shall not be applied to an expression whose underlying type is unsigned. |
5-3-3 | The unary & operator shall not be overloaded. |
5-3-4 | Evaluation of the operand to the sizeof operator shall not contain side effects. |
5-8-1 | The right hand operand of a shift operator shall lie between zero and one less than the width in bits of the underlying type of the left hand operand. |
5-14-1 | The right hand operand of a logical && or || operator shall not contain side effects. |
5-18-1 | The comma operator shall not be used. |
5-19-1 | Evaluation of constant unsigned integer expressions should not lead to wrap-around. |
Statements
Rule | Description |
---|---|
6-2-1 | Assignment operators shall not be used in sub-expressions. |
6-2-2 | Floating-point expressions shall not be directly or indirectly tested for equality or inequality. |
6-2-3 | Before preprocessing, a null statement shall only occur on a line by itself; it may be followed by a comment, provided that the first character following the null statement is a white - space character. |
6-3-1 | The statement forming the body of a switch, while, do ... while or for statement shall be a compound statement. |
6-4-1 | An if ( condition ) construct shall be followed by a compound statement. The else keyword shall be followed by either a compound statement, or another if statement. |
6-4-2 | All if ... else if constructs shall be terminated with an else clause. |
6-4-3 | A switch statement shall be a well-formed switch statement. |
6-4-4 | A switch-label shall only be used when the most closely-enclosing compound statement is the body of a switch statement. |
6-4-5 | An unconditional throw or break statement shall terminate every non - empty switch-clause. |
6-4-6 | The final clause of a switch statement shall be the default-clause. |
6-4-7 | The condition of a switch statement shall not have bool type. |
6-4-8 | Every switch statement shall have at least one case-clause. |
6-5-1 | A for loop shall contain a single loop-counter which shall not have floating type. |
6-5-2 | If loop-counter is not modified by -- or ++, then, within condition, the loop-counter shall only be used as an operand to <=, <, > or >=. |
6-5-3 | The loop-counter shall not be modified within condition or statement. |
6-5-4 | The loop-counter shall be modified by one of: --, ++, -=n, or +=n ; where n remains constant for the duration of the loop. |
6-5-5 | A loop-control-variable other than the loop-counter shall not be modified within condition or expression. |
6-5-6 | A loop-control-variable other than the loop-counter which is modified in statement shall have type bool. |
6-6-1 | Any label referenced by a goto statement shall be declared in the same block, or in a block enclosing the goto statement. |
6-6-2 | The goto statement shall jump to a label declared later in the same function body. |
6-6-3 | The continue statement shall only be used within a well-formed for loop. |
6-6-4 | For any iteration statement there shall be no more than one break or goto statement used for loop termination. |
6-6-5 | A function shall have a single point of exit at the end of the function. |
Declarations
Rule | Description |
---|---|
7-3-1 | The global namespace shall only contain main, namespace declarations and extern "C" declarations. |
7-3-2 | The identifier main shall not be used for a function other than the global function main. |
7-3-3 | There shall be no unnamed namespaces in header files. |
7-3-4 | using-directives shall not be used. |
7-3-5 | Multiple declarations for an identifier in the same namespace shall not straddle a using-declaration for that identifier. |
7-3-6 | using-directives and using-declarations (excluding class scope or function scope using-declarations) shall not be used in header files. |
7-4-2 | Assembler instructions shall only be introduced using the asm declaration. |
7-4-3 | Assembly language shall be encapsulated and isolated. |
Declarators
Rule | Description |
---|---|
8-0-1 | An init-declarator-list or a member-declarator-list shall consist of a single init-declarator or member-declarator respectively. |
8-3-1 | Parameters in an overriding virtual function shall either use the same default arguments as the function they override, or else shall not specify any default arguments. |
8-4-1 | Functions shall not be defined using the ellipsis notation. |
8-4-2 | The identifiers used for the parameters in a re-declaration of a function shall be identical to those in the declaration. |
8-4-3 | All exit paths from a function with non- void return type shall have an explicit return statement with an expression. |
8-4-4 | A function identifier shall either be used to call the function or it shall be preceded by &. |
8-5-2 | Braces shall be used to indicate and match the structure in the non- zero initialization of arrays and structures. |
8-5-3 | In an enumerator list, the = construct shall not be used to explicitly initialize members other than the first, unless all items are explicitly initialized. |
Classes
Rule | Description |
---|---|
9-3-1 | const member functions shall not return non-const pointers or references to class-data. |
9-3-2 | Member functions shall not return non-const handles to class-data. |
9-5-1 | Unions shall not be used. |
9-6-2 | Bit-fields shall be either bool type or an explicitly unsigned or signed integral type. |
9-6-3 | Bit-fields shall not have enum type. |
9-6-4 | Named bit-fields with signed integer type shall have a length of more than one bit. |
Derived Classes
Rule | Description |
---|---|
10-1-1 | Classes should not be derived from virtual bases. |
10-1-2 | A base class shall only be declared virtual if it is used in a diamond hierarchy. |
10-1-3 | An accessible base class shall not be both virtual and non-virtual in the same hierarchy. |
10-2-1 | All accessible entity names within a multiple inheritance hierarchy should be unique. |
10-3-1 | There shall be no more than one definition of each virtual function on each path through the inheritance hierarchy. |
10-3-2 | Each overriding virtual function shall be declared with the virtual keyword. |
10-3-3 | A virtual function shall only be overridden by a pure virtual function if it is itself declared as pure virtual. |
Member Access Control
Rule | Description |
---|---|
11-0-1 | Member data in non- POD class types shall be private. |
Special Member Functions
Rule | Description |
---|---|
12-1-1 | An object's dynamic type shall not be used from the body of its constructor or destructor. |
12-1-2 | All constructors of a class should explicitly call a constructor for all of its immediate base classes and all virtual base classes. |
12-1-3 | All constructors that are callable with a single argument of fundamental type shall be declared explicit. |
12-8-1 | A copy constructor shall only initialize its base classes and the non- static members of the class of which it is a member. |
12-8-2 | The copy assignment operator shall be declared protected or private in an abstract class. |
Templates
Rule | Description |
---|---|
14-5-2 | A copy constructor shall be declared when there is a template constructor with a single parameter that is a generic parameter. |
14-5-3 | A copy assignment operator shall be declared when there is a template assignment operator with a parameter that is a generic parameter. |
14-6-1 | In a class template with a dependent base, any name that may be found in that dependent base shall be referred to using a qualified-id or this->. |
14-6-2 | The function chosen by overload resolution shall resolve to a function declared previously in the translation unit. |
14-7-3 | All partial and explicit specializations for a template shall be declared in the same file as the declaration of their primary template. |
14-8-1 | Overloaded function templates shall not be explicitly specialized. |
14-8-2 | The viable function set for a function call should either contain no function specializations, or only contain function specializations. |
Exception Handling
Rule | Description |
---|---|
15-0-2 | An exception object should not have pointer type. |
15-0-3 | Control shall not be transferred into a try or catch block using a goto or a switch statement. |
15-1-2 | NULL shall not be thrown explicitly. |
15-1-3 | An empty throw (throw;) shall only be used in the compound- statement of a catch handler. |
15-3-2 | There should be at least one exception handler to catch all otherwise unhandled exceptions |
15-3-3 | Handlers of a function-try-block implementation of a class constructor or destructor shall not reference non-static members from this class or its bases. |
15-3-5 | A class type exception shall always be caught by reference. |
15-3-6 | Where multiple handlers are provided in a single try-catch statement or function-try-block for a derived class and some or all of its bases, the handlers shall be ordered most-derived to base class. |
15-3-7 | Where multiple handlers are provided in a single try-catch statement or function-try-block, any ellipsis (catch-all) handler shall occur last. |
15-5-1 | A class destructor shall not exit with an exception. |
15-5-2 | Where a function's declaration includes an exception-specification, the function shall only be capable of throwing exceptions of the indicated type(s). |
Preprocessing Directives
Rule | Description |
---|---|
16-0-1 | #include directives in a file shall only be preceded by other preprocessor directives or comments. |
16-0-2 | Macros shall only be #define 'd or #undef 'd in the global namespace. |
16-0-3 | #undef shall not be used. |
16-0-4 | Function-like macros shall not be defined. |
16-0-5 | Arguments to a function-like macro shall not contain tokens that look like preprocessing directives. |
16-0-6 | In the definition of a function-like macro, each instance of a parameter shall be enclosed in parentheses, unless it is used as the operand of # or ##. |
16-0-7 | Undefined macro identifiers shall not be used in #if or #elif preprocessor directives, except as operands to the defined operator. |
16-0-8 | If the # token appears as the first token on a line, then it shall be immediately followed by a preprocessing token. |
16-1-1 | The defined preprocessor operator shall only be used in one of the two standard forms. |
16-1-2 | All #else, #elif and #endif preprocessor directives shall reside in the same file as the #if or #ifdef directive to which they are related. |
16-2-1 | The pre-processor shall only be used for file inclusion and include guards. |
16-2-2 | C++ macros shall only be used for: include guards, type qualifiers, or storage class specifiers. |
16-2-3 | Include guards shall be provided. |
16-2-4 | The ', ", /* or // characters shall not occur in a header file name. |
16-2-5 | The \ character should not occur in a header file name. |
16-2-6 | The #include directive shall be followed by either a <filename> or "filename" sequence. |
16-3-1 | There shall be at most one occurrence of the # or ## operators in a single macro definition. |
16-3-2 | The # and ## operators should not be used. |
16-6-1 | All uses of the #pragma directive shall be documented. |
17-0-1 | Reserved identifiers, macros and functions in the standard library shall not be defined, redefined or undefined. |
17-0-2 | The names of standard library macros and objects shall not be reused. |
17-0-5 | The setjmp macro and the longjmp function shall not be used. |
Language Support Library
Rule | Description |
---|---|
18-0-1 | The C library shall not be used. |
18-0-2 | The library functions atof, atoi and atol from library <cstdlib> shall not be used. |
18-0-3 | The library functions abort, exit, getenv and system from library <cstdlib> shall not be used. |
18-0-4 | The time handling functions of library <ctime> shall not be used. |
18-0-5 | The unbounded functions of library <cstring> shall not be used. |
18-2-1 | The macro offsetof shall not be used. |
18-4-1 | Dynamic heap memory allocation shall not be used. |
18-7-1 | The signal handling facilities of <csignal> shall not be used. |
Diagnostic Library
Rule | Description |
---|---|
19-3-1 | The error indicator errno shall not be used. |
Input/Output Library
Rule | Description |
---|---|
27-0-1 | The stream input/output library <cstdio> shall not be used. |