fix debug printing of valuetype name with namespaces (#2968)

This commit is contained in:
IOBYTE 2020-12-21 13:47:54 -05:00 committed by GitHub
parent 01ac4073c8
commit 2ecab32fbe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 1 deletions

View File

@ -6623,7 +6623,7 @@ std::string ValueType::str() const
while (scope && scope->type != Scope::eGlobal) { while (scope && scope->type != Scope::eGlobal) {
if (scope->type == Scope::eClass || scope->type == Scope::eStruct || scope->type == Scope::eNamespace) if (scope->type == Scope::eClass || scope->type == Scope::eStruct || scope->type == Scope::eNamespace)
className = scope->className + "::" + className; className = scope->className + "::" + className;
scope = scope->definedType ? scope->definedType->enclosingScope : scope->nestedIn; scope = (scope->definedType && scope->definedType->enclosingScope) ? scope->definedType->enclosingScope : scope->nestedIn;
} }
ret += ' ' + className; ret += ' ' + className;
} else if (type == ValueType::Type::CONTAINER && container) { } else if (type == ValueType::Type::CONTAINER && container) {

View File

@ -333,6 +333,7 @@ private:
TEST_CASE(symboldatabase86); TEST_CASE(symboldatabase86);
TEST_CASE(symboldatabase87); // #9922 'extern const char ( * x [ 256 ] ) ;' TEST_CASE(symboldatabase87); // #9922 'extern const char ( * x [ 256 ] ) ;'
TEST_CASE(symboldatabase88); // #10040 (using namespace) TEST_CASE(symboldatabase88); // #10040 (using namespace)
TEST_CASE(symboldatabase89); // valuetype name
TEST_CASE(createSymbolDatabaseFindAllScopes1); TEST_CASE(createSymbolDatabaseFindAllScopes1);
@ -4805,6 +4806,27 @@ private:
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
} }
void symboldatabase89() { // valuetype name
GET_SYMBOL_DB("namespace external {\n"
"namespace ns1 {\n"
"class A {\n"
"public:\n"
" struct S { };\n"
" A(const S&) { }\n"
"};\n"
"static const A::S AS = A::S();\n"
"}\n"
"}\n"
"using namespace external::ns1;\n"
"A a{AS};");
const Token *vartok1 = Token::findsimplematch(tokenizer.tokens(), "A a");
ASSERT(vartok1);
ASSERT(vartok1->next());
ASSERT(vartok1->next()->variable());
ASSERT(vartok1->next()->variable()->valueType());
ASSERT(vartok1->next()->variable()->valueType()->str() == "external::ns1::A");
}
void createSymbolDatabaseFindAllScopes1() { void createSymbolDatabaseFindAllScopes1() {
GET_SYMBOL_DB("void f() { union {int x; char *p;} a={0}; }"); GET_SYMBOL_DB("void f() { union {int x; char *p;} a={0}; }");
ASSERT(db->scopeList.size() == 3); ASSERT(db->scopeList.size() == 3);