1 .. title:: clang-tidy - readability-else-after-return
3 readability-else-after-return
4 =============================
6 `LLVM Coding Standards <https://llvm.org/docs/CodingStandards.html>`_ advises to
7 reduce indentation where possible and where it makes understanding code easier.
8 Early exit is one of the suggested enforcements of that. Please do not use
9 ``else`` or ``else if`` after something that interrupts control flow - like
10 ``return``, ``break``, ``continue``, ``throw``.
12 The following piece of code illustrates how the check works. This piece of code:
18 for (int i = 0; i < 42; i++) {
39 Would be transformed into:
45 for (int i = 0; i < 42; i++) {
65 .. option:: WarnOnUnfixable
67 When `true`, emit a warning for cases where the check can't output a
68 Fix-It. These can occur with declarations inside the ``else`` branch that
69 would have an extended lifetime if the ``else`` branch was removed.
70 Default value is `true`.
72 .. option:: WarnOnConditionVariables
74 When `true`, the check will attempt to refactor a variable defined inside
75 the condition of the ``if`` statement that is used in the ``else`` branch
76 defining them just before the ``if`` statement. This can only be done if
77 the ``if`` statement is the last statement in its parent's scope.
78 Default value is `true`.
84 There is an alias of this check called llvm-else-after-return.
85 In that version the options :option:`WarnOnUnfixable` and
86 :option:`WarnOnConditionVariables` are both set to `false` by default.
88 This check helps to enforce this `LLVM Coding Standards recommendation
89 <https://llvm.org/docs/CodingStandards.html#don-t-use-else-after-a-return>`_.