zinovy.nis updated this revision to Diff 267565. zinovy.nis added a comment.
- Fix test. - Simplify the code. CHANGES SINCE LAST ACTION https://reviews.llvm.org/D80896/new/ https://reviews.llvm.org/D80896 Files: clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp clang-tools-extra/test/clang-tidy/checkers/misc-redundant-expression.cpp Index: clang-tools-extra/test/clang-tidy/checkers/misc-redundant-expression.cpp =================================================================== --- clang-tools-extra/test/clang-tidy/checkers/misc-redundant-expression.cpp +++ clang-tools-extra/test/clang-tidy/checkers/misc-redundant-expression.cpp @@ -15,6 +15,30 @@ extern int bar(int x); extern int bat(int x, int y); +namespace no_crash { +struct Foo {}; +bool operator<(const Foo &, const Foo &); +template <class T> +struct Bar { + static const Foo &GetFoo(); + static bool Test(const T &maybe_foo, const Foo &foo) { + return foo < GetFoo() && foo < maybe_foo; + } +}; + +template <class... Values> +struct Bar2 { + static_assert((... && (sizeof(Values) > 0)) || (... && (sizeof(Values) > 0))); + // CHECK-MESSAGES: :[[@LINE-1]]:47: warning: both sides of operator are equivalent [misc-redundant-expression] +}; +} // namespace no_crash + +template <int Shift, int Mask> +int TestOperatorConfusionDependent(int Y) { + int r1 = (Y << Shift) & 0xff; + int r2 = (Y << 8) & Mask; +} + int TestSimpleEquivalent(int X, int Y) { if (X - X) return 1; // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: both sides of operator are equivalent [misc-redundant-expression] @@ -774,23 +798,6 @@ // CHECK-FIXES: {{^}} return ~(1 | 2 | 4);{{$}} } -template <int Shift, int Mask> -int TestOperatorConfusionDependent(int Y) { - int r1 = (Y << Shift) & 0xff; - int r2 = (Y << 8) & Mask; -} #undef FLAG1 #undef FLAG2 #undef FLAG3 - -namespace no_crash { -struct Foo {}; -bool operator<(const Foo&, const Foo&); -template <class T> -struct Bar { - static const Foo &GetFoo(); - static bool Test(const T & maybe_foo, const Foo& foo) { - return foo < GetFoo() && foo < maybe_foo; - } -}; -} Index: clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp =================================================================== --- clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp +++ clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp @@ -72,8 +72,8 @@ Expr::const_child_iterator LeftIter = Left->child_begin(); Expr::const_child_iterator RightIter = Right->child_begin(); while (LeftIter != Left->child_end() && RightIter != Right->child_end()) { - if (!areEquivalentExpr(dyn_cast<Expr>(*LeftIter), - dyn_cast<Expr>(*RightIter))) + if (!areEquivalentExpr(dyn_cast_or_null<Expr>(*LeftIter), + dyn_cast_or_null<Expr>(*RightIter))) return false; ++LeftIter; ++RightIter; @@ -117,6 +117,9 @@ case Stmt::MemberExprClass: return cast<MemberExpr>(Left)->getMemberDecl() == cast<MemberExpr>(Right)->getMemberDecl(); + case Stmt::CXXFoldExprClass: + return cast<CXXFoldExpr>(Left)->getOperator() == + cast<CXXFoldExpr>(Right)->getOperator(); case Stmt::CXXFunctionalCastExprClass: case Stmt::CStyleCastExprClass: return cast<ExplicitCastExpr>(Left)->getTypeAsWritten() ==
Index: clang-tools-extra/test/clang-tidy/checkers/misc-redundant-expression.cpp =================================================================== --- clang-tools-extra/test/clang-tidy/checkers/misc-redundant-expression.cpp +++ clang-tools-extra/test/clang-tidy/checkers/misc-redundant-expression.cpp @@ -15,6 +15,30 @@ extern int bar(int x); extern int bat(int x, int y); +namespace no_crash { +struct Foo {}; +bool operator<(const Foo &, const Foo &); +template <class T> +struct Bar { + static const Foo &GetFoo(); + static bool Test(const T &maybe_foo, const Foo &foo) { + return foo < GetFoo() && foo < maybe_foo; + } +}; + +template <class... Values> +struct Bar2 { + static_assert((... && (sizeof(Values) > 0)) || (... && (sizeof(Values) > 0))); + // CHECK-MESSAGES: :[[@LINE-1]]:47: warning: both sides of operator are equivalent [misc-redundant-expression] +}; +} // namespace no_crash + +template <int Shift, int Mask> +int TestOperatorConfusionDependent(int Y) { + int r1 = (Y << Shift) & 0xff; + int r2 = (Y << 8) & Mask; +} + int TestSimpleEquivalent(int X, int Y) { if (X - X) return 1; // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: both sides of operator are equivalent [misc-redundant-expression] @@ -774,23 +798,6 @@ // CHECK-FIXES: {{^}} return ~(1 | 2 | 4);{{$}} } -template <int Shift, int Mask> -int TestOperatorConfusionDependent(int Y) { - int r1 = (Y << Shift) & 0xff; - int r2 = (Y << 8) & Mask; -} #undef FLAG1 #undef FLAG2 #undef FLAG3 - -namespace no_crash { -struct Foo {}; -bool operator<(const Foo&, const Foo&); -template <class T> -struct Bar { - static const Foo &GetFoo(); - static bool Test(const T & maybe_foo, const Foo& foo) { - return foo < GetFoo() && foo < maybe_foo; - } -}; -} Index: clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp =================================================================== --- clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp +++ clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp @@ -72,8 +72,8 @@ Expr::const_child_iterator LeftIter = Left->child_begin(); Expr::const_child_iterator RightIter = Right->child_begin(); while (LeftIter != Left->child_end() && RightIter != Right->child_end()) { - if (!areEquivalentExpr(dyn_cast<Expr>(*LeftIter), - dyn_cast<Expr>(*RightIter))) + if (!areEquivalentExpr(dyn_cast_or_null<Expr>(*LeftIter), + dyn_cast_or_null<Expr>(*RightIter))) return false; ++LeftIter; ++RightIter; @@ -117,6 +117,9 @@ case Stmt::MemberExprClass: return cast<MemberExpr>(Left)->getMemberDecl() == cast<MemberExpr>(Right)->getMemberDecl(); + case Stmt::CXXFoldExprClass: + return cast<CXXFoldExpr>(Left)->getOperator() == + cast<CXXFoldExpr>(Right)->getOperator(); case Stmt::CXXFunctionalCastExprClass: case Stmt::CStyleCastExprClass: return cast<ExplicitCastExpr>(Left)->getTypeAsWritten() ==
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits