From the concept of the Cvalue, I realized that
"An expression that should not undergo further conversions, either implicitly or explicitly, is called a cvalue expression."
But with the example presented by this rule.
s32 = static_cast < int32_t > ( s8 ) + s8; // Example 2 - Compliant
s32 = s32 + s8; // Example 3 - Compliant
Obviously, the right addition expressions occur implicitly and explicitly conversions here. And this rule mark them as compliant. I think it is conflicted with the notion cvalue.
In the end of page 57, MISRA Cpp 2008:
Reading the long list after that paragraph, nothing can be applied to
s8
.Then,
s8
is not cvalues, it has the underlying type of the operation, in your example, its underlying type isint32_t
. The promotion toint32_t
doesn't violate the rule.The whole point of 5-0-3 is it wants to ensure all operations are performed in the same underlying type.
In those above examples, the
+
is performed with the underlying type ofint32_t
(by now, most ofint
isint32_t
orint16_t
), return the underlying type ofint32_t
, then assign to anint32_t
variable, thus compliant with MISRA Cpp.In this example:
It doesn't compliance because the additive operator is performed with the type of
int
, the result will be converted toint32_t
which is not necessary the same withint
, thus not-compliance.