Fix regression: wrong varid with using namespace (#3866)

* Fix #10059 missing varId with using namespace

* Undo

* Fix test

* Limit namespace candidates, duplicateBranch

* rvalue ref

* Undo

* Undo

* Undo

* Format

* Fix condition

* Fix regression: wrong varid with using namespace
This commit is contained in:
chrchr-github 2022-03-02 07:46:04 +01:00 committed by GitHub
parent 0b310b9d07
commit 43fb3dd047
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 51 additions and 23 deletions

View File

@ -4377,6 +4377,7 @@ void Tokenizer::setVarIdPass2()
Token *tok2 = matchMemberVarName(var, scopeInfo);
if (!tok2)
continue;
if (tok2->varId() == 0)
tok2->varId(thisClassVars[tok2->str()]);
}

View File

@ -6876,6 +6876,7 @@ private:
}
void simplifyKnownVariablesNamespace() { // #10059
{
const char code[] = "namespace N {\n"
" const int n = 0;\n"
" namespace M { const int m = 0; }\n"
@ -6900,6 +6901,32 @@ private:
ASSERT_EQUALS(exp, tokenizeDebugListing(code));
}
{
const char code[] = "struct S {\n"
" S() { f(); }\n"
" void f();\n"
" int i;\n"
"};\n"
"namespace N { int j; }\n"
"using namespace N;\n"
"void S::f() {\n"
" i = 0;\n"
"}\n";
const char exp[] = "\n\n##file 0\n"
"1: struct S {\n"
"2: S ( ) { f ( ) ; }\n"
"3: void f ( ) ;\n"
"4: int i@1 ;\n"
"5: } ;\n"
"6: namespace N { int j@2 ; }\n"
"7: using namespace N ;\n"
"8: void S :: f ( ) {\n"
"9: i@1 = 0 ;\n"
"10: }\n";
ASSERT_EQUALS(exp, tokenizeDebugListing(code));
}
}
void simplifyKnownVariablesClassMember() {
// Ticket #2815
{