fix #10172 (debug: Executable scope 'x' with unknown function.) (#3121)

This commit is contained in:
IOBYTE 2021-02-11 02:08:45 -05:00 committed by GitHub
parent 51f93400d1
commit b6e93bb575
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 92 additions and 1 deletions

View File

@ -1808,6 +1808,22 @@ namespace {
}
}
const ScopeInfo3 * findScopeRecursive(const std::string & scope) const {
if (fullName.size() < scope.size() &&
fullName == scope.substr(0, fullName.size())) {
for (auto & child : children) {
if (child.fullName == scope && &child != this)
return &child;
else {
const ScopeInfo3 * temp1 = child.findScopeRecursive(scope);
if (temp1)
return temp1;
}
}
}
return nullptr;
}
const ScopeInfo3 * findScope(const std::string & scope) const {
const ScopeInfo3 * tempScope = this;
while (tempScope) {
@ -1815,9 +1831,17 @@ namespace {
if (child.type == Record && (child.name == scope || child.fullName == scope))
return &child;
}
tempScope = tempScope->parent;
}
// check for another scope with same name
const ScopeInfo3 * global = this;
while (global->parent)
global = global->parent;
for (const ScopeInfo3 & tempChild : global->children) {
const ScopeInfo3 * temp = tempChild.findScopeRecursive(scope);
if (temp)
return temp;
}
return nullptr;
}

View File

@ -80,6 +80,7 @@ private:
TEST_CASE(simplifyUsing10054);
TEST_CASE(simplifyUsing10136);
TEST_CASE(simplifyUsing10171);
TEST_CASE(simplifyUsing10172);
}
std::string tok(const char code[], bool simplify = true, Settings::PlatformType type = Settings::Native, bool debugwarnings = true) {
@ -1032,6 +1033,72 @@ private:
"void B :: f ( const std :: vector < unsigned char > & ) const { } "
"}";
ASSERT_EQUALS(exp, tok(code, false));
ASSERT_EQUALS("", errout.str());
}
void simplifyUsing10172() {
{
const char code[] = "namespace ns {\n"
" class A {\n"
" public:\n"
" using h = std::function<void()>;\n"
" };\n"
" class B : public A {\n"
" void f(h);\n"
" };\n"
"}\n"
"namespace ns {\n"
" void B::f(h) { }\n"
"}";
const char exp[] = "namespace ns { "
"class A { "
"public: "
"} ; "
"class B : public A { "
"void f ( std :: function < void ( ) > ) ; "
"} ; "
"} "
"namespace ns { "
"void B :: f ( std :: function < void ( ) > ) { } "
"}";
ASSERT_EQUALS(exp, tok(code, false));
ASSERT_EQUALS("", errout.str());
}
{
const char code[] = "namespace ns {\n"
"namespace external {\n"
"class A {\n"
"public: \n"
" using h = std::function<void()>;\n"
"};\n"
"class B : public A {\n"
" void f(h);\n"
"};\n"
"}\n"
"}\n"
"namespace ns {\n"
"namespace external {\n"
"void B::f(h) {}\n"
"}\n"
"}";
const char exp[] = "namespace ns { "
"namespace external { "
"class A { "
"public: "
"} ; "
"class B : public A { "
"void f ( std :: function < void ( ) > ) ; "
"} ; "
"} "
"} "
"namespace ns { "
"namespace external { "
"void B :: f ( std :: function < void ( ) > ) { } "
"} "
"}";
ASSERT_EQUALS(exp, tok(code, false));
ASSERT_EQUALS("", errout.str());
}
}
};