diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 033462ca2e2..eabdb2e7d28 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -5165,8 +5165,10 @@ static Token * matchMemberName(const std::list &scope, const Token // Current scope.. for (auto it = scope.cbegin(); it != scope.cend(); ++it) { - if (scopeIt == scopeInfo.cend() || scopeIt->name != *it) - return nullptr; + if (scopeIt == scopeInfo.cend() || scopeIt->name != *it) { + scopeIt = scopeInfo.cbegin(); + break; + } ++scopeIt; } diff --git a/test/testvarid.cpp b/test/testvarid.cpp index c8d16bc89a5..e30c613c0bc 100644 --- a/test/testvarid.cpp +++ b/test/testvarid.cpp @@ -102,6 +102,7 @@ class TestVarID : public TestFixture { TEST_CASE(varid70); // #12660 - function TEST_CASE(varid71); // #12676 - wrong varid in uninstantiated templated constructor TEST_CASE(varid72); + TEST_CASE(varid73); TEST_CASE(varid_for_1); TEST_CASE(varid_for_2); TEST_CASE(varid_for_3); @@ -1409,6 +1410,14 @@ class TestVarID : public TestFixture { ASSERT_EQUALS(expected1, tokenize(code1)); } + void varid73() { + const char code[] = "namespace a { int x; };\n" + "namespace b { int x = a::x; };\n"; + const char expected[] = "1: namespace a { int x@1 ; } ;\n" + "2: namespace b { int x@2 ; x@2 = a :: x@1 ; } ;\n"; + ASSERT_EQUALS(expected, tokenize(code)); + } + void varid_for_1() { const char code[] = "void foo(int a, int b) {\n" " for (int a=1,b=2;;) {}\n"