[clang] [Clang] Consider preferred_type in bitfield warnings (#116760) (PR #116785)

Oliver Hunt via cfe-commits cfe-commits at lists.llvm.org
Sat Jan 4 11:28:02 PST 2025


ojhunt wrote:

> (while too lazy to godbolt right now)

Given I basically wrote the entire example, I thought I would just do the godbolting, and lo

```cpp
enum class Enum {
  A, B, C, D
};

struct S {
  Enum e: 1; // I'm a rockstar developer and "know" that I'll only ever assign A or B here
};
void f(bool x) {
  S s;
  if (x)
    s.e = Enum::A;
  else
    s.e = Enum::B;
}
```

Compiles cleanly with `-Wbitfield-width -Wbitfield-enum-conversion`: https://godbolt.org/z/a1fErxv74

https://github.com/llvm/llvm-project/pull/116785


More information about the cfe-commits mailing list