メインコンテンツ

高速解析モードで検出される Bug Finder の結果

高速解析モードでは、Bug Finder は欠陥とコーディング ルールのサブセットをチェックします。次の表は、高速解析で検出できる結果を示しています。Bug Finder を高速解析モードで使用 (-fast-analysis) も参照してください。

これらの欠陥とコーディング規約違反は、解析で早期に発見されるか、以前の解析からのアーカイブ情報を利用します。解析結果の確認と修正は比較的容易です。これは、ほとんどの結果は 2 ~ 3 行のコード (欠陥のある行とその前の 1 ~ 2 行) に注目すれば理解できるためです。

簡略化された解析であるため、高速解析モードでは通常の Bug Finder 解析と比較して、表示される欠陥が少なくなる可能性があります。

Polyspace Bug Finder の欠陥

静的メモリ

名前説明
無効な文字列形式指定子によるバッファー オーバーフロー
(str_format_buffer_overflow)

文字列形式指定子により標準ライブラリ関数のバッファー引数でオーバーフローが発生

関数ポインターの信頼性の低いキャスト
(func_cast)

関数ポインターの、引数または戻り値の型が異なる別の関数ポインターへのキャスト

ポインターの信頼性の低いキャスト
(ptr_cast)

暗黙的に別のデータ型にキャストされるポインター

プログラミング

名前説明
オーバーラップするメモリのコピーです
(overlapping_copy)

コピー関数のソース引数とコピー先引数にオーバーラップするメモリがある

例外が値によってキャッチされました
(excp_caught_by_value)

catch ステートメントがオブジェクトを値によって受け取る

前のハンドラーによって隠された例外ハンドラーです
(excp_handler_hidden)

同じ例外に対して catch ステートメントが先行しているため、catch ステートメントに到達しない

書式文字列指定子と引数の不一致
(string_format)

文字列指定子が対応する引数と一致しない

配列の初期化が不適切です
(improper_array_init)

初期化子を使用した場合の配列の初期化が正しくない

== 演算子の無効な使用
(bad_equal_equal_use)

代入ステートメント内の等号演算子

= 演算子の無効な使用
(bad_equal_use)

条件付きステートメント内の代入

浮動小数点演算の無効な使用
(bad_float_op)

浮動小数点変数の不正確な比較

文字列配列での null 値の欠落
(missing_null_char)

文字列が null 文字で終了していない

代入が重複しています
(overlapping_assign)

代入の左辺と右辺間のメモリ オーバーラップ

演算子の優先順位のルールにより、予期せぬ式の評価が得られる可能性があります
(operator_precedence)

演算子の優先順位のルールにより、演算式での評価順が予想外のものになる

ポインターと整数間での変換は安全ではありません
(bad_int_ptr_cast)

ポインターと整数型間の変換によるミスアライメントまたは不適切な結果

sizeof において使用された誤った型
(ptr_sizeof_mismatch)

sizeof の引数が指している型と一致しない

データ フロー

名前説明
条件が常に false であるために非アクティブにされたコード
(deactivated_code)

#if 0 命令または if(0) 条件によって非アクティブにされたコード セグメント

return ステートメントがありません
(missing_return)

関数が値を返さないが、戻り値の型は void ではない

呼び出されていない静的関数
(uncalled_func)

ファイルで呼び出されない静的スコープをもつ関数

変数のシャドウイング
(var_shadowing)

入れ子にされたスコープで変数が同じ名前の別の変数を隠す

オブジェクト指向

名前説明
*this はコピー代入演算子に返されません
(return_not_ref_to_this)

operator= メソッドが現在のオブジェクトを指すポインターを返さない

基底クラスの代入演算子が呼び出されていません
(missing_base_assign_op_call)

コピー代入演算子が、基底サブオブジェクトのコピー代入演算子を呼び出さない

基底クラス デストラクターが非バーチャルです
(dtor_not_virtual)

派生クラス オブジェクトの削除にあたりクラスがポリモーフィックに動作できない

コピー コンストラクターが初期化リストで呼び出されていません
(missing_copy_ctor_call)

コピー コンストラクターが一部のメンバーまたは基底クラスのコピー コンストラクターを呼び出さない

型に互換性がないためオーバーライドされません
(virtual_func_hiding)

派生クラスのメソッドが virtual 基底クラスのメソッドをオーバーライドせずに隠している

コンストラクターでメンバーが初期化されません
(non_init_member)

コンストラクターでクラスのメンバーの一部が初期化されない

明示的なキーワードがありません
(missing_explicit_keyword)

コンストラクターに指定子 explicit がない

バーチャル継承がありません
(missing_virtual_inheritance)

基底クラスが同じ階層内でバーチャルに継承され、また非バーチャルに継承されている

オブジェクトのスライス
(object_slicing)

派生クラス オブジェクトが基底クラス パラメーターをもつ関数に値渡しされる

オーバーロードされたバーチャル関数の一部のみをオーバーライドします
(partial_override)

特定名をもつ継承されたバーチャル関数の一部をクラスがオーバーライド

カプセル化されたデータ メンバーに定数ではないハンドルが返されています
(breaking_data_encapsulation)

メソッドにより、オブジェクトの内部メンバーへのポインターまたは参照が返される

自己代入が演算子でテストされていません
(missing_self_assign_test)

コピー代入演算子で自己代入がテストされない

セキュリティ

名前説明
関数ポインターに絶対アドレスが割り当てられています
(func_ptr_absolute_addr)

関数アドレスとして使用される定数式にコード インジェクションに対する脆弱性がある

適切な手法

名前説明
同じデータに対してビット演算と算術演算が行われています
(bitwise_arith_mix)

ビット演算と算術演算が混在したステートメント

void ポインターが削除されています
(delete_of_void_ptr)

オブジェクトを指す void* ポインターに対し delete を実行

バッファー サイズがハードコードされています
(hard_coded_buffer_size)

メモリ バッファーのサイズがシンボリック定数ではなく数値になっている

ループ境界がハード コードされています
(hard_coded_loop_boundary)

ループ境界がシンボリック定数でなく数値になっている

値渡しの大きな引数
(pass_by_value)

関数間で値渡しされる大きな引数

ステートメントが複数存在する行
(more_than_one_statement)

1 行に複数のステートメント

switch case の break がありません
(missing_switch_break)

break ステートメントがない switch case の末尾にコメントがない

解放したポインターのリセットがありません
(missing_freed_ptr_reset)

後で残りのデータをクリアするリセット ステートメントが行われていないポインター free

未使用のパラメーターです
(unused_parameter)

関数プロトタイプに、関数本体で読み取りも書き込みもされないパラメーターがある

MISRA C:2004 および MISRA AC AGC ルール

このソフトウェアでは、解析の早い段階で以下のルールをチェックします。

言語の拡張

ルール説明
2.1

Assembly language shall be encapsulated and isolated.

2.2

Source code shall only use /* */ style comments.

2.3

The character sequence /* shall not be used within a comment.

ドキュメンテーション

ルール説明
3.4

All uses of the #pragma directive shall be documented and explained.

文字セット

ルール説明
4.1

Only those escape sequences which are defined in the ISO C standard shall be used.

4.2

Trigraphs shall not be used.

識別子

ルール説明
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.

ルール説明
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

typedefs that indicate size and signedness should be used in place of the basic types.

6.4

Bit fields shall only be defined to be of type unsigned int or signed int.

6.5

Bit fields of type signed int shall be at least 2 bits long.

定数

ルール説明
7.1

Octal constants (other than zero) and octal escape sequences shall not be used.

宣言と定義

ルール説明
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 static storage class specifier shall be used in definitions and declarations of objects and functions that have internal linkage

8.12

When an array is declared with external linkage, its size shall be stated explicitly or defined implicitly by initialization.

初期化

ルール説明
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 = construct shall not be used to explicitly initialize members other than the first, unless all items are explicitly initialized.

演算型変換

ルール説明
10.1

The value of an expression of integer type shall not be implicitly converted to a different underlying type if:

  • It is not a conversion to a wider integer type of the same signedness, or

  • The expression is complex, or

  • The expression is not constant and is a function argument, or

  • The expression is not constant and is a return expression

10.2

The value of an expression of floating type shall not be implicitly converted to a different type if

  • It is not a conversion to a wider floating type, or

  • The expression is complex, or

  • The expression is a function argument, or

  • The expression is a return expression

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 ~ and << are applied to an operand of underlying type unsigned char or unsigned short, the result shall be immediately cast to the underlying type of the operand

10.6

The "U" suffix shall be applied to all constants of unsigned types.

ポインター型変換

ルール説明
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 void.

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 const or volatile qualification from the type addressed by a pointer

ルール説明
12.1

Limited dependence should be placed on C's operator precedence rules in expressions.

12.3

The sizeof operator should not be used on expressions that contain side effects.

12.5

The operands of a logical && or || shall be primary-expressions.

12.6

Operands of logical operators (&&, || and !) should be effectively Boolean.Expression that are effectively Boolean should not be used as operands to operators other than (&&, || or !).

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 (++) and decrement (--) operators should not be mixed with other operators in an expression

制御ステートメントの式

ルール説明
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 for statement shall not contain any objects of floating type.

13.5

The three expressions of a for statement shall be concerned only with loop control.

13.6

Numeric variables being used within a for loop for iteration counting should not be modified in the body of the loop.

制御フロー

ルール説明
14.3

All non-null statements shall either

  • have at least one side effect however executed, or

  • cause control flow to change.

14.4

The goto statement shall not be used.

14.5

The continue statement shall not be used.

14.6

For any iteration statement, there shall be at most one break statement used for loop termination.

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 switch, while, do while or for statement shall be a compound statement.

14.9

An if (expression) construct shall be followed by a compound statement.The else keyword shall be followed by either a compound statement, or another if statement.

14.10

All if else if constructs should contain a final else clause.

switch ステートメント

ルール説明
15.0

Unreachable code is detected between switch statement and first case.

15.1

A switch label shall only be used when the most closely-enclosing compound statement is the body of a switch statement.

15.2

An unconditional break statement shall terminate every non-empty switch clause.

15.3

The final clause of a switch statement shall be the default clause.

15.4

A switch expression should not represent a value that is effectively Boolean.

15.5

Every switch statement shall have at least one case clause.

関数

ルール説明
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 void.

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-void return type shall have an explicit return statement with an expression.

16.9

A function identifier shall only be used with either a preceding &, or with a parenthesized parameter list, which may be empty.

ポインターと配列

ルール説明
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.

構造体と共用体

ルール説明
18.1

All structure or union types shall be complete at the end of a translation unit.

18.4

Unions shall not be used.

プリプロセッサ命令

ルール説明
19.1

#include statements in a file shall only be preceded by other preprocessors directives or comments.

19.2

Nonstandard characters should not occur in header file names in #include directives.

19.3

The #include directive shall be followed by either a <filename> or "filename" sequence.

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 #defined and #undefd within a block.

19.6

#undef shall not be used.

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 # or ##.

19.11

All macro identifiers in preprocessor directives shall be defined before use, except in #ifdef and #ifndef preprocessor directives and the defined() operator.

19.12

There shall be at most one occurrence of the # or ## preprocessor operators in a single macro definition.

19.13

The # and ## preprocessor operators should not be used.

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 #else, #elif and #endif preprocessor directives shall reside in the same file as the #if or #ifdef directive to which they are related.

標準ライブラリ

ルール説明
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 errno shall not be used.

20.6

The macro offsetof, in library <stddef.h>, shall not be used.

20.7

The setjmp macro and the longjmp function shall not be used.

20.8

The signal handling facilities of <signal.h> shall not be used.

20.9

The input/output library <stdio.h> shall not be used in production code.

20.10

The library functions atof, atoi and atoll from library <stdlib.h> shall not be used.

20.11

The library functions abort, exit, getenv and system from library <stdlib.h> shall not be used.

20.12

The time handling functions of library <time.h> shall not be used.

MISRA C:2012 ルール

標準 C 環境

ルール説明
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.

未使用コード

ルール説明
2.6

A function should not contain unused label declarations.

2.7

There should be no unused parameters in functions.

コメント

ルール説明
3.1

The character sequences /* and // shall not be used within a comment.

3.2

Line-splicing shall not be used in // comments.

文字セットおよび構文規則

ルール説明
4.1

Octal and hexadecimal escape sequences shall be terminated.

4.2

Trigraphs should not be used.

識別子

ルール説明
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.

ルール説明
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.

リテラルおよび定数

ルール説明
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".

宣言と定義

ルール説明
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.5An external object or function shall be declared once in one and only one file.
8.6An identifier with external linkage shall have exactly one external definition.
8.8

The static storage class specifier shall be used in all declarations of objects and functions that have internal linkage.

8.10

An inline function shall be declared with the static storage class.

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 restrict type qualifier shall not be used.

初期化

ルール説明
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.

実質的な型モデル

ルール説明
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.

ポインター型変換

ルール説明
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 NULL shall be the only permitted form of integer null pointer constant.

ルール説明
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.

二次的影響

ルール説明
13.3

A full expression containing an increment (++) or decrement (--) operator should have no other potential side effects other than that caused by the increment or decrement operator.

13.4

The result of an assignment operator should not be used.

13.6

The operand of the sizeof operator shall not contain any expression which has potential side effects.

制御ステートメントの式

ルール説明
14.4

The controlling expression of an if statement and the controlling expression of an iteration-statement shall have essentially Boolean type.

制御フロー

ルール説明
15.1

The goto statement should not be used.

15.2

The goto statement shall jump to a label declared later in the same function.

15.3

Any label referenced by a goto statement shall be declared in the same block, or in any block enclosing the goto statement.

15.4

There should be no more than one break or goto statement used to terminate any iteration statement.

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 if … else if constructs shall be terminated with an else statement.

switch ステートメント

ルール説明
16.1

All switch statements shall be well-formed.

16.2

A switch label shall only be used when the most closely-enclosing compound statement is the body of a switch statement.

16.3

An unconditional break statement shall terminate every switch-clause.

16.4

Every switch statement shall have a default label.

16.5

A default label shall appear as either the first or the last switch label of a switch statement.

16.6

Every switch statement shall have at least two switch-clauses.

16.7

A switch-expression shall not have essentially Boolean type.

関数

ルール説明
17.1

The features of <starg.h> shall not be used.

17.3

A function shall not be declared implicitly.

17.4

All exit paths from a function with non-void return type shall have an explicit return statement with an expression.

17.6

The declaration of an array parameter shall not contain the static keyword between the [ ].

17.7

The value returned by a function having non-void return type shall be used.

ポインターと配列

ルール説明
18.4

The +, -, += and -= operators should not be applied to an expression of pointer type.

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.

重複ストレージ

ルール説明
19.2

The union keyword should not be used.

プリプロセッサ命令

ルール説明
20.1

#include directives should only be preceded by preprocessor directives or comments.

20.2

The ', ", or \ characters and the /* or // character sequences shall not occur in a header file name.

20.3

The #include directive shall be followed by either a <filename> or \"filename\" sequence.

20.4

A macro shall not be defined with the same name as a keyword.

20.5

#undef should not be used.

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 #if or #elif preprocessing directive shall evaluate to 0 or 1.

20.9

All identifiers used in the controlling expression of #if or #elif preprocessing directives shall be #define'd before evaluation.

20.10

The # and ## preprocessor operators should not be used.

20.11

A macro parameter immediately following a # operator shall not immediately be followed by a ## operator.

20.12

A macro parameter used as an operand to the # or ## operators, which is itself subject to further macro replacement, shall only be used as an operand to these operators.

20.13

A line whose first token is # shall be a valid preprocessing directive.

20.14

All #else, #elif and #endif preprocessor directives shall reside in the same file as the #if, #ifdef or #ifndef directive to which they are related.

標準ライブラリ

ルール説明
21.1

#define and #undef shall not be used on a reserved identifier or reserved macro name.

21.2

A reserved identifier or macro name shall not be declared.

21.3

The memory allocation and deallocation functions of <stdlib.h> shall not be used.

21.4

The standard header file <setjmp.h> shall not be used.

21.5

The standard header file <signal.h> shall not be used.

21.6

The Standard Library input/output functions shall not be used.

21.7

The atof, atoi, atol, and atoll functions of <stdlib.h> shall not be used.

21.8

The library functions abort, exit, getenv and system of <stdlib.h> shall not be used.

21.9

The library functions bsearch and qsort of <stdlib.h> shall not be used.

21.10

The Standard Library time and date functions shall not be used.

21.11

The standard header file <tgmath.h> shall not be used.

21.12

The exception handling features of <fenv.h> should not be used.

MISRA C++ 2008 ルール

言語に依存しない問題

ルール説明
0-1-7The value returned by a function having a non-void return type that is not an overloaded operator shall always be used.
0-1-11There shall be no unused parameters (named or unnamed) in non- virtual functions.
0-1-12There 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-1An object shall not be assigned to an overlapping object.

一般

ルール説明
1-0-1All code shall conform to ISO/IEC 14882:2003 "The C++ Standard Incorporating Technical Corrigendum 1".

構文規則

ルール説明
2-3-1Trigraphs shall not be used.
2-5-1Digraphs should not be used.
2-7-1The character sequence /* shall not be used within a C-style comment.
2-10-1Different identifiers shall be typographically unambiguous.
2-10-2Identifiers declared in an inner scope shall not hide an identifier declared in an outer scope.
2-10-3A typedef name (including qualification, if any) shall be a unique identifier.
2-10-4A class, union or enum name (including qualification, if any) shall be a unique identifier.
2-10-6If an identifier refers to a type, it shall not also refer to an object or a function in the same scope.
2-13-1Only those escape sequences that are defined in ISO/IEC 14882:2003 shall be used.
2-13-2Octal constants (other than zero) and octal escape sequences (other than "\0") shall not be used.
2-13-3A "U" suffix shall be applied to all octal or hexadecimal integer literals of unsigned type.
2-13-4Literal suffixes shall be upper case.
2-13-5Narrow and wide string literals shall not be concatenated.

基本概念

ルール説明
3-1-1It shall be possible to include any header file in multiple translation units without violating the One Definition Rule.
3-1-2Functions shall not be declared at block scope.
3-1-3When an array is declared, its size shall either be stated explicitly or defined implicitly by initialization.
3-3-1Objects or functions with external linkage shall be declared in a header file.
3-3-2If a function has internal linkage then all re-declarations shall include the static storage class specifier.
3-4-1An identifier declared to be an object or type shall be defined in a block that minimizes its visibility.
3-9-1The 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-2Typedefs that indicate size and signedness should be used in place of the basic numerical types.
3-9-3The underlying bit representations of floating-point values shall not be used.

標準変換

ルール説明
4-5-1Expressions 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-2Expressions 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-3Expressions 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.

ルール説明
5-0-1The value of an expression shall be the same under any order of evaluation that the standard permits.
5-0-2Limited dependence should be placed on C++ operator precedence rules in expressions.
5-0-3A cvalue expression shall not be implicitly converted to a different underlying type.
5-0-4An implicit integral conversion shall not change the signedness of the underlying type.
5-0-5There shall be no implicit floating-integral conversions.
5-0-6An implicit integral or floating-point conversion shall not reduce the size of the underlying type.
5-0-7There shall be no explicit floating-integral conversions of a cvalue expression.
5-0-8An explicit integral or floating-point conversion shall not increase the size of the underlying type of a cvalue expression.
5-0-9An explicit integral conversion shall not change the signedness of the underlying type of a cvalue expression.
5-0-10If 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-11The plain char type shall only be used for the storage and use of character values.
5-0-12signed char and unsigned char type shall only be used for the storage and use of numeric values.
5-0-13The condition of an if-statement and the condition of an iteration-statement shall have type bool.
5-0-14The first operand of a conditional-operator shall have type bool.
5-0-15Array 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-19The declaration of objects shall contain no more than two levels of pointer indirection.
5-0-20Non-constant operands to a binary bitwise operator shall have the same underlying type.
5-0-21Bitwise operators shall only be applied to operands of unsigned underlying type.
5-2-1Each operand of a logical && or || shall be a postfix - expression.
5-2-2A pointer to a virtual base class shall only be cast to a pointer to a derived class by means of dynamic_cast.
5-2-3Casts from a base class to a derived class should not be performed on polymorphic types.
5-2-4C-style casts (other than void casts) and functional notation casts (other than explicit constructor calls) shall not be used.
5-2-5A cast shall not remove any const or volatile qualification from the type of a pointer or reference.
5-2-6A cast shall not convert a pointer to a function to any other pointer type, including a pointer to function type.
5-2-7An object with pointer type shall not be converted to an unrelated pointer type, either directly or indirectly.
5-2-8An object with integer type or pointer to void type shall not be converted to an object with pointer type.
5-2-9A cast should not convert a pointer type to an integral type.
5-2-10The increment ( ++ ) and decrement ( -- ) operators should not be mixed with other operators in an expression.
5-2-11The comma operator, && operator and the || operator shall not be overloaded.
5-2-12An identifier with array type passed as a function argument shall not decay to a pointer.
5-3-1Each operand of the ! operator, the logical && or the logical || operators shall have type bool.
5-3-2The unary minus operator shall not be applied to an expression whose underlying type is unsigned.
5-3-3The unary & operator shall not be overloaded.
5-3-4Evaluation of the operand to the sizeof operator shall not contain side effects.
5-8-1The 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-1The right hand operand of a logical && or || operator shall not contain side effects.
5-18-1The comma operator shall not be used.
5-19-1Evaluation of constant unsigned integer expressions should not lead to wrap-around.

ステートメント

ルール説明
6-2-1Assignment operators shall not be used in sub-expressions.
6-2-2Floating-point expressions shall not be directly or indirectly tested for equality or inequality.
6-2-3Before 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-1The statement forming the body of a switch, while, do ... while or for statement shall be a compound statement.
6-4-1An 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-2All if ... else if constructs shall be terminated with an else clause.
6-4-3A switch statement shall be a well-formed switch statement.
6-4-4A switch-label shall only be used when the most closely-enclosing compound statement is the body of a switch statement.
6-4-5An unconditional throw or break statement shall terminate every non - empty switch-clause.
6-4-6The final clause of a switch statement shall be the default-clause.
6-4-7The condition of a switch statement shall not have bool type.
6-4-8Every switch statement shall have at least one case-clause.
6-5-1A for loop shall contain a single loop-counter which shall not have floating type.
6-5-2If loop-counter is not modified by -- or ++, then, within condition, the loop-counter shall only be used as an operand to <=, <, > or >=.
6-5-3The loop-counter shall not be modified within condition or statement.
6-5-4The loop-counter shall be modified by one of: --, ++, -=n, or +=n ; where n remains constant for the duration of the loop.
6-5-5A loop-control-variable other than the loop-counter shall not be modified within condition or expression.
6-5-6A loop-control-variable other than the loop-counter which is modified in statement shall have type bool.
6-6-1Any label referenced by a goto statement shall be declared in the same block, or in a block enclosing the goto statement.
6-6-2The goto statement shall jump to a label declared later in the same function body.
6-6-3The continue statement shall only be used within a well-formed for loop.
6-6-4For any iteration statement there shall be no more than one break or goto statement used for loop termination.
6-6-5A function shall have a single point of exit at the end of the function.

宣言

ルール説明
7-3-1The global namespace shall only contain main, namespace declarations and extern "C" declarations.
7-3-2The identifier main shall not be used for a function other than the global function main.
7-3-3There shall be no unnamed namespaces in header files.
7-3-4using-directives shall not be used.
7-3-5Multiple declarations for an identifier in the same namespace shall not straddle a using-declaration for that identifier.
7-3-6using-directives and using-declarations (excluding class scope or function scope using-declarations) shall not be used in header files.
7-4-2Assembler instructions shall only be introduced using the asm declaration.
7-4-3Assembly language shall be encapsulated and isolated.

宣言子

ルール説明
8-0-1An init-declarator-list or a member-declarator-list shall consist of a single init-declarator or member-declarator respectively.
8-3-1Parameters 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-1Functions shall not be defined using the ellipsis notation.
8-4-2The identifiers used for the parameters in a re-declaration of a function shall be identical to those in the declaration.
8-4-3All exit paths from a function with non- void return type shall have an explicit return statement with an expression.
8-4-4A function identifier shall either be used to call the function or it shall be preceded by &.
8-5-2Braces shall be used to indicate and match the structure in the non- zero initialization of arrays and structures.
8-5-3In an enumerator list, the = construct shall not be used to explicitly initialize members other than the first, unless all items are explicitly initialized.

クラス

ルール説明
9-3-1const member functions shall not return non-const pointers or references to class-data.
9-3-2Member functions shall not return non-const handles to class-data.
9-5-1Unions shall not be used.
9-6-2Bit-fields shall be either bool type or an explicitly unsigned or signed integral type.
9-6-3Bit-fields shall not have enum type.
9-6-4Named bit-fields with signed integer type shall have a length of more than one bit.

派生クラス

ルール説明
10-1-1Classes should not be derived from virtual bases.
10-1-2A base class shall only be declared virtual if it is used in a diamond hierarchy.
10-1-3An accessible base class shall not be both virtual and non-virtual in the same hierarchy.
10-2-1All accessible entity names within a multiple inheritance hierarchy should be unique.
10-3-1There shall be no more than one definition of each virtual function on each path through the inheritance hierarchy.
10-3-2Each overriding virtual function shall be declared with the virtual keyword.
10-3-3A virtual function shall only be overridden by a pure virtual function if it is itself declared as pure virtual.

メンバー アクセス制御

ルール説明
11-0-1Member data in non- POD class types shall be private.

特殊なメンバー関数

ルール説明
12-1-1An object's dynamic type shall not be used from the body of its constructor or destructor.
12-1-2All constructors of a class should explicitly call a constructor for all of its immediate base classes and all virtual base classes.
12-1-3All constructors that are callable with a single argument of fundamental type shall be declared explicit.
12-8-1A copy constructor shall only initialize its base classes and the non- static members of the class of which it is a member.
12-8-2The copy assignment operator shall be declared protected or private in an abstract class.

テンプレート

ルール説明
14-5-2A copy constructor shall be declared when there is a template constructor with a single parameter that is a generic parameter.
14-5-3A copy assignment operator shall be declared when there is a template assignment operator with a parameter that is a generic parameter.
14-6-1In 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-2The function chosen by overload resolution shall resolve to a function declared previously in the translation unit.
14-7-3All partial and explicit specializations for a template shall be declared in the same file as the declaration of their primary template.
14-8-1Overloaded function templates shall not be explicitly specialized.
14-8-2The viable function set for a function call should either contain no function specializations, or only contain function specializations.

Exception Handling

ルール説明
15-0-2An exception object should not have pointer type.
15-0-3Control shall not be transferred into a try or catch block using a goto or a switch statement.
15-1-2NULL shall not be thrown explicitly.
15-1-3An empty throw (throw;) shall only be used in the compound- statement of a catch handler.
15-3-2There should be at least one exception handler to catch all otherwise unhandled exceptions
15-3-3Handlers 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-5A class type exception shall always be caught by reference.
15-3-6Where 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-7Where multiple handlers are provided in a single try-catch statement or function-try-block, any ellipsis (catch-all) handler shall occur last.
15-5-1A class destructor shall not exit with an exception.
15-5-2Where a function's declaration includes an exception-specification, the function shall only be capable of throwing exceptions of the indicated type(s).

プリプロセッサ命令

ルール説明
16-0-1#include directives in a file shall only be preceded by other preprocessor directives or comments.
16-0-2Macros shall only be #define 'd or #undef 'd in the global namespace.
16-0-3#undef shall not be used.
16-0-4Function-like macros shall not be defined.
16-0-5Arguments to a function-like macro shall not contain tokens that look like preprocessing directives.
16-0-6In 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-8If the # token appears as the first token on a line, then it shall be immediately followed by a preprocessing token.
16-1-1The defined preprocessor operator shall only be used in one of the two standard forms.
16-1-2All #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-1The pre-processor shall only be used for file inclusion and include guards.
16-2-2C++ macros shall only be used for: include guards, type qualifiers, or storage class specifiers.
16-2-3Include guards shall be provided.
16-2-4The ', ", /* or // characters shall not occur in a header file name.
16-2-5The \ character should not occur in a header file name.
16-2-6The #include directive shall be followed by either a <filename> or "filename" sequence
16-3-1There shall be at most one occurrence of the # or ## operators in a single macro definition.
16-3-2The # and ## operators should not be used.
16-6-1All uses of the #pragma directive shall be documented.
17-0-1Reserved identifiers, macros and functions in the standard library shall not be defined, redefined or undefined.
17-0-2The names of standard library macros and objects shall not be reused.
17-0-5The setjmp macro and the longjmp function shall not be used.

言語サポート ライブラリ

ルール説明
18-0-1The C library shall not be used.
18-0-2The library functions atof, atoi and atol from library <cstdlib> shall not be used.
18-0-3The library functions abort, exit, getenv and system from library <cstdlib> shall not be used.
18-0-4The time handling functions of library <ctime> shall not be used.
18-0-5The unbounded functions of library <cstring> shall not be used.
18-2-1The macro offsetof shall not be used.
18-4-1Dynamic heap memory allocation shall not be used.
18-7-1The signal handling facilities of <csignal> shall not be used.

診断ライブラリ

ルール説明
19-3-1The error indicator errno shall not be used.

入出力ライブラリ

ルール説明
27-0-1The stream input/output library <cstdio> shall not be used.