Skip to content

Commit bd521ed

Browse files
Fix #14300 FP duplicateValueTernary for pointers allocated with new (danmar#8004)
Co-authored-by: chrchr-github <noreply@github.com>
1 parent 566de27 commit bd521ed

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

lib/astutils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1430,7 +1430,7 @@ static bool compareKnownValue(const Token * const tok1, const Token * const tok2
14301430
if (v1 == tok1->values().end()) {
14311431
return false;
14321432
}
1433-
if (v1->isNonValue() || v1->isContainerSizeValue() || v1->isSymbolicValue())
1433+
if (v1->isNonValue() || v1->isContainerSizeValue() || v1->isBufferSizeValue() || v1->isSymbolicValue())
14341434
return false;
14351435
const auto v2 = std::find_if(tok2->values().cbegin(), tok2->values().cend(), isKnownFn);
14361436
if (v2 == tok2->values().end()) {

test/testother.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8203,6 +8203,18 @@ class TestOther : public TestFixture {
82038203
" return (x >= 0.0) ? 0.0 : -0.0;\n"
82048204
"}\n");
82058205
ASSERT_EQUALS("", errout_str());
8206+
8207+
check("struct A {};\n" // # 14300
8208+
"struct B {};\n"
8209+
"void f(bool x) {\n"
8210+
" A* a = new A();\n"
8211+
" B* b = new B();\n"
8212+
" auto p = x ? static_cast<void*>(a) : static_cast<void*>(b);\n"
8213+
" (void)p;\n"
8214+
" delete a;\n"
8215+
" delete b;\n"
8216+
"}\n");
8217+
ASSERT_EQUALS("", errout_str());
82068218
}
82078219

82088220
void duplicateValueTernarySizeof() { // #13773

0 commit comments

Comments
 (0)