| 1 | // RUN: %check_clang_tidy %s readability-braces-around-statements %t -- -- -std=c++17 |
| 2 | |
| 3 | void handle(bool); |
| 4 | |
| 5 | template <bool branch> |
| 6 | void shouldFail() { |
| 7 | if constexpr (branch) |
| 8 | // CHECK-MESSAGES: :[[@LINE-1]]:24: warning: statement should be inside braces [readability-braces-around-statements] |
| 9 | handle(true); |
| 10 | else |
| 11 | // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: statement should be inside braces [readability-braces-around-statements] |
| 12 | handle(false); |
| 13 | } |
| 14 | |
| 15 | template <bool branch> |
| 16 | void shouldPass() { |
| 17 | if constexpr (branch) { |
| 18 | handle(true); |
| 19 | } else { |
| 20 | handle(false); |
| 21 | } |
| 22 | } |
| 23 | |
| 24 | void shouldFailNonTemplate() { |
| 25 | constexpr bool branch = false; |
| 26 | if constexpr (branch) |
| 27 | // CHECK-MESSAGES: :[[@LINE-1]]:24: warning: statement should be inside braces [readability-braces-around-statements] |
| 28 | handle(true); |
| 29 | else |
| 30 | // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: statement should be inside braces [readability-braces-around-statements] |
| 31 | handle(false); |
| 32 | } |
| 33 | |
| 34 | void shouldPass() { |
| 35 | constexpr bool branch = false; |
| 36 | if constexpr (branch) { |
| 37 | handle(true); |
| 38 | } else { |
| 39 | handle(false); |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | void run() { |
| 44 | shouldFail<true>(); |
| 45 | shouldFail<false>(); |
| 46 | shouldPass<true>(); |
| 47 | shouldPass<false>(); |
| 48 | } |
| 49 | |