parent
27bd972832
commit
f4d18a8d1e
|
@ -4405,10 +4405,12 @@ void Tokenizer::setVarIdClassFunction(const std::string &classname,
|
||||||
std::map<nonneg int, std::map<std::string, nonneg int>>& structMembers,
|
std::map<nonneg int, std::map<std::string, nonneg int>>& structMembers,
|
||||||
nonneg int &varId_)
|
nonneg int &varId_)
|
||||||
{
|
{
|
||||||
|
const auto pos = classname.rfind(' '); // TODO handle multiple scopes
|
||||||
|
const std::string lastScope = classname.substr(pos == std::string::npos ? 0 : pos + 1);
|
||||||
for (Token *tok2 = startToken; tok2 && tok2 != endToken; tok2 = tok2->next()) {
|
for (Token *tok2 = startToken; tok2 && tok2 != endToken; tok2 = tok2->next()) {
|
||||||
if (tok2->varId() != 0 || !tok2->isName())
|
if (tok2->varId() != 0 || !tok2->isName())
|
||||||
continue;
|
continue;
|
||||||
if (Token::Match(tok2->tokAt(-2), ("!!" + classname + " ::").c_str()))
|
if (Token::Match(tok2->tokAt(-2), ("!!" + lastScope + " ::").c_str()))
|
||||||
continue;
|
continue;
|
||||||
if (Token::Match(tok2->tokAt(-4), "%name% :: %name% ::")) // Currently unsupported
|
if (Token::Match(tok2->tokAt(-4), "%name% :: %name% ::")) // Currently unsupported
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -145,6 +145,7 @@ private:
|
||||||
TEST_CASE(varid_namespace_3); // #8627
|
TEST_CASE(varid_namespace_3); // #8627
|
||||||
TEST_CASE(varid_namespace_4);
|
TEST_CASE(varid_namespace_4);
|
||||||
TEST_CASE(varid_namespace_5);
|
TEST_CASE(varid_namespace_5);
|
||||||
|
TEST_CASE(varid_namespace_6);
|
||||||
TEST_CASE(varid_initList);
|
TEST_CASE(varid_initList);
|
||||||
TEST_CASE(varid_initListWithBaseTemplate);
|
TEST_CASE(varid_initListWithBaseTemplate);
|
||||||
TEST_CASE(varid_initListWithScope);
|
TEST_CASE(varid_initListWithScope);
|
||||||
|
@ -2200,6 +2201,29 @@ private:
|
||||||
"9: }\n", tokenize(code, "test.cpp"));
|
"9: }\n", tokenize(code, "test.cpp"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void varid_namespace_6() {
|
||||||
|
const char code[] = "namespace N {\n" // #12077
|
||||||
|
" namespace O {\n"
|
||||||
|
" U::U(int* map) : id(0) {\n"
|
||||||
|
" this->p = map;\n"
|
||||||
|
" }\n"
|
||||||
|
" void U::f() {\n"
|
||||||
|
" std::map<Vec2i, int>::iterator iter;\n"
|
||||||
|
" }\n"
|
||||||
|
" }\n"
|
||||||
|
"}";
|
||||||
|
ASSERT_EQUALS("1: namespace N {\n"
|
||||||
|
"2: namespace O {\n"
|
||||||
|
"3: U :: U ( int * map@1 ) : id ( 0 ) {\n"
|
||||||
|
"4: this . p = map@1 ;\n"
|
||||||
|
"5: }\n"
|
||||||
|
"6: void U :: f ( ) {\n"
|
||||||
|
"7: std :: map < Vec2i , int > :: iterator iter@2 ;\n"
|
||||||
|
"8: }\n"
|
||||||
|
"9: }\n"
|
||||||
|
"10: }\n", tokenize(code, "test.cpp"));
|
||||||
|
}
|
||||||
|
|
||||||
void varid_initList() {
|
void varid_initList() {
|
||||||
const char code1[] = "class A {\n"
|
const char code1[] = "class A {\n"
|
||||||
" A() : x(0) {}\n"
|
" A() : x(0) {}\n"
|
||||||
|
|
Loading…
Reference in New Issue