Skip to content

Commit 10fc070

Browse files
committed
SymbolDatabase: Better handling of type aliases in ValueType
1 parent b62c562 commit 10fc070

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

lib/symboldatabase.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5184,6 +5184,8 @@ static const Token * parsedecl(const Token *type, ValueType * const valuetype, V
51845184
valuetype->pointer++;
51855185
else if (type->isStandardType())
51865186
valuetype->fromLibraryType(type->str(), settings);
5187+
else if (Token::Match(type->previous(), "!!:: %name% !!::"))
5188+
valuetype->fromLibraryType(type->str(), settings);
51875189
if (!type->originalName().empty())
51885190
valuetype->originalTypeName = type->originalName();
51895191
type = type->next();

test/testsymboldatabase.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,9 @@ class TestSymbolDatabase: public TestFixture {
146146
TEST_CASE(isVariableDeclarationRValueRef);
147147
TEST_CASE(isVariableStlType);
148148

149+
TEST_CASE(VariableValueType1);
150+
TEST_CASE(VariableValueType2);
151+
149152
TEST_CASE(findVariableType1);
150153
TEST_CASE(findVariableType2);
151154
TEST_CASE(findVariableType3);
@@ -789,6 +792,22 @@ class TestSymbolDatabase: public TestFixture {
789792
ASSERT(var.tokens()->tokAt(2)->scope() != 0);
790793
}
791794

795+
void VariableValueType1() {
796+
GET_SYMBOL_DB("typedef uint8_t u8;\n"
797+
"static u8 x;\n");
798+
const Variable* x = db->getVariableFromVarId(1);
799+
ASSERT_EQUALS("x", x->name());
800+
ASSERT(x->valueType()->isIntegral());
801+
}
802+
803+
void VariableValueType2() {
804+
GET_SYMBOL_DB("using u8 = uint8_t;\n"
805+
"static u8 x;\n");
806+
const Variable* x = db->getVariableFromVarId(1);
807+
ASSERT_EQUALS("x", x->name());
808+
ASSERT(x->valueType()->isIntegral());
809+
}
810+
792811
void findVariableType1() {
793812
GET_SYMBOL_DB("class A {\n"
794813
"public:\n"

0 commit comments

Comments
 (0)