Issue 76208
Summary [clang-tidy] suppress `[clang-analyzer-optin.core.EnumCastOutOfRange]` for bit-wise operator of scoped enum
Labels clang-tidy
Assignees
Reporter zufuliu
    related to issue  #48725.

```c++
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.
```
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to