JavaScript is not currently enabled, but is required for full CodeSonar manual search and browse functionality.

If you are viewing this file in your hub's Web GUI, enable JavaScript in your browser: you will also need it for GUI functionality.

If you opened this file directly from disk, your browser may be directly suppressing JavaScript functionality: certain browsers perform this suppression on local files (but not files delivered by web servers) for security reasons.

CodeSonar® 9.2p0 CONFIDENTIAL CodeSecure Inc
C and C++


LANG.STRUCT.PARENS : 不十分な括弧

要旨

式の括弧が不十分なので、Misra2012:12.1Misra2004:12.1、及び MisraC++2008:5-0-2 の明示的な演算子の 優先順位の要求に合っていません。特に、:

このワーニングクラスの適用上、演算子の優先順位は、Misra2012:12.1に従います:

説明 演算子 または オペランド 優先順位
最優先 識別子、定数、文字列リテラル、() 16 (高)
後置演算子 [] () (関数呼び出し) . -> ++ (後置インクリメント) -- (後置デクリメント) () {} (C99: コンパウンドリテラル) 15
単項演算子 ++ (前置インクリメント) -- (前置デクリメント) & * + - ~ ! sizeof defined (プリプロセッサ) 14
キャスト演算子 () 13
乗算、除算、剰余 * / % 12
加算、減算 + - 11
シフト演算子 << >> 10
関係演算子 < > <= >= 9
等価演算子 == != 8
ビットAND & 7
ビットXOR ^ 6
ビットOR | 5
論理AND && 4
論理OR || 3
条件演算子 ?: 2
代入演算子 = *= /= %= += -= <<= >>= &= ^= |= 1
コンマ演算子 , 0 (低)

プロパティ

クラス名 Missing Parentheses
日本語クラス名 不十分な括弧
クラス分類 スタイル (style)
ニーモニック LANG.STRUCT.PARENS
カテゴリー
MisraC2025 MisraC2025:12.1 The precedence of operators within expressions should be made explicit
MisraC2023 MisraC2023:12.1 The precedence of operators within expressions should be made explicit
Misra2012 Misra2012:12.1 The precedence of operators within expressions should be made explicit
Misra2004 Misra2004:12.1 Limited dependence should be placed on C's operator precedence rules in expressions
AUTOSARC++14 AUTOSARC++14:M5-0-2 Limited dependence should be placed on C++ operator precedence rules in expressions.
  AUTOSARC++14:A5-2-6 The operands of a logical && or || shall be parenthesized if the operands contain binary operators.
MisraC++2008 MisraC++2008:5-0-2 Limited dependence should be placed on C++ operator precedence rules in expressions.
MisraC++2023 MisraC++2023:8.0.1 Parentheses should be used to make the meaning of an expression appropriately explicit
CWE CWE:710 Improper Adherence to Coding Standards
CERT-C CERT-C:EXP00-C Use parentheses for precedence of operation
JSF++ JSF++:158 The operands of a logical && or || shall be parenthesized if the operands contain binary operators.
  JSF++:213 No dependence shall be placed on C++'s operator precedence rules, below arithmetic operators, in expressions.
JPL JPL:18 Make the order of evaluation in compound expressions explicit.
対応言語 C および C++ で利用可能です。
有効/無効設定 このワーニングクラスのチェックはデフォルトで無効になっており、プロジェクトには非正規の C向けAST が必要になります。有効にするにはプロジェクト設定ファイル (configuration file) に以下の WARNING_FILTER ルールと RETAIN_UNNORMALIZED_C_AST 設定を追加してください。
RETAIN_UNNORMALIZED_C_AST = Yes
WARNING_FILTER += allow class="Missing Parentheses"
注:非正規化された AST を継続して使用した場合、使用ディスク容量が増加し解析時間が長くなる可能性があります。

#include <stddef.h>

int lang_struct_parens(void){
    int x=1;
    size_t s,t;

    s = sizeof x;   /* 'Missing Parentheses' warning issued here */
    t = sizeof(x);                  /* sizeof argument parenthesized */

    x = x << t + s; /* 'Missing Parentheses' warning issued here */
    x += x << (t + s);              /* sub-expression parenthesized */

    return x;
}

関連のある設定ファイルパラメータ

設定ファイルの以下のパラメータがこのワーニングクラスのチェックに影響します。

 

To report problems with this documentation, please visit https://support.codesecure.com/.