From fa428ef79d6b2224d29610704b7bd16c1f77b126 Mon Sep 17 00:00:00 2001 From: chrchr-github Date: Sat, 17 Feb 2024 14:11:49 +0100 Subject: [PATCH 1/2] Fix #12450 Assert failure in ExpressionAnalyzer() --- lib/symboldatabase.cpp | 5 ++++- test/testvarid.cpp | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 32b9c921e73..14a35dd4ad8 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -1623,7 +1623,10 @@ namespace { return; const Token* op2 = tok->astParent()->astOperand2(); if (op2 && op2->exprId() == 0 && - !(isLambdaCaptureList(op2) || (op2->str() == "(" && isLambdaCaptureList(op2->astOperand1())) || Token::simpleMatch(op2, "{ }"))) + !((tok->astParent()->astParent() && tok->astParent()->isAssignmentOp() && tok->astParent()->astParent()->isAssignmentOp()) || + isLambdaCaptureList(op2) || + (op2->str() == "(" && isLambdaCaptureList(op2->astOperand1())) || + Token::simpleMatch(op2, "{ }"))) return; if (tok->astParent()->isExpandedMacro() || Token::Match(tok->astParent(), "++|--")) { diff --git a/test/testvarid.cpp b/test/testvarid.cpp index 98780b06653..1fc5a500dbe 100644 --- a/test/testvarid.cpp +++ b/test/testvarid.cpp @@ -244,6 +244,7 @@ class TestVarID : public TestFixture { TEST_CASE(exprid7); TEST_CASE(exprid8); TEST_CASE(exprid9); + TEST_CASE(exprid10); TEST_CASE(structuredBindings); } @@ -4028,6 +4029,19 @@ class TestVarID : public TestFixture { ASSERT_EQUALS(expected, tokenizeExpr(code)); } + void exprid10() + { + const char code[] = "void f(const std::string& p) {\n" // #12350 + " std::string s;\n" + " ((s = \"abc\") += p) += \"def\";\n" + "}\n"; + const char expected[] = "1: void f ( const std :: string & p ) {\n" + "2: std ::@UNIQUE string s@2 ;\n" + "3: ( ( s@2 =@UNIQUE \"abc\" ) +=@UNIQUE p@1 ) +=@UNIQUE \"def\"@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", From e24e243abd157d7de3140a61dce76e702e543de2 Mon Sep 17 00:00:00 2001 From: chrchr-github Date: Sat, 17 Feb 2024 14:13:31 +0100 Subject: [PATCH 2/2] Format --- lib/symboldatabase.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 14a35dd4ad8..1d004e60cd5 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -1624,9 +1624,9 @@ namespace { const Token* op2 = tok->astParent()->astOperand2(); if (op2 && op2->exprId() == 0 && !((tok->astParent()->astParent() && tok->astParent()->isAssignmentOp() && tok->astParent()->astParent()->isAssignmentOp()) || - isLambdaCaptureList(op2) || - (op2->str() == "(" && isLambdaCaptureList(op2->astOperand1())) || - Token::simpleMatch(op2, "{ }"))) + isLambdaCaptureList(op2) || + (op2->str() == "(" && isLambdaCaptureList(op2->astOperand1())) || + Token::simpleMatch(op2, "{ }"))) return; if (tok->astParent()->isExpandedMacro() || Token::Match(tok->astParent(), "++|--")) {