[PATCH] D41815: [clang-tidy] implement check for goto

Jonas Toth via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jan 11 13:50:51 PST 2018


JonasToth added a comment.

In https://reviews.llvm.org/D41815#973265, @lebedev.ri wrote:

> In https://reviews.llvm.org/D41815#973260, @JonasToth wrote:
>
> > - check that jumps will only be forward. AFAIK that is required in all sensefull usecases of goto, is it?
>
>
> You could implement loops/recursion with goto, something like:
>
>   const int end = 10;
>   int i = 0;
>   assert(i < end);
>  
>   begin:
>   <do stuff>
>   i++
>   if(i < end)
>     goto begin;
>  
>   // end
>
>
> But it really should be done with normal `for()`, or `while()`, so i think it would make sense to diagnose those.


That check is specifically targeting these code constellations to be bad practice. As you said, using the looping constructs is the way to go :)


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D41815





More information about the cfe-commits mailing list