MISRA Discussion Forums
A5-16-1 Clarification - Printable Version

+- MISRA Discussion Forums (https://forum.misra.org.uk)
+-- Forum: MISRA C++ (https://forum.misra.org.uk/forumdisplay.php?fid=18)
+--- Forum: AUTOSAR C++:2014 rules (https://forum.misra.org.uk/forumdisplay.php?fid=185)
+--- Thread: A5-16-1 Clarification (/showthread.php?tid=1620)



A5-16-1 Clarification - hahn - 06-05-2022

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!


RE: A5-16-1 Clarification - hahn - 10-05-2022

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.


RE: A5-16-1 Clarification - misra cpp - 13-05-2022

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.