summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/test/clang-tidy/checkers/readability-braces-around-statements-constexpr-if-templates.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'clang-tools-extra/test/clang-tidy/checkers/readability-braces-around-statements-constexpr-if-templates.cpp')
-rw-r--r--clang-tools-extra/test/clang-tidy/checkers/readability-braces-around-statements-constexpr-if-templates.cpp48
1 files changed, 48 insertions, 0 deletions
diff --git a/clang-tools-extra/test/clang-tidy/checkers/readability-braces-around-statements-constexpr-if-templates.cpp b/clang-tools-extra/test/clang-tidy/checkers/readability-braces-around-statements-constexpr-if-templates.cpp
new file mode 100644
index 00000000000..988125f9ce2
--- /dev/null
+++ b/clang-tools-extra/test/clang-tidy/checkers/readability-braces-around-statements-constexpr-if-templates.cpp
@@ -0,0 +1,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>();
+}
OpenPOWER on IntegriCloud