Skip to content

Commit 8119a9d

Browse files
Fix #13305 FN moduloofone with %= (danmar#8353)
1 parent 3a7e382 commit 8119a9d

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

lib/checkother.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4429,7 +4429,7 @@ void CheckOther::checkModuloOfOne()
44294429
for (const Token *tok = mTokenizer->tokens(); tok; tok = tok->next()) {
44304430
if (!tok->astOperand2() || !tok->astOperand1())
44314431
continue;
4432-
if (tok->str() != "%")
4432+
if (tok->str() != "%" && tok->str() != "%=")
44334433
continue;
44344434
if (!tok->valueType() || !tok->valueType()->isIntegral())
44354435
continue;

test/testother.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13284,6 +13284,13 @@ class TestOther : public TestFixture {
1328413284
" if (j % c) {}\n"
1328513285
"}\n");
1328613286
ASSERT_EQUALS("", errout_str());
13287+
13288+
check("void f() {\n"
13289+
" int i = 0;\n"
13290+
" i %= 1;\n"
13291+
" (void)i;\n"
13292+
"}\n");
13293+
ASSERT_EQUALS("[test.cpp:3:7]: (style) Modulo of one is always equal to zero [moduloofone]\n", errout_str());
1328713294
}
1328813295

1328913296
void sameExpressionPointers() {

0 commit comments

Comments
 (0)