Skip to content

Commit c8cdd7a

Browse files
authored
Fix #12999: Improve smart_pointer ValueType assignment (danmar#6674)
1 parent aa3b8d9 commit c8cdd7a

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

lib/symboldatabase.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7303,9 +7303,9 @@ static const Token* parsedecl(const Token* type,
73037303
type = type->next();
73047304
}
73057305
break;
7306-
} else if (!valuetype->typeScope && (type->str() == "struct" || type->str() == "enum"))
7306+
} else if (!valuetype->typeScope && (type->str() == "struct" || type->str() == "enum") && valuetype->type != ValueType::Type::SMART_POINTER)
73077307
valuetype->type = type->str() == "struct" ? ValueType::Type::RECORD : ValueType::Type::NONSTD;
7308-
else if (!valuetype->typeScope && type->type() && type->type()->classScope) {
7308+
else if (!valuetype->typeScope && type->type() && type->type()->classScope && valuetype->type != ValueType::Type::SMART_POINTER) {
73097309
if (type->type()->classScope->type == Scope::ScopeType::eEnum) {
73107310
valuetype->sign = ValueType::Sign::SIGNED;
73117311
valuetype->type = getEnumType(type->type()->classScope, settings.platform);

test/testsymboldatabase.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ class TestSymbolDatabase : public TestFixture {
221221
TEST_CASE(VariableValueType3);
222222
TEST_CASE(VariableValueType4); // smart pointer type
223223
TEST_CASE(VariableValueType5); // smart pointer type
224+
TEST_CASE(VariableValueType6); // smart pointer type
224225
TEST_CASE(VariableValueTypeReferences);
225226
TEST_CASE(VariableValueTypeTemplate);
226227

@@ -1264,6 +1265,16 @@ class TestSymbolDatabase : public TestFixture {
12641265
ASSERT(p->valueType()->pointer == 1);
12651266
}
12661267

1268+
void VariableValueType6() {
1269+
GET_SYMBOL_DB("struct Data{};\n"
1270+
"void foo() { std::unique_ptr<Data> data = std::unique_ptr<Data>(new Data); }");
1271+
1272+
const Token* check = Token::findsimplematch(tokenizer.tokens(), "( new");
1273+
ASSERT(check);
1274+
ASSERT(check->valueType());
1275+
ASSERT(check->valueType()->smartPointerTypeToken);
1276+
}
1277+
12671278
void VariableValueTypeReferences() {
12681279
{
12691280
GET_SYMBOL_DB("void foo(int x) {}\n");

test/testunusedvar.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6552,7 +6552,6 @@ class TestUnusedVar : public TestFixture {
65526552
" auto a2 = std::unique_ptr<A>(new A());\n"
65536553
"}\n");
65546554
ASSERT_EQUALS("[test.cpp:7]: (style) Variable 'a' is assigned a value that is never used.\n"
6555-
"[test.cpp:8]: (style) Variable 'a2' is assigned a value that is never used.\n"
65566555
"[test.cpp:8]: (style) Variable 'a2' is assigned a value that is never used.\n", // duplicate
65576556
errout_str());
65586557

0 commit comments

Comments
 (0)