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