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

via cfe-commits cfe-commits at lists.llvm.org
Wed Jun 17 08:54:25 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.
----------------
earnol wrote:

Done.

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


More information about the cfe-commits mailing list