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

Mariya Podchishchaeva via cfe-commits cfe-commits at lists.llvm.org
Wed Nov 20 02:30:11 PST 2024


================
@@ -10530,9 +10541,13 @@ static bool AnalyzeBitFieldAssignment(Sema &S, FieldDecl *Bitfield, Expr *Init,
       if (BitsNeeded > FieldWidth) {
         Expr *WidthExpr = Bitfield->getBitWidth();
         S.Diag(InitLoc, diag::warn_bitfield_too_small_for_enum)
-            << Bitfield << ED;
+            << Bitfield << PreferredTypeDiagIndex << ED;
         S.Diag(WidthExpr->getExprLoc(), diag::note_widen_bitfield)
             << BitsNeeded << ED << WidthExpr->getSourceRange();
+        if (PTAttr) {
+          S.Diag(PTAttr->getLocation(), diag::note_bitfield_preferred_type)
+              << ED;
+        }
----------------
Fznamznon wrote:

Curly braces can be removed.
```suggestion
        if (PTAttr)
          S.Diag(PTAttr->getLocation(), diag::note_bitfield_preferred_type)
              << ED;
```

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


More information about the cfe-commits mailing list