Rule 5-0-3 false positive warning

Moderators: david ward, misra cpp

Post Reply
Posts: 3
Joined: Sat Mar 18, 2017 4:32 pm
Company: Minho University

Rule 5-0-3 false positive warning

Post by mikearmagedon » Tue Apr 04, 2017 3:59 pm

My static analyzer is throwing the following warning:
MCPP Rule 5-0-3: This complex expression is implicitly converted to a different essential type
for the following code:

Code: Select all

void func(const uint32_t arg)
    //32U has underlying type uint8_t
    const uint32_t u32a = arg % 32U; //warning issued in this line
    const uint32_t u32b = static_cast<uint32_t>(arg % 32U); //compliant
I think this warning may be a false positive because, despite the 32U having a uint8_t underlying type, the expression should take the underlying type of the larger type, in this case the uint32_t, thus making the need for the static_cast unnecessary.

Do you agree this is a false positive? Or am I looking at it all wrong?

misra cpp
Posts: 163
Joined: Mon Jun 02, 2008 1:55 pm
Company: MISRA

Re: Rule 5-0-3 false positive warning

Post by misra cpp » Mon Jul 10, 2017 11:11 am

Your example code is compliant - contact your static analysis vendor
Posted by and on behalf of
the MISRA C++ Working Group

Post Reply

Return to “6.5 Expressions (C++)”