1// RUN: %check_clang_tidy %s readability-else-after-return %t -- \
2// RUN: -config='{CheckOptions: { \
3// RUN: readability-else-after-return.WarnOnConditionVariables: false, \
4// RUN: }}'
5
6bool foo(int Y) {
7 // Excess scopes are here so that the check would have to opportunity to
8 // refactor the variable out of the condition.
9
10 // Expect warnings here as we don't need to move declaration of 'X' out of the
11 // if condition as its not used in the else.
12 {
13 if (int X = Y)
14 return X < 0;
15 else
16 // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: do not use 'else' after 'return'
17 return false;
18 }
19 {
20 if (int X = Y; X)
21 return X < 0;
22 else
23 // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: do not use 'else' after 'return'
24 return false;
25 }
26
27 // Expect no warnings for these cases, as even though its safe to move
28 // declaration of 'X' out of the if condition, that has been disabled
29 // by the options.
30 {
31 if (int X = Y)
32 return false;
33 else
34 return X < 0;
35 }
36 {
37 if (int X = Y; X)
38 return false;
39 else
40 return X < 0;
41 }
42}
43

source code of clang-tools-extra/test/clang-tidy/checkers/readability/else-after-return-no-cond-var-refactor.cpp