"... Yes, compliant with 7.0.5. But this code then violates 7.0.6, since there is an implicit narrowing conversion from uint32_t to uint8_t in the assignment, right?"
No. The introduction to the section that includes 7.0.5. and 7.0.6 says "Note: compound assignments are not assignments", so 7.0.6 does not apply to a compound assignment.
We recognise that it may be surprising that a += b; is treated differently to a = a + b; but we failed to find an acceptable form of words to say 'treat a = a + ....' as 'a += ....'
The example: u8a += static_cast< uint32_t >( u8b ); is correct and compliant
No. The introduction to the section that includes 7.0.5. and 7.0.6 says "Note: compound assignments are not assignments", so 7.0.6 does not apply to a compound assignment.
We recognise that it may be surprising that a += b; is treated differently to a = a + b; but we failed to find an acceptable form of words to say 'treat a = a + ....' as 'a += ....'
The example: u8a += static_cast< uint32_t >( u8b ); is correct and compliant
Posted by and on behalf of
the MISRA C++ Working Group
the MISRA C++ Working Group