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 @@ -144,8 +144,9 @@ const auto *RightUnaryExpr = cast(Right); if (LeftUnaryExpr->isArgumentType() && RightUnaryExpr->isArgumentType()) - return LeftUnaryExpr->getArgumentType() == - RightUnaryExpr->getArgumentType(); + return LeftUnaryExpr->getKind() == RightUnaryExpr->getKind() && + LeftUnaryExpr->getArgumentType() == + RightUnaryExpr->getArgumentType(); if (!LeftUnaryExpr->isArgumentType() && !RightUnaryExpr->isArgumentType()) return areEquivalentExpr(LeftUnaryExpr->getArgumentExpr(), RightUnaryExpr->getArgumentExpr()); 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 @@ -360,6 +360,10 @@ ` to avoid warning on declarations inside anonymous namespaces. +- Fixed false-positive in :doc:`misc-redundant-expression + ` check where expressions like + ``alignof`` or ``sizeof`` were incorrectly flagged as identical. + - Improved :doc:`misc-unused-parameters ` check with new `IgnoreVirtual` option to optionally ignore virtual methods. 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 @@ -843,3 +843,15 @@ return 2; } + +namespace PR63096 { + +struct alignas(sizeof(int)) X { + int x; +}; + +static_assert(alignof(X) == sizeof(X)); +static_assert(sizeof(X) == sizeof(X)); +// CHECK-MESSAGES: :[[@LINE-1]]:25: warning: both sides of operator are equivalent + +}