From 9f40341ba8588b00663638801dfbaef52240856c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Tue, 8 Oct 2019 12:51:23 +0200 Subject: [PATCH] SymbolDatabase: Hardcoded handling for std::make_shared and std::make_unique , todo: library configuration would be better than hard coding --- lib/symboldatabase.cpp | 13 +++++++++++++ test/testautovariables.cpp | 3 +-- test/testsymboldatabase.cpp | 3 +++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index c3dca6b69..3502c7cc9 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -5591,6 +5591,19 @@ void SymbolDatabase::setValueTypeInTokenList(bool reportDebugWarnings) setValueType(tok, vt); continue; } + + const std::string e = tok->astOperand1()->expressionString(); + + if ((e == "std::make_shared" || e == "std::make_unique") && Token::Match(tok->astOperand1(), ":: %name% < %name%")) { + ValueType vt; + parsedecl(tok->astOperand1()->tokAt(3), &vt, mDefaultSignedness, mSettings); + if (vt.typeScope) { + vt.smartPointerType = vt.typeScope->definedType; + vt.typeScope = nullptr; + setValueType(tok, vt); + continue; + } + } } const std::string& typestr(mSettings->library.returnValueType(tok->previous())); diff --git a/test/testautovariables.cpp b/test/testautovariables.cpp index 7635971d1..00b82341d 100644 --- a/test/testautovariables.cpp +++ b/test/testautovariables.cpp @@ -2349,8 +2349,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void danglingTemporaryLifetime() - { + void danglingTemporaryLifetime() { check("const int& g(const int& x) {\n" " return x;\n" "}\n" diff --git a/test/testsymboldatabase.cpp b/test/testsymboldatabase.cpp index c7510fe9f..380980491 100644 --- a/test/testsymboldatabase.cpp +++ b/test/testsymboldatabase.cpp @@ -6382,6 +6382,9 @@ private: // Variable declaration ASSERT_EQUALS("char *", typeOf("; char abc[] = \"abc\";", "[")); ASSERT_EQUALS("", typeOf("; int x[10] = { [3]=1 };", "[ 3 ]")); + + // std::make_shared + ASSERT_EQUALS("smart-pointer", typeOf("class C {}; x = std::make_shared();", "(")); } void variadic1() { // #7453