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