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 : Missing Parentheses

Summary

An expression is not sufficiently parenthesized, so does not meet the explicit operator precendece requirements of Misra2012:12.1, Misra2004:12.1, and MisraC++2008:5-0-2. In particular, either:

For the purposes of this warning class, operator precedences are as specified in Misra2012:12.1:

Description Operator or Operand Precedence
Primary identifier, constant, string literal, ( expression ) 16 (high)
Postfix [] () (function call) . -> ++ (post-increment) -- (post-decrement) () {} (C99: compound literal) 15
Unary ++ (pre-increment) -- (pre-decrement) & * + - ~ ! sizeof defined (preprocessor) 14
Cast () 13
Multiplicative * / % 12
Additive + - 11
Bitwise shift << >> 10
Relational < > <= >= 9
Equality == != 8
Bitwise AND & 7
Bitwise XOR ^ 6
Bitwise OR | 5
Logical AND && 4
Logical OR || 3
Conditional ?: 2
Assignment = *= /= %= += -= <<= >>= &= ^= |= 1
Comma , 0 (low)

Properties

Class Name Missing Parentheses
Significance style
Mnemonic LANG.STRUCT.PARENS
Categories
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.
Availability Available for C and C++.
Enabling Checks for this warning class are disabled by default, and require the unnormalized C ASTs for the project. To enable them, add the following WARNING_FILTER rule and RETAIN_UNNORMALIZED_C_AST specification to the project configuration file.
RETAIN_UNNORMALIZED_C_AST = Yes
WARNING_FILTER += allow class="Missing Parentheses"
Note that retaining the unnormalized ASTs will increase the disk space used to store the project representation, and may make the analysis take longer.

Example

#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;
}

Relevant Configuration File Parameters

The following configuration file parameters affect checks for this warning class.

 

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