Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #12999: Improve smart_pointer ValueType assignment #6674

Merged
merged 3 commits into from
Aug 11, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/symboldatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7305,9 +7305,9 @@ static const Token* parsedecl(const Token* type,
type = type->next();
}
break;
} else if (!valuetype->typeScope && (type->str() == "struct" || type->str() == "enum"))
} else if (!valuetype->typeScope && (type->str() == "struct" || type->str() == "enum") && valuetype->type != ValueType::Type::SMART_POINTER)
valuetype->type = type->str() == "struct" ? ValueType::Type::RECORD : ValueType::Type::NONSTD;
else if (!valuetype->typeScope && type->type() && type->type()->classScope) {
else if (!valuetype->typeScope && type->type() && type->type()->classScope && valuetype->type != ValueType::Type::SMART_POINTER) {
if (type->type()->classScope->type == Scope::ScopeType::eEnum) {
valuetype->sign = ValueType::Sign::SIGNED;
valuetype->type = getEnumType(type->type()->classScope, settings.platform);
Expand Down
17 changes: 17 additions & 0 deletions test/testsymboldatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ class TestSymbolDatabase : public TestFixture {
TEST_CASE(VariableValueType3);
TEST_CASE(VariableValueType4); // smart pointer type
TEST_CASE(VariableValueType5); // smart pointer type
TEST_CASE(VariableValueType6); // smart pointer type
TEST_CASE(VariableValueTypeReferences);
TEST_CASE(VariableValueTypeTemplate);

Expand Down Expand Up @@ -1264,6 +1265,22 @@ class TestSymbolDatabase : public TestFixture {
ASSERT(p->valueType()->pointer == 1);
}

void VariableValueType6() {
GET_SYMBOL_DB("struct Data{};\n"
"void foo(std::shared_ptr<C>* p) { std::unique_ptr<Data> data = std::unique_ptr<Data>(new Data); }");
danmar marked this conversation as resolved.
Show resolved Hide resolved

const Token * check{nullptr};
danmar marked this conversation as resolved.
Show resolved Hide resolved
for (const Token * tok = tokenizer.tokens(); tok; tok = tok->next()) {
if (Token::Match(tok, "> ( new")) {
check = tok->next();
break;
}
}
ASSERT(check);
ASSERT(check->valueType());
ASSERT(check->valueType()->smartPointerTypeToken);
}

void VariableValueTypeReferences() {
{
GET_SYMBOL_DB("void foo(int x) {}\n");
Expand Down
1 change: 0 additions & 1 deletion test/testunusedvar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6552,7 +6552,6 @@ class TestUnusedVar : public TestFixture {
" auto a2 = std::unique_ptr<A>(new A());\n"
"}\n");
ASSERT_EQUALS("[test.cpp:7]: (style) Variable 'a' is assigned a value that is never used.\n"
"[test.cpp:8]: (style) Variable 'a2' is assigned a value that is never used.\n"
"[test.cpp:8]: (style) Variable 'a2' is assigned a value that is never used.\n", // duplicate
errout_str());

Expand Down
Loading