@@ -159,6 +159,13 @@ static bool sameValue(const Expr *E1, const Expr *E2) {
159
159
case Stmt::UnaryOperatorClass:
160
160
return sameValue (cast<UnaryOperator>(E1 )->getSubExpr (),
161
161
cast<UnaryOperator>(E2 )->getSubExpr ());
162
+ case Stmt::BinaryOperatorClass: {
163
+ const auto *BinOp1 = cast<BinaryOperator>(E1 );
164
+ const auto *BinOp2 = cast<BinaryOperator>(E2 );
165
+ return BinOp1->getOpcode () == BinOp2->getOpcode () &&
166
+ sameValue (BinOp1->getLHS (), BinOp2->getLHS ()) &&
167
+ sameValue (BinOp1->getRHS (), BinOp2->getRHS ());
168
+ }
162
169
case Stmt::CharacterLiteralClass:
163
170
return cast<CharacterLiteral>(E1 )->getValue () ==
164
171
cast<CharacterLiteral>(E2 )->getValue ();
@@ -199,17 +206,22 @@ void UseDefaultMemberInitCheck::storeOptions(
199
206
}
200
207
201
208
void UseDefaultMemberInitCheck::registerMatchers (MatchFinder *Finder) {
202
- auto ConstExpRef = varDecl (anyOf (isConstexpr (), isStaticStorageClass ()));
209
+ auto NumericLiteral = anyOf (integerLiteral (), floatLiteral ());
210
+ auto UnaryNumericLiteral = unaryOperator (hasAnyOperatorName (" +" , " -" ),
211
+ hasUnaryOperand (NumericLiteral));
212
+
213
+ auto ConstExprRef = varDecl (anyOf (isConstexpr (), isStaticStorageClass ()));
214
+ auto ImmutableRef =
215
+ declRefExpr (to (decl (anyOf (enumConstantDecl (), ConstExprRef))));
216
+
217
+ auto BinaryNumericExpr = binaryOperator (
218
+ hasOperands (anyOf (NumericLiteral, ImmutableRef, binaryOperator ()),
219
+ anyOf (NumericLiteral, ImmutableRef, binaryOperator ())));
203
220
204
221
auto InitBase =
205
- anyOf (stringLiteral (), characterLiteral (), integerLiteral (),
206
- unaryOperator (hasAnyOperatorName (" +" , " -" ),
207
- hasUnaryOperand (integerLiteral ())),
208
- floatLiteral (),
209
- unaryOperator (hasAnyOperatorName (" +" , " -" ),
210
- hasUnaryOperand (floatLiteral ())),
211
- cxxBoolLiteral (), cxxNullPtrLiteralExpr (), implicitValueInitExpr (),
212
- declRefExpr (to (anyOf (enumConstantDecl (), ConstExpRef))));
222
+ anyOf (stringLiteral (), characterLiteral (), NumericLiteral,
223
+ UnaryNumericLiteral, cxxBoolLiteral (), cxxNullPtrLiteralExpr (),
224
+ implicitValueInitExpr (), ImmutableRef, BinaryNumericExpr);
213
225
214
226
auto ExplicitCastExpr = castExpr (hasSourceExpression (InitBase));
215
227
auto InitMatcher = anyOf (InitBase, ExplicitCastExpr);
0 commit comments