[PATCH] D16310: new clang-tidy checker misc-long-cast

Daniel Marjamäki via cfe-commits cfe-commits at lists.llvm.org
Fri Jan 22 03:47:02 PST 2016


danielmarjamaki added a comment.

In http://reviews.llvm.org/D16310#331538, @LegalizeAdulthood wrote:

> If you state what the check does, then
>
> In http://reviews.llvm.org/D16310#331054, @danielmarjamaki wrote:
>
> > In http://reviews.llvm.org/D16310#330367, @LegalizeAdulthood wrote:
> >
> > > Why not supply a fixit that removes the cast?
> >
> >
> > I am skeptic. There are different valid fixes.
> >
> > Example code:
> >
> >   l = (long)(a*1000);
> >   
> >
> > Fix1:
> >
> >   l = ((long)a * 1000);
> >   
> >
> > Fix2:
> >
> >   l = (a * (long)1000);
> >   
> >
> > Fix3:
> >
> >   l = (a * 1000L);
>
>
> The way I see it, the check is complaining about the pointless cast and pointing the finger at the beginning of the cast.  To me, my expectation is that the suggested fix is none of the options you gave but instead:
>
>   l = (a*1000);
>


I expect that this warning will in most cases be fixed by moving the cast.

I believe there is often a bug in such code.

If you want that we hide these bugs by removing the casts I can do it.. but I personally think that is wrong.

And yes clang-tidy does not have static analysis. that would not help much to determine proper fix anyway - if we can see there is overflow then should it be fixed with fix 1,2,3 or is the overflow intentional.


Repository:
  rL LLVM

http://reviews.llvm.org/D16310





More information about the cfe-commits mailing list