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:
parent
0b310b9d07
commit
43fb3dd047
|
@ -4377,7 +4377,8 @@ void Tokenizer::setVarIdPass2()
|
|||
Token *tok2 = matchMemberVarName(var, scopeInfo);
|
||||
if (!tok2)
|
||||
continue;
|
||||
tok2->varId(thisClassVars[tok2->str()]);
|
||||
if (tok2->varId() == 0)
|
||||
tok2->varId(thisClassVars[tok2->str()]);
|
||||
}
|
||||
|
||||
if (isC() || tok->str() == "namespace")
|
||||
|
|
|
@ -6876,28 +6876,55 @@ private:
|
|||
}
|
||||
|
||||
void simplifyKnownVariablesNamespace() { // #10059
|
||||
const char code[] = "namespace N {\n"
|
||||
" const int n = 0;\n"
|
||||
" namespace M { const int m = 0; }\n"
|
||||
"}\n"
|
||||
"using namespace N;\n"
|
||||
"int i(n);\n"
|
||||
"int j(M::m);\n"
|
||||
"using namespace N::M;\n"
|
||||
"int k(m);\n"
|
||||
"int l(N::M::m);\n";
|
||||
const char exp[] = "\n\n##file 0\n"
|
||||
"1: namespace N {\n"
|
||||
"2: const int n@1 = 0 ;\n"
|
||||
"3: namespace M { const int m@2 = 0 ; }\n"
|
||||
"4: }\n"
|
||||
"5: using namespace N ;\n"
|
||||
"6: int i ; i = n@1 ;\n"
|
||||
"7: int j ( M :: m@2 ) ;\n"
|
||||
"8: using namespace N :: M ;\n"
|
||||
"9: int k ; k = m@2 ;\n"
|
||||
"10: int l ( N :: M :: m@2 ) ;\n";
|
||||
ASSERT_EQUALS(exp, tokenizeDebugListing(code));
|
||||
{
|
||||
const char code[] = "namespace N {\n"
|
||||
" const int n = 0;\n"
|
||||
" namespace M { const int m = 0; }\n"
|
||||
"}\n"
|
||||
"using namespace N;\n"
|
||||
"int i(n);\n"
|
||||
"int j(M::m);\n"
|
||||
"using namespace N::M;\n"
|
||||
"int k(m);\n"
|
||||
"int l(N::M::m);\n";
|
||||
const char exp[] = "\n\n##file 0\n"
|
||||
"1: namespace N {\n"
|
||||
"2: const int n@1 = 0 ;\n"
|
||||
"3: namespace M { const int m@2 = 0 ; }\n"
|
||||
"4: }\n"
|
||||
"5: using namespace N ;\n"
|
||||
"6: int i ; i = n@1 ;\n"
|
||||
"7: int j ( M :: m@2 ) ;\n"
|
||||
"8: using namespace N :: M ;\n"
|
||||
"9: int k ; k = m@2 ;\n"
|
||||
"10: int l ( N :: M :: m@2 ) ;\n";
|
||||
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() {
|
||||
|
|
Loading…
Reference in New Issue