@@ -441,8 +441,6 @@ AST_MATCHER(Expr, isIntegerConstantExpr) {
441
441
return Node.isIntegerConstantExpr (Finder->getASTContext ());
442
442
}
443
443
444
- AST_MATCHER (Expr, isRequiresExpr) { return isa<RequiresExpr>(Node); }
445
-
446
444
AST_MATCHER (BinaryOperator, operandsAreEquivalent) {
447
445
return areEquivalentExpr (Node.getLHS (), Node.getRHS ());
448
446
}
@@ -862,7 +860,8 @@ void RedundantExpressionCheck::registerMatchers(MatchFinder *Finder) {
862
860
863
861
const auto BannedIntegerLiteral =
864
862
integerLiteral (expandedByMacro (KnownBannedMacroNames));
865
- const auto BannedAncestor = expr (isRequiresExpr ());
863
+ const auto IsInUnevaluatedContext = expr (anyOf (
864
+ hasAncestor (expr (hasUnevaluatedContext ())), hasAncestor (typeLoc ())));
866
865
867
866
// Binary with equivalent operands, like (X != 2 && X != 2).
868
867
Finder->addMatcher (
@@ -879,7 +878,7 @@ void RedundantExpressionCheck::registerMatchers(MatchFinder *Finder) {
879
878
unless (hasEitherOperand (hasType (realFloatingPointType ()))),
880
879
unless (hasLHS (AnyLiteralExpr)),
881
880
unless (hasDescendant (BannedIntegerLiteral)),
882
- unless (hasAncestor (BannedAncestor) ))
881
+ unless (IsInUnevaluatedContext ))
883
882
.bind (" binary" )),
884
883
this );
885
884
@@ -893,7 +892,7 @@ void RedundantExpressionCheck::registerMatchers(MatchFinder *Finder) {
893
892
unless (binaryOperatorIsInMacro ()),
894
893
// TODO: if the banned macros are themselves duplicated
895
894
unless (hasDescendant (BannedIntegerLiteral)),
896
- unless (hasAncestor (BannedAncestor) ))
895
+ unless (IsInUnevaluatedContext ))
897
896
.bind (" nested-duplicates" ),
898
897
this );
899
898
@@ -904,7 +903,7 @@ void RedundantExpressionCheck::registerMatchers(MatchFinder *Finder) {
904
903
// Filter noisy false positives.
905
904
unless (conditionalOperatorIsInMacro ()),
906
905
unless (isInTemplateInstantiation ()),
907
- unless (hasAncestor (BannedAncestor) ))
906
+ unless (IsInUnevaluatedContext ))
908
907
.bind (" cond" )),
909
908
this );
910
909
@@ -918,7 +917,7 @@ void RedundantExpressionCheck::registerMatchers(MatchFinder *Finder) {
918
917
parametersAreEquivalent (),
919
918
// Filter noisy false positives.
920
919
unless (isMacro ()), unless (isInTemplateInstantiation ()),
921
- unless (hasAncestor (BannedAncestor) ))
920
+ unless (IsInUnevaluatedContext ))
922
921
.bind (" call" )),
923
922
this );
924
923
@@ -929,7 +928,7 @@ void RedundantExpressionCheck::registerMatchers(MatchFinder *Finder) {
929
928
nestedParametersAreEquivalent (), argumentCountIs (2 ),
930
929
// Filter noisy false positives.
931
930
unless (isMacro ()), unless (isInTemplateInstantiation ()),
932
- unless (hasAncestor (BannedAncestor) ))
931
+ unless (IsInUnevaluatedContext ))
933
932
.bind (" nested-duplicates" ),
934
933
this );
935
934
@@ -947,7 +946,7 @@ void RedundantExpressionCheck::registerMatchers(MatchFinder *Finder) {
947
946
integerLiteral ())),
948
947
hasRHS (integerLiteral ())))))
949
948
.bind (" logical-bitwise-confusion" )),
950
- unless (hasAncestor (BannedAncestor) ))),
949
+ unless (IsInUnevaluatedContext ))),
951
950
this );
952
951
953
952
// Match expressions like: (X << 8) & 0xFF
@@ -961,7 +960,7 @@ void RedundantExpressionCheck::registerMatchers(MatchFinder *Finder) {
961
960
integerLiteral ().bind (" shift-const" ))))),
962
961
ignoringParenImpCasts (
963
962
integerLiteral ().bind (" and-const" ))),
964
- unless (hasAncestor (BannedAncestor) ))
963
+ unless (IsInUnevaluatedContext ))
965
964
.bind (" left-right-shift-confusion" )),
966
965
this );
967
966
@@ -980,7 +979,7 @@ void RedundantExpressionCheck::registerMatchers(MatchFinder *Finder) {
980
979
Finder->addMatcher (
981
980
traverse (TK_AsIs, binaryOperator (isComparisonOperator (),
982
981
hasOperands (BinOpCstLeft, CstRight),
983
- unless (hasAncestor (BannedAncestor) ))
982
+ unless (IsInUnevaluatedContext ))
984
983
.bind (" binop-const-compare-to-const" )),
985
984
this );
986
985
@@ -991,7 +990,7 @@ void RedundantExpressionCheck::registerMatchers(MatchFinder *Finder) {
991
990
binaryOperator (isComparisonOperator (),
992
991
anyOf (allOf (hasLHS (BinOpCstLeft), hasRHS (SymRight)),
993
992
allOf (hasLHS (SymRight), hasRHS (BinOpCstLeft))),
994
- unless (hasAncestor (BannedAncestor) ))
993
+ unless (IsInUnevaluatedContext ))
995
994
.bind (" binop-const-compare-to-sym" )),
996
995
this );
997
996
@@ -1002,7 +1001,7 @@ void RedundantExpressionCheck::registerMatchers(MatchFinder *Finder) {
1002
1001
hasRHS (BinOpCstRight),
1003
1002
// Already reported as redundant.
1004
1003
unless (operandsAreEquivalent ()),
1005
- unless (hasAncestor (BannedAncestor) ))
1004
+ unless (IsInUnevaluatedContext ))
1006
1005
.bind (" binop-const-compare-to-binop-const" )),
1007
1006
this );
1008
1007
@@ -1019,7 +1018,7 @@ void RedundantExpressionCheck::registerMatchers(MatchFinder *Finder) {
1019
1018
hasLHS (ComparisonLeft), hasRHS (ComparisonRight),
1020
1019
// Already reported as redundant.
1021
1020
unless (operandsAreEquivalent ()),
1022
- unless (hasAncestor (BannedAncestor) ))
1021
+ unless (IsInUnevaluatedContext ))
1023
1022
.bind (" comparisons-of-symbol-and-const" )),
1024
1023
this );
1025
1024
}
0 commit comments