================
@@ -0,0 +1,474 @@
+// RUN: %check_clang_tidy -check-suffixes=BASE -std=c++11 %s
readability-redundant-nested-if %t -- -- -fno-delayed-template-parsing
+// RUN: %check_clang_tidy -check-suffixes=BASE,CXX17 -std=c++17 %s
readability-redundant-nested-if %t -- -- -fno-delayed-template-parsing
+// RUN: %check_clang_tidy -check-suffixes=BASE,CXX17,CXX20 -std=c++20 %s
readability-redundant-nested-if %t -- -- -fno-delayed-template-parsing
+// RUN: %check_clang_tidy -check-suffixes=BASE,CXX17,CXX20,CXX23 -std=c++23 %s
readability-redundant-nested-if %t -- -- -fno-delayed-template-parsing
+// RUN: %check_clang_tidy -check-suffixes=BASE,CXX17,CXX20,CXX23,CXX26
-std=c++26 %s readability-redundant-nested-if %t -- --
-fno-delayed-template-parsing
+// RUN: %check_clang_tidy -check-suffixes=BASE,CXX17,CXX20,CXX23,CXX26,OPTWARN
-std=c++26 %s readability-redundant-nested-if %t -- -config='{CheckOptions:
{readability-redundant-nested-if.WarnOnDependentConstexprIf: true,
readability-redundant-nested-if.UserDefinedBoolConversionMode: WarnOnly}}' --
-fno-delayed-template-parsing
+// RUN: %check_clang_tidy -check-suffixes=BASE,CXX17,OPTFIX -std=c++17 %s
readability-redundant-nested-if %t -- -config='{CheckOptions:
{readability-redundant-nested-if.UserDefinedBoolConversionMode: WarnAndFix}}'
-- -fno-delayed-template-parsing
+
+bool cond(int X = 0);
+void sink();
+void bar();
+struct BoolLike {
+ explicit operator bool() const;
+};
+BoolLike make_bool_like();
+
+#define INNER_IF(C) if (C) sink()
+#define COND_MACRO cond()
+#define OUTER_IF if (cond())
+
+// Core coverage under default options.
+void positive_cases() {
+ // CHECK-MESSAGES-BASE: :[[@LINE+1]]:3: warning: nested if statements can be
merged
+ if (cond()) {
+ if (cond(1)) {
+ sink();
+ }
+ }
+ // CHECK-FIXES-BASE: if ((cond()) && (cond(1)))
+ // CHECK-FIXES-BASE: sink();
+
+ // CHECK-MESSAGES-BASE: :[[@LINE+1]]:3: warning: nested if statements can be
merged
+ if (cond() || cond(1))
+ if (cond(2))
+ sink();
+ // CHECK-FIXES-BASE: if ((cond() || cond(1)) && (cond(2)))
+ // CHECK-FIXES-BASE: sink();
+
+ // CHECK-MESSAGES-BASE: :[[@LINE+1]]:3: warning: nested if statements can be
merged
+ if (cond()) {
+ if (cond(1))
+ if (cond(2)) {
+ sink();
+ }
+ }
+ // CHECK-FIXES-BASE: if ((cond()) && (cond(1)) && (cond(2)))
+ // CHECK-FIXES-BASE: sink();
+}
+
+void stress_long_chain_case() {
+ // CHECK-MESSAGES-BASE: :[[@LINE+1]]:3: warning: nested if statements can be
merged
+ if (cond(0)) {
----------------
vbvictor wrote:
Can we emit notes on each `if` statement that should be merged?
https://github.com/llvm/llvm-project/pull/181558
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits