Closed
Description
related to issue #48725.
enum class Flag {
None = 0,
A = 1,
B = 2,
};
constexpr Flag operator|(Flag a, Flag b) noexcept {
return static_cast<Flag>(static_cast<int>(a) | static_cast<int>(b));
}
Flag getFlag() {
return Flag::A | Flag::B;
}
https://godbolt.org/z/bhqcoPEPj
<source>:8:12: warning: The value '3' provided to the cast expression is not in the valid range of values for 'Flag' [clang-analyzer-optin.core.EnumCastOutOfRange]
8 | return static_cast<Flag>(static_cast<int>(a) | static_cast<int>(b));
| ^
<source>:1:12: note: enum declared here
1 | enum class Flag {
| ~~~~~~~~~~~^~~~~~
2 | None = 0,
| ~~~~~~~~~
3 | A = 1,
| ~~~~~~
4 | B = 2,
| ~~~~~~
5 | };
| ~
<source>:12:12: note: Calling 'operator|'
12 | return Flag::A | Flag::B;
| ^~~~~~~~~~~~~~~~~
<source>:8:12: note: The value '3' provided to the cast expression is not in the valid range of values for 'Flag'
8 | return static_cast<Flag>(static_cast<int>(a) | static_cast<int>(b));
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 warning generated.