Fix #12249 Assert failure in ExpressionAnalyzer (#5731)

This commit is contained in:
chrchr-github 2023-12-06 20:04:20 +01:00 committed by GitHub
parent 3fc62ce10b
commit 613bbe7674
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 2 deletions

View File

@ -1732,7 +1732,7 @@ void SymbolDatabase::createSymbolDatabaseExprIds()
} else if (tok->astParent() && !tok->astOperand1() && !tok->astOperand2()) { } else if (tok->astParent() && !tok->astOperand1() && !tok->astOperand2()) {
if (tok->tokType() == Token::Type::eBracket) if (tok->tokType() == Token::Type::eBracket)
continue; continue;
if (tok->astParent()->isAssignmentOp()) if (tok->astParent()->str() == "=")
continue; continue;
if (tok->isControlFlowKeyword()) if (tok->isControlFlowKeyword())
continue; continue;

View File

@ -603,7 +603,7 @@ void nullPointer_localtime_s(const std::time_t *restrict time, struct tm *restri
(void)std::localtime_s(time, result); (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 time_t t = time(0);
const struct tm* const now = new tm(); const struct tm* const now = new tm();

View File

@ -242,6 +242,7 @@ private:
TEST_CASE(exprid5); TEST_CASE(exprid5);
TEST_CASE(exprid6); TEST_CASE(exprid6);
TEST_CASE(exprid7); TEST_CASE(exprid7);
TEST_CASE(exprid8);
TEST_CASE(structuredBindings); TEST_CASE(structuredBindings);
} }
@ -3957,6 +3958,18 @@ private:
ASSERT_EQUALS(expected, tokenizeExpr(code)); 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() { void structuredBindings() {
const char code[] = "int foo() { auto [x,y] = xy(); return x+y; }"; 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", ASSERT_EQUALS("1: int foo ( ) { auto [ x@1 , y@2 ] = xy ( ) ; return x@1 + y@2 ; }\n",