Posts: 259
Threads: 1
Joined: Jun 2008
Reputation:
6
We don't wish to encourage the use of signed values in bitwise expressions, even if constant - so are not planning an exception.
We are assuming that FLAG_A etc. are C-style enums, so the code also violates 10.2.3 "The numeric value of an unscoped enumeration with no fixed underlying type shall not be used"
You need to deviate each such expression, or better define your own bitwise operator for this enum type (which will still need a deviation for 10.2.3 - but only in one place)
Posted by and on behalf of
the MISRA C++ Working Group
Posts: 53
Threads: 26
Joined: Mar 2021
Reputation:
1
20-12-2024, 02:36 PM
(This post was last modified: 20-12-2024, 02:48 PM by cgpzs.)
Sorry, I should have been more explicit. FLAG_A, etc are C-style positive signed integer #defines, like:
#define FLAG_A 0x0001
#define FLAG_B 0x0002
#define FLAG_C 0x0004
Thus we cannot unfortunately define a bitwise operator for them.
Posts: 53
Threads: 26
Joined: Mar 2021
Reputation:
1
@misracpp does my above clarification change your view on the issue?
I also note that rule 7.0.5 does have an exception for constant non-negative signed values that are converted to unsigned:
> A compile-time constant with signed integral type that has a non-negative value may be converted to an unsigned type through the usual arithmetic conversions.
Would it be reasonable to apply the same exception for 7.0.4?
Posts: 259
Threads: 1
Joined: Jun 2008
Reputation:
6
Its an interesting use case, but we suggest you should apply a wrapper around the third-party code, to convert the flags to unsigned constants or enums with unsigned underlying type
Posted by and on behalf of
the MISRA C++ Working Group