Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
A5-16-1 Clarification
#1
Hi,

we stumbled upon a few situations in which rule A5-16-1 is not particularly clear.

(1) The example contradicts the rule text as the usage of ?: as sub-expression in assignments (which is an expression again) is named compliant. This was already mentioned in https://forum.misra.org.uk/thread-1612.html .
(2) Code like "A a = 1 ? x : y;" where A is a class and x and y are objects of A. Assuming assignments are okay for this rule, the ?: is not the operand of the assignment but of an implicit call to the copy constructor of A. Should such implicit calls be ignored (aka treated as transparent) or is the rule okay with usage of ?: as function call argument in general?

It would be great if the exceptions for this rule could be clarified. Thanks a lot!
Reply
#2
I just realized that the provided examples are not actual assignment expressions but declarations with initialization. With this in mind, the ?: are not sub-expressions but top-level expressions and thus do not violate the rule.
Reply
#3
We've just agreed the following reply:  

Regarding your points (1) and (2), the examples do not contradict the rule text as none of them involve assignment expressions.  The example you have provided in (2) and line 9 of the document are initializers and the initializing expressions are not sub-expressions:

 int i;
    int32_t j = (1 ? 2 : 3);  // Compliant
    i = (1 ? 2 : 3);           // Non-compliant


However, we do agree that the rule is overly restrictive and it is possible that the original intent was to be more inline with the original source rule.

This will be reviewed in a future version.
Posted by and on behalf of
the MISRA C++ Working Group
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)