[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
================
@@ -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;
+ }
----------------
Fznamznon wrote:
```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