Skip to content

Commit fa40b5e

Browse files
Fix #12450 Assert failure in ExpressionAnalyzer() (#5992)
1 parent d14dd5d commit fa40b5e

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

lib/symboldatabase.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1623,7 +1623,10 @@ namespace {
16231623
return;
16241624
const Token* op2 = tok->astParent()->astOperand2();
16251625
if (op2 && op2->exprId() == 0 &&
1626-
!(isLambdaCaptureList(op2) || (op2->str() == "(" && isLambdaCaptureList(op2->astOperand1())) || Token::simpleMatch(op2, "{ }")))
1626+
!((tok->astParent()->astParent() && tok->astParent()->isAssignmentOp() && tok->astParent()->astParent()->isAssignmentOp()) ||
1627+
isLambdaCaptureList(op2) ||
1628+
(op2->str() == "(" && isLambdaCaptureList(op2->astOperand1())) ||
1629+
Token::simpleMatch(op2, "{ }")))
16271630
return;
16281631

16291632
if (tok->astParent()->isExpandedMacro() || Token::Match(tok->astParent(), "++|--")) {

test/testvarid.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ class TestVarID : public TestFixture {
244244
TEST_CASE(exprid7);
245245
TEST_CASE(exprid8);
246246
TEST_CASE(exprid9);
247+
TEST_CASE(exprid10);
247248

248249
TEST_CASE(structuredBindings);
249250
}
@@ -4028,6 +4029,19 @@ class TestVarID : public TestFixture {
40284029
ASSERT_EQUALS(expected, tokenizeExpr(code));
40294030
}
40304031

4032+
void exprid10()
4033+
{
4034+
const char code[] = "void f(const std::string& p) {\n" // #12350
4035+
" std::string s;\n"
4036+
" ((s = \"abc\") += p) += \"def\";\n"
4037+
"}\n";
4038+
const char expected[] = "1: void f ( const std :: string & p ) {\n"
4039+
"2: std ::@UNIQUE string s@2 ;\n"
4040+
"3: ( ( s@2 =@UNIQUE \"abc\" ) +=@UNIQUE p@1 ) +=@UNIQUE \"def\"@UNIQUE ;\n"
4041+
"4: }\n";
4042+
ASSERT_EQUALS(expected, tokenizeExpr(code));
4043+
}
4044+
40314045
void structuredBindings() {
40324046
const char code[] = "int foo() { auto [x,y] = xy(); return x+y; }";
40334047
ASSERT_EQUALS("1: int foo ( ) { auto [ x@1 , y@2 ] = xy ( ) ; return x@1 + y@2 ; }\n",

0 commit comments

Comments
 (0)