parent
1872725ca2
commit
f48e195c31
|
@ -1843,9 +1843,10 @@ namespace {
|
||||||
return;
|
return;
|
||||||
if (tok->str() == "{" && (*scopeInfo)->parent && tok == (*scopeInfo)->bodyStart)
|
if (tok->str() == "{" && (*scopeInfo)->parent && tok == (*scopeInfo)->bodyStart)
|
||||||
return;
|
return;
|
||||||
|
if (tok->str() == "}" && (*scopeInfo)->parent && tok == (*scopeInfo)->bodyEnd) {
|
||||||
while (tok->str() == "}" && (*scopeInfo)->parent && tok == (*scopeInfo)->bodyEnd)
|
|
||||||
*scopeInfo = (*scopeInfo)->parent;
|
*scopeInfo = (*scopeInfo)->parent;
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (!Token::Match(tok, "namespace|class|struct|union %name% {|:|::|<")) {
|
if (!Token::Match(tok, "namespace|class|struct|union %name% {|:|::|<")) {
|
||||||
// check for using namespace
|
// check for using namespace
|
||||||
if (Token::Match(tok, "using namespace %name% ;|::")) {
|
if (Token::Match(tok, "using namespace %name% ;|::")) {
|
||||||
|
@ -2254,12 +2255,20 @@ bool Tokenizer::simplifyUsing()
|
||||||
// of the token stream because templates are instantiated at
|
// of the token stream because templates are instantiated at
|
||||||
// the end of the token stream and it may be used before then.
|
// the end of the token stream and it may be used before then.
|
||||||
std::string scope1;
|
std::string scope1;
|
||||||
|
bool inMemberFunc = false;
|
||||||
|
const ScopeInfo3 * memberFuncScope = nullptr;
|
||||||
|
const Token * memberFuncEnd = nullptr;
|
||||||
bool skip = false; // don't erase type aliases we can't parse
|
bool skip = false; // don't erase type aliases we can't parse
|
||||||
for (Token* tok1 = list.front(); tok1; tok1 = tok1->next()) {
|
for (Token* tok1 = list.front(); tok1; tok1 = tok1->next()) {
|
||||||
if ((Token::Match(tok1, "{|}|namespace|class|struct|union") && tok1->strAt(-1) != "using") ||
|
if ((Token::Match(tok1, "{|}|namespace|class|struct|union") && tok1->strAt(-1) != "using") ||
|
||||||
Token::Match(tok1, "using namespace %name% ;|::")) {
|
Token::Match(tok1, "using namespace %name% ;|::")) {
|
||||||
setScopeInfo(tok1, ¤tScope1, true);
|
setScopeInfo(tok1, ¤tScope1, true);
|
||||||
scope1 = currentScope1->fullName;
|
scope1 = currentScope1->fullName;
|
||||||
|
if (inMemberFunc && memberFuncEnd && tok1 == memberFuncEnd) {
|
||||||
|
inMemberFunc = false;
|
||||||
|
memberFuncScope = nullptr;
|
||||||
|
memberFuncEnd = nullptr;
|
||||||
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2280,9 +2289,18 @@ bool Tokenizer::simplifyUsing()
|
||||||
if (!scope1.empty())
|
if (!scope1.empty())
|
||||||
scope1 += " :: ";
|
scope1 += " :: ";
|
||||||
scope1 += memberFunctionScope(tok1);
|
scope1 += memberFunctionScope(tok1);
|
||||||
}
|
memberFuncScope = currentScope1->findScope(scope1);
|
||||||
|
|
||||||
if (!usingMatch(nameToken, scope, &tok1, scope1, currentScope1))
|
if (!memberFuncScope)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
inMemberFunc = true;
|
||||||
|
memberFuncEnd = currentScope1->bodyEnd;
|
||||||
|
continue;
|
||||||
|
} else if (inMemberFunc && memberFuncScope) {
|
||||||
|
if (!usingMatch(nameToken, scope, &tok1, scope1, memberFuncScope))
|
||||||
|
continue;
|
||||||
|
} else if (!usingMatch(nameToken, scope, &tok1, scope1, currentScope1))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// remove the qualification
|
// remove the qualification
|
||||||
|
|
|
@ -971,37 +971,8 @@ private:
|
||||||
"a . f ( v ) ; "
|
"a . f ( v ) ; "
|
||||||
"c . f ( v ) ; "
|
"c . f ( v ) ; "
|
||||||
"}";
|
"}";
|
||||||
const char act[] = "namespace NS1 { "
|
ASSERT_EQUALS(exp, tok(code, true));
|
||||||
"class B { "
|
ASSERT_EQUALS("", errout.str());
|
||||||
"public: "
|
|
||||||
"virtual void f ( const std :: vector < char > & ) const = 0 ; "
|
|
||||||
"} ; "
|
|
||||||
"} "
|
|
||||||
"namespace NS2 { "
|
|
||||||
"class A : public NS1 :: B { "
|
|
||||||
"public: "
|
|
||||||
"void f ( const std :: vector < char > & ) const override ; "
|
|
||||||
"} ; "
|
|
||||||
"namespace NS3 { "
|
|
||||||
"class C : public A { "
|
|
||||||
"public: "
|
|
||||||
"void f ( const std :: vector < char > & ) const override ; "
|
|
||||||
"} ; "
|
|
||||||
"void C :: f ( const V & ) const { } "
|
|
||||||
"} "
|
|
||||||
"void A :: f ( const V & ) const { } "
|
|
||||||
"} "
|
|
||||||
"void foo ( ) { "
|
|
||||||
"NS2 :: A a ; "
|
|
||||||
"NS2 :: NS3 :: C c ; "
|
|
||||||
"std :: vector < char > v ; "
|
|
||||||
"a . f ( v ) ; "
|
|
||||||
"c . f ( v ) ; "
|
|
||||||
"}";
|
|
||||||
TODO_ASSERT_EQUALS(exp, act, tok(code, true));
|
|
||||||
TODO_ASSERT_EQUALS("",
|
|
||||||
"[test.cpp:18]: (debug) Executable scope 'f' with unknown function.\n"
|
|
||||||
"[test.cpp:20]: (debug) Executable scope 'f' with unknown function.\n", errout.str());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue