summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/test/clang-tidy/readability-else-after-return-if-constexpr.cpp
diff options
context:
space:
mode:
authorMarek Kurdej <marek.kurdej@gmail.com>2018-10-19 15:26:17 +0000
committerMarek Kurdej <marek.kurdej@gmail.com>2018-10-19 15:26:17 +0000
commitbc76dc3cec8a0cfd8e12844c6bce037a0b6af747 (patch)
treebee1f2f4a5cebf2d85f9820fee01e1c44d4f7162 /clang-tools-extra/test/clang-tidy/readability-else-after-return-if-constexpr.cpp
parent2a13d66301ce20583f15316515d50cf9ad70df71 (diff)
downloadbcm5719-llvm-bc76dc3cec8a0cfd8e12844c6bce037a0b6af747.tar.gz
bcm5719-llvm-bc76dc3cec8a0cfd8e12844c6bce037a0b6af747.zip
[clang-tidy] Resolve readability-else-after-return false positive for constexpr if.
Summary: It fixes the false positive when using constexpr if and where else cannot be removed: Example: ``` if constexpr (sizeof(int) > 4) // ... return /* ... */; else // This else cannot be removed. // ... return /* ... */; ``` Reviewers: alexfh, aaron.ballman Reviewed By: aaron.ballman Subscribers: lebedev.ri, xazax.hun, cfe-commits Differential Revision: https://reviews.llvm.org/D53372 llvm-svn: 344785
Diffstat (limited to 'clang-tools-extra/test/clang-tidy/readability-else-after-return-if-constexpr.cpp')
-rw-r--r--clang-tools-extra/test/clang-tidy/readability-else-after-return-if-constexpr.cpp22
1 files changed, 22 insertions, 0 deletions
diff --git a/clang-tools-extra/test/clang-tidy/readability-else-after-return-if-constexpr.cpp b/clang-tools-extra/test/clang-tidy/readability-else-after-return-if-constexpr.cpp
new file mode 100644
index 00000000000..6532940eaf2
--- /dev/null
+++ b/clang-tools-extra/test/clang-tidy/readability-else-after-return-if-constexpr.cpp
@@ -0,0 +1,22 @@
+// RUN: %check_clang_tidy %s readability-else-after-return %t -- -- -std=c++17
+
+// Constexpr if is an exception to the rule, we cannot remove the else.
+void f() {
+ if (sizeof(int) > 4)
+ return;
+ else
+ return;
+ // CHECK-MESSAGES: [[@LINE-2]]:3: warning: do not use 'else' after 'return'
+
+ if constexpr (sizeof(int) > 4)
+ return;
+ else
+ return;
+
+ if constexpr (sizeof(int) > 4)
+ return;
+ else if constexpr (sizeof(long) > 4)
+ return;
+ else
+ return;
+}
OpenPOWER on IntegriCloud