https://bugs.llvm.org/show_bug.cgi?id=49381

            Bug ID: 49381
           Summary: [analyzer] EnumCastOutOfRange false-positive for
                    bitmasks
           Product: clang
           Version: 11.0
          Hardware: PC
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Static Analyzer
          Assignee: dcough...@apple.com
          Reporter: balazs.ben...@sigmatechnology.se
                CC: dcough...@apple.com, llvm-bugs@lists.llvm.org

The EnumCastOutOfRange checker emits a warning for this code:

// -std=c++17 -Xclang -analyze -Xclang
-analyzer-checker=core,alpha.cplusplus.EnumCastOutOfRange -Xclang
-analyzer-output=text
https://godbolt.org/z/xosTxq

  enum TestEnum {
    A = 0,
    B = 1,
    C = 2,
    D = 4,
  };

  void bitmasks() {
    static_assert((B | C | D) == 7);
    TestEnum t = static_cast<TestEnum>(7); // should not warn
    (void)t;
  }

The checker should recognize the bitmask and check the bounds accordingly.
/CC Endre Fülöp, the co-author of the checker

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to