Fixed #8270 (Tokenizer: wrong varid (using namespace std))

This commit is contained in:
Daniel Marjamäki 2017-11-09 22:08:58 +01:00
parent 432ea03f59
commit 2408f01cc0
2 changed files with 31 additions and 0 deletions

View File

@ -2917,6 +2917,11 @@ static Token * matchMemberVarName(const Member &var, const std::list<ScopeInfo2>
static Token * matchMemberFunctionName(const Member &func, const std::list<ScopeInfo2> &scopeInfo) static Token * matchMemberFunctionName(const Member &func, const std::list<ScopeInfo2> &scopeInfo)
{ {
Token *tok = matchMemberName(func, scopeInfo); Token *tok = matchMemberName(func, scopeInfo);
if (!tok) {
const std::list<std::string> emptyScope;
const Member m2(emptyScope,func.tok);
tok = matchMemberName(m2, scopeInfo);
}
return Token::Match(tok, "~| %name% (") ? tok : nullptr; return Token::Match(tok, "~| %name% (") ? tok : nullptr;
} }

View File

@ -180,6 +180,8 @@ private:
TEST_CASE(varidnamespace1); TEST_CASE(varidnamespace1);
TEST_CASE(varidnamespace2); TEST_CASE(varidnamespace2);
TEST_CASE(usingNamespace1);
TEST_CASE(usingNamespace2);
} }
std::string tokenize(const char code[], bool simplify = false, const char filename[] = "test.cpp") { std::string tokenize(const char code[], bool simplify = false, const char filename[] = "test.cpp") {
@ -2849,6 +2851,30 @@ private:
ASSERT_EQUALS(expected, tokenize(code)); ASSERT_EQUALS(expected, tokenize(code));
} }
void usingNamespace1() {
const char code[] = "namespace NS {\n"
" class A { int x; void dostuff(); };\n"
"}\n"
"using namespace NS;\n"
"void A::dostuff() { x = 0; }\n";
const char expected[] = "1: namespace NS {\n"
"2: class A { int x@1 ; void dostuff ( ) ; } ;\n"
"3: }\n"
"4: using namespace NS ;\n"
"5: void A :: dostuff ( ) { x@1 = 0 ; }\n";
ASSERT_EQUALS(expected, tokenize(code));
}
void usingNamespace2() {
const char code[] = "class A { int x; void dostuff(); };\n"
"using namespace NS;\n"
"void A::dostuff() { x = 0; }\n";
const char expected[] = "1: class A { int x@1 ; void dostuff ( ) ; } ;\n"
"2: using namespace NS ;\n"
"3: void A :: dostuff ( ) { x@1 = 0 ; }\n";
ASSERT_EQUALS(expected, tokenize(code));
}
}; };
REGISTER_TEST(TestVarID) REGISTER_TEST(TestVarID)