[clang-tools-extra] [clang-tidy] Fix readability-else-after-return for [[likely]]/[[unlikely]] if (PR #184684)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Mar 6 22:19:16 PST 2026
================
@@ -0,0 +1,41 @@
+// RUN: %check_clang_tidy -std=c++20-or-later %s readability-else-after-return %t
+
+void g();
+
+void f() {
+ if (true) [[likely]] {
+ return;
+ } else { // comment-0
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: do not use 'else' after 'return'
+ // CHECK-FIXES: {{^}} } // comment-0
+ }
+
+ if (false) [[unlikely]] {
+ return;
+ } else { // comment-1
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: do not use 'else' after 'return'
+ // CHECK-FIXES: {{^}} } // comment-1
+ }
+
+ if (true) [[likely]]
+ return;
+ else // comment-2
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not use 'else' after 'return'
+ // CHECK-FIXES: {{^}} else // comment-2
----------------
zeyi2 wrote:
Thanks!
https://github.com/llvm/llvm-project/pull/184684
More information about the cfe-commits
mailing list