Skip to content

[clang-tidy] False positive bugprone-non-zero-enum-to-bool-conversion with custom operator #65315

Closed
@chrchr-github

Description

@chrchr-github
enum E {
    E0 = 0x1,
    E1 = 0x2,
    E2 = 0x4
};

E operator&(E a, E b) { return static_cast<E>(a & b); }

void f(E e) {
    if (e & E1) {}
}
<[source>:10:9: warning: conversion of 'E' into 'bool' will always return 'true', enum doesn't have a zero-value enumerator [bugprone-non-zero-enum-to-bool-conversion]
   10 |     if (e & E1) {}
      |         ^
[<source>:1:6: note: enum is defined here]
    1 | enum E {
      |      ^

https://godbolt.org/z/nv3PxYdM7

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions