[PATCH] D30923: Warn on enum assignment to bitfields that can't fit all values

Hal Finkel via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Mar 14 11:00:33 PDT 2017


hfinkel added a comment.

In https://reviews.llvm.org/D30923#700780, @rnk wrote:

> In https://reviews.llvm.org/D30923#700708, @hfinkel wrote:
>
> > In https://reviews.llvm.org/D30923#700696, @rnk wrote:
> >
> > > Do you think it's worth indicating that the error can be suppressed with an explicit cast, or is that wasted space?
> >
> >
> > What might this look like? Also, I don't see a regression test for this.
>
>
> The warning only looks through implicit casts and paren exprs, so it could look like this:  `f.two_bits = (unsigned)three_bits;` I added a test for it.


Great, thanks!



================
Comment at: lib/Sema/SemaChecking.cpp:8765
+        TypeSourceInfo *TSI = Bitfield->getTypeSourceInfo();
+        SourceRange TypeRange = TSI ? TSI->getTypeLoc().getSourceRange() : SourceRange();
+        S.Diag(Bitfield->getTypeSpecStartLoc(), diag::note_change_bitfield_sign)
----------------
Line is too long.


https://reviews.llvm.org/D30923





More information about the cfe-commits mailing list