Skip to content

Commit dd01ff1

Browse files
authored
fix #14315: FP knownConditionTrueFalse with constant in assert() (#8064)
1 parent 69a2d17 commit dd01ff1

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

lib/checkother.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2948,7 +2948,9 @@ void CheckOther::checkDuplicateExpression()
29482948
while (parent && parent->astParent()) {
29492949
parent = parent->astParent();
29502950
}
2951-
if (parent && parent->previous() && isStaticAssert(*mSettings, parent->previous())) {
2951+
if (parent && parent->previous() &&
2952+
(isStaticAssert(*mSettings, parent->previous()) ||
2953+
Token::simpleMatch(parent->previous(), "assert"))) {
29522954
continue;
29532955
}
29542956
}

test/testother.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ class TestOther : public TestFixture {
195195
TEST_CASE(duplicateExpression16); // #10569
196196
TEST_CASE(duplicateExpression17); // #12036
197197
TEST_CASE(duplicateExpression18);
198+
TEST_CASE(duplicateExpression19);
198199
TEST_CASE(duplicateExpressionLoop);
199200
TEST_CASE(duplicateValueTernary);
200201
TEST_CASE(duplicateValueTernarySizeof); // #13773
@@ -7988,6 +7989,14 @@ class TestOther : public TestFixture {
79887989
ASSERT_EQUALS("", errout_str());
79897990
}
79907991

7992+
void duplicateExpression19() {
7993+
checkP("const int i = 0;\n"
7994+
"void f() {\n"
7995+
" assert(i == 0);\n"
7996+
"}\n");
7997+
ASSERT_EQUALS("", errout_str());
7998+
}
7999+
79918000
void duplicateExpressionLoop() {
79928001
check("void f() {\n"
79938002
" int a = 1;\n"

0 commit comments

Comments
 (0)