Skip to content

Commit 613bbe7

Browse files
Fix #12249 Assert failure in ExpressionAnalyzer (#5731)
1 parent 3fc62ce commit 613bbe7

3 files changed

Lines changed: 15 additions & 2 deletions

File tree

lib/symboldatabase.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1732,7 +1732,7 @@ void SymbolDatabase::createSymbolDatabaseExprIds()
17321732
} else if (tok->astParent() && !tok->astOperand1() && !tok->astOperand2()) {
17331733
if (tok->tokType() == Token::Type::eBracket)
17341734
continue;
1735-
if (tok->astParent()->isAssignmentOp())
1735+
if (tok->astParent()->str() == "=")
17361736
continue;
17371737
if (tok->isControlFlowKeyword())
17381738
continue;

test/cfg/std.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,7 @@ void nullPointer_localtime_s(const std::time_t *restrict time, struct tm *restri
603603
(void)std::localtime_s(time, result);
604604
}
605605

606-
void memleak_localtime_s(const std::time_t *restrict time, struct tm *restrict result)
606+
void memleak_localtime_s(const std::time_t *restrict time, struct tm *restrict result) // #9258
607607
{
608608
const time_t t = time(0);
609609
const struct tm* const now = new tm();

test/testvarid.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ class TestVarID : public TestFixture {
242242
TEST_CASE(exprid5);
243243
TEST_CASE(exprid6);
244244
TEST_CASE(exprid7);
245+
TEST_CASE(exprid8);
245246

246247
TEST_CASE(structuredBindings);
247248
}
@@ -3957,6 +3958,18 @@ class TestVarID : public TestFixture {
39573958
ASSERT_EQUALS(expected, tokenizeExpr(code));
39583959
}
39593960

3961+
void exprid8() {
3962+
const char code[] = "void f() {\n" // #12249
3963+
" std::string s;\n"
3964+
" (((s += \"--\") += std::string()) += \"=\");\n"
3965+
"}\n";
3966+
const char expected[] = "1: void f ( ) {\n"
3967+
"2: std ::@UNIQUE string s@1 ;\n"
3968+
"3: ( ( s@1 +=@UNIQUE \"--\"@UNIQUE ) +=@UNIQUE std ::@UNIQUE string (@UNIQUE ) ) +=@UNIQUE \"=\"@UNIQUE ;\n"
3969+
"4: }\n";
3970+
ASSERT_EQUALS(expected, tokenizeExpr(code));
3971+
}
3972+
39603973
void structuredBindings() {
39613974
const char code[] = "int foo() { auto [x,y] = xy(); return x+y; }";
39623975
ASSERT_EQUALS("1: int foo ( ) { auto [ x@1 , y@2 ] = xy ( ) ; return x@1 + y@2 ; }\n",

0 commit comments

Comments
 (0)