1 .. title:: clang-tidy - cppcoreguidelines-avoid-goto
3 cppcoreguidelines-avoid-goto
4 ============================
6 The usage of ``goto`` for control flow is error prone and should be replaced
7 with looping constructs. Only forward jumps in nested loops are accepted.
9 This check implements `ES.76
10 <https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#es76-avoid-goto>`_
11 from the C++ Core Guidelines and
12 `6.3.1 <https://www.perforce.com/resources/qac/high-integrity-cpp-coding-standard/statements>`_
13 from High Integrity C++ Coding Standard.
15 For more information on why to avoid programming
16 with ``goto`` you can read the famous paper `A Case against the GO TO Statement. <https://www.cs.utexas.edu/users/EWD/ewd02xx/EWD215.PDF>`_.
18 The check diagnoses ``goto`` for backward jumps in every language mode. These
19 should be replaced with `C/C++` looping constructs.
23 // Bad, handwritten for loop.
25 // Jump label for the loop
35 for(int i = 0; i < 100; ++i)
38 Modern C++ needs ``goto`` only to jump out of nested loops.
42 for(int i = 0; i < 100; ++i) {
43 for(int j = 0; j < 100; ++j) {
52 All other uses of ``goto`` are diagnosed in `C++`.