Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #12249 Assert failure in ExpressionAnalyzer #5731

Merged
merged 2 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/symboldatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1732,7 +1732,7 @@ void SymbolDatabase::createSymbolDatabaseExprIds()
} else if (tok->astParent() && !tok->astOperand1() && !tok->astOperand2()) {
if (tok->tokType() == Token::Type::eBracket)
continue;
if (tok->astParent()->isAssignmentOp())
if (tok->astParent()->str() == "=")
continue;
if (tok->isControlFlowKeyword())
continue;
Expand Down
2 changes: 1 addition & 1 deletion test/cfg/std.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ void nullPointer_localtime_s(const std::time_t *restrict time, struct tm *restri
(void)std::localtime_s(time, result);
}

void memleak_localtime_s(const std::time_t *restrict time, struct tm *restrict result)
void memleak_localtime_s(const std::time_t *restrict time, struct tm *restrict result) // #9258
{
const time_t t = time(0);
const struct tm* const now = new tm();
Expand Down
13 changes: 13 additions & 0 deletions test/testvarid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ class TestVarID : public TestFixture {
TEST_CASE(exprid5);
TEST_CASE(exprid6);
TEST_CASE(exprid7);
TEST_CASE(exprid8);

TEST_CASE(structuredBindings);
}
Expand Down Expand Up @@ -3957,6 +3958,18 @@ class TestVarID : public TestFixture {
ASSERT_EQUALS(expected, tokenizeExpr(code));
}

void exprid8() {
const char code[] = "void f() {\n" // #12249
" std::string s;\n"
" (((s += \"--\") += std::string()) += \"=\");\n"
"}\n";
const char expected[] = "1: void f ( ) {\n"
"2: std ::@UNIQUE string s@1 ;\n"
"3: ( ( s@1 +=@UNIQUE \"--\"@UNIQUE ) +=@UNIQUE std ::@UNIQUE string (@UNIQUE ) ) +=@UNIQUE \"=\"@UNIQUE ;\n"
"4: }\n";
ASSERT_EQUALS(expected, tokenizeExpr(code));
}

void structuredBindings() {
const char code[] = "int foo() { auto [x,y] = xy(); return x+y; }";
ASSERT_EQUALS("1: int foo ( ) { auto [ x@1 , y@2 ] = xy ( ) ; return x@1 + y@2 ; }\n",
Expand Down
Loading