CPP-5803 S7035 Add exception for casts to bool
This commit is contained in:
parent
d071c05987
commit
d162735cf0
@ -65,7 +65,20 @@ This rule raises an issue when an enum is converted to an integral value without
|
|||||||
|
|
||||||
=== Exceptions
|
=== Exceptions
|
||||||
|
|
||||||
Unscoped enums with no underlying type specified have an implementation-defined implicit underlying type. Calling `std::to_underlying` on them wouldn't make the code more portable so this rule doesn't raise on them.
|
The result of casting any integer type to `bool` does not depend on the specific integer type.
|
||||||
|
For the same reason, casting an enumeration to `bool` does not depend on the underlying type of enumerator, so this rule does not raise.
|
||||||
|
|
||||||
|
[source,cpp]
|
||||||
|
----
|
||||||
|
enum class Enum {A, B, C};
|
||||||
|
void foo(Enum e) {
|
||||||
|
auto i = static_cast<bool>(e); // Compliant by exception, the intent is obvious
|
||||||
|
...
|
||||||
|
}
|
||||||
|
----
|
||||||
|
|
||||||
|
Unscoped enums with no underlying type specified have an implementation-defined implicit underlying type.
|
||||||
|
Calling `std::to_underlying` on them would not make the code more portable so this rule does not raise on them.
|
||||||
|
|
||||||
[source,cpp]
|
[source,cpp]
|
||||||
----
|
----
|
||||||
|
Loading…
x
Reference in New Issue
Block a user