高速解析モードで検出される 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) |
|
| 前のハンドラーによって隠された例外ハンドラーです ( excp_handler_hidden) | 同じ例外に対して |
| 書式文字列指定子と引数の不一致 ( 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) |
|
データ フロー
| 名前 | 説明 |
|---|---|
| 条件が常に false であるために非アクティブにされたコード ( deactivated_code) |
|
| 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) | オブジェクトを指す |
| バッファー サイズがハードコードされています ( 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 |
| 2.3 | The character sequence |
ドキュメンテーション
| ルール | 説明 |
|---|---|
| 3.4 | All uses of the |
文字セット
| ルール | 説明 |
|---|---|
| 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 |
|
| 6.4 | Bit fields shall only be defined to be of type |
| 6.5 | Bit fields of type |
定数
| ルール | 説明 |
|---|---|
| 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 |
| 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 |
演算型変換
| ルール | 説明 |
|---|---|
| 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 |
ポインター型変換
| ルール | 説明 |
|---|---|
| 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 |
式
| ルール | 説明 |
|---|---|
| 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 ( |
制御ステートメントの式
| ルール | 説明 |
|---|---|
| 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 |
制御フロー
| ルール | 説明 |
|---|---|
| 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 ステートメント
| ルール | 説明 |
|---|---|
| 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 |
関数
| ルール | 説明 |
|---|---|
| 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 |
ポインターと配列
| ルール | 説明 |
|---|---|
| 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 |
|
| 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 |
標準ライブラリ
| ルール | 説明 |
|---|---|
| 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 ルール
標準 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 |
| 3.2 | Line-splicing shall not be used in |
文字セットおよび構文規則
| ルール | 説明 |
|---|---|
| 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.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 |
初期化
| ルール | 説明 |
|---|---|
| 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 |
式
| ルール | 説明 |
|---|---|
| 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 ( |
| 13.4 | The result of an assignment operator should not be used. |
| 13.6 | The operand of the |
制御ステートメントの式
| ルール | 説明 |
|---|---|
| 14.4 | The controlling expression of an |
制御フロー
| ルール | 説明 |
|---|---|
| 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 ステートメント
| ルール | 説明 |
|---|---|
| 16.1 | All |
| 16.2 | A |
| 16.3 | An unconditional |
| 16.4 | Every |
| 16.5 | A |
| 16.6 | Every |
| 16.7 | A |
関数
| ルール | 説明 |
|---|---|
| 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- |
ポインターと配列
| ルール | 説明 |
|---|---|
| 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. |
重複ストレージ
| ルール | 説明 |
|---|---|
| 19.2 | The |
プリプロセッサ命令
| ルール | 説明 |
|---|---|
| 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 |
標準ライブラリ
| ルール | 説明 |
|---|---|
| 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 ルール
言語に依存しない問題
| ルール | 説明 |
|---|---|
| 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. |
一般
| ルール | 説明 |
|---|---|
| 1-0-1 | All code shall conform to ISO/IEC 14882:2003 "The C++ Standard Incorporating Technical Corrigendum 1". |
構文規則
| ルール | 説明 |
|---|---|
| 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. |
基本概念
| ルール | 説明 |
|---|---|
| 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. |
標準変換
| ルール | 説明 |
|---|---|
| 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. |
式
| ルール | 説明 |
|---|---|
| 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. |
ステートメント
| ルール | 説明 |
|---|---|
| 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. |
宣言
| ルール | 説明 |
|---|---|
| 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. |
宣言子
| ルール | 説明 |
|---|---|
| 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. |
クラス
| ルール | 説明 |
|---|---|
| 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. |
派生クラス
| ルール | 説明 |
|---|---|
| 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. |
メンバー アクセス制御
| ルール | 説明 |
|---|---|
| 11-0-1 | Member data in non- POD class types shall be private. |
特殊なメンバー関数
| ルール | 説明 |
|---|---|
| 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. |
テンプレート
| ルール | 説明 |
|---|---|
| 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
| ルール | 説明 |
|---|---|
| 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). |
プリプロセッサ命令
| ルール | 説明 |
|---|---|
| 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. |
言語サポート ライブラリ
| ルール | 説明 |
|---|---|
| 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. |
診断ライブラリ
| ルール | 説明 |
|---|---|
| 19-3-1 | The error indicator errno shall not be used. |
入出力ライブラリ
| ルール | 説明 |
|---|---|
| 27-0-1 | The stream input/output library <cstdio> shall not be used. |