From 39265f8ce01a0441136f7caad0bcb31ac5d4bfb9 Mon Sep 17 00:00:00 2001 From: Paul Fultz II Date: Sun, 3 Apr 2022 13:04:18 -0500 Subject: [PATCH] Fix 10931: Assert failure in setSymbolic() (#3967) * Fix 10931: Assert failure in setSymbolic() * Format --- lib/symboldatabase.cpp | 3 +++ test/testautovariables.cpp | 3 ++- test/testvalueflow.cpp | 6 ++++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index b1edc11db..276f75c08 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -1466,6 +1466,9 @@ void SymbolDatabase::createSymbolDatabaseEscapeFunctions() static bool isExpression(const Token* tok) { + if (Token::simpleMatch(tok, "{") && tok->scope() && tok->scope()->bodyStart != tok && + (tok->astOperand1() || tok->astOperand2())) + return true; if (!Token::Match(tok, "(|.|[|::|?|:|++|--|%cop%|%assign%")) return false; if (Token::Match(tok, "*|&|&&")) { diff --git a/test/testautovariables.cpp b/test/testautovariables.cpp index 18f083b16..7c206213e 100644 --- a/test/testautovariables.cpp +++ b/test/testautovariables.cpp @@ -3203,7 +3203,8 @@ private: "A f() {\n" " return A{0};\n" "}\n"); - TODO_ASSERT_EQUALS("error", "", errout.str()); + ASSERT_EQUALS("[test.cpp:8] -> [test.cpp:8]: (error) Returning object that will be invalid when returning.\n", + errout.str()); check("struct A {\n" " int n;\n" diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index 671a70783..720bdacc2 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -6428,6 +6428,12 @@ private: " return x;\n" "}\n"; valueOfTok(code, "x"); + + code = "int* g();\n" + "void f() {\n" + " std::cout << (void*)(std::shared_ptr{ g() }.get());\n" + "}\n"; + valueOfTok(code, "."); } void valueFlowHang() {