diff --git a/clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp b/clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp --- a/clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp +++ b/clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp @@ -134,6 +134,8 @@ return cast(Left)->getOpcode() == cast(Right)->getOpcode(); case Stmt::BinaryOperatorClass: + if (cast(Left)->isAssignmentOp()) + return false; return cast(Left)->getOpcode() == cast(Right)->getOpcode(); case Stmt::UnaryExprOrTypeTraitExprClass: diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -132,7 +132,7 @@ the vector is a member of a structure. - Fixed a false positive in :doc:`readability-non-const-parameter - ` when the parameter is referenced by an lvalue + ` when the parameter is referenced by an lvalue. - Fixed a crash in :doc:`readability-const-return-type ` when a pure virtual function @@ -150,6 +150,9 @@ Fixed an issue when there was already an initializer in the constructor and the check would try to create another initializer for the same member. +- Fixed a false positive in :doc:`misc-redundant-expression ` + involving assignments in conditions. This fixes `Issue 35853 `_. + Removed checks ^^^^^^^^^^^^^^ diff --git a/clang-tools-extra/test/clang-tidy/checkers/misc-redundant-expression.cpp b/clang-tools-extra/test/clang-tidy/checkers/misc-redundant-expression.cpp --- a/clang-tools-extra/test/clang-tidy/checkers/misc-redundant-expression.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/misc-redundant-expression.cpp @@ -831,3 +831,15 @@ }; } // namespace no_crash + +int TestAssignSideEffect(int i) { + int k = i; + + if ((k = k + 1) != 1 || (k = k + 1) != 2) + return 0; + + if ((k = foo(0)) != 1 || (k = foo(0)) != 2) + return 1; + + return 2; +}