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

via cfe-commits cfe-commits at lists.llvm.org
Tue Nov 26 01:26:18 PST 2024


================
@@ -10509,14 +10516,18 @@ static bool AnalyzeBitFieldAssignment(Sema &S, FieldDecl *Bitfield, Expr *Init,
                  ED->getNumPositiveBits() == FieldWidth) {
         DiagID = diag::warn_signed_bitfield_enum_conversion;
       }
-
+      unsigned PreferredTypeDiagIndex = PTAttr != nullptr;
       if (DiagID) {
-        S.Diag(InitLoc, DiagID) << Bitfield << ED;
+        S.Diag(InitLoc, DiagID) << Bitfield << PreferredTypeDiagIndex << ED;
         TypeSourceInfo *TSI = Bitfield->getTypeSourceInfo();
         SourceRange TypeRange =
             TSI ? TSI->getTypeLoc().getSourceRange() : SourceRange();
         S.Diag(Bitfield->getTypeSpecStartLoc(), diag::note_change_bitfield_sign)
             << SignedEnum << TypeRange;
+        if (PTAttr) {
+          S.Diag(PTAttr->getLocation(), diag::note_bitfield_preferred_type)
+              << ED;
+        }
----------------
cor3ntin wrote:

I think a lot of people don't like them, but it is part of our coding standards, so you must
https://llvm.org/docs/CodingStandards.html#don-t-use-braces-on-simple-single-statement-bodies-of-if-else-loop-statements

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


More information about the cfe-commits mailing list