[clang-tools-extra] [clang-tidy] Fix bugprone-misplaced-widening-cast false positive on bitfield assignments (PR #197554)

Baranov Victor via cfe-commits cfe-commits at lists.llvm.org
Thu Jun 11 23:57:20 PDT 2026


================
@@ -195,14 +204,28 @@ void MisplacedWideningCastCheck::check(const MatchFinder::MatchResult &Result) {
   const QualType CastType = Cast->getType();
   const QualType CalcType = Calc->getType();
 
+  // If assigning to a bit field, use the bit field width as the effective
+  // target width. The declared type may be wider than the actual bit field
+  // storage. "BitField" is bound in the matcher via optionally(); if present,
+  // the LHS is a bit field member.
----------------
vbvictor wrote:

```suggestion
  // If assigning to a bit field, use the bit field width as the effective
  // target width. The declared type may be wider than the actual bit field
  // storage.
```

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


More information about the cfe-commits mailing list