@@ -129,6 +129,7 @@ class TestVarID : public TestFixture {
129129 TEST_CASE (varid_in_class21); // #7788
130130 TEST_CASE (varid_namespace_1); // #7272
131131 TEST_CASE (varid_namespace_2); // #7000
132+ TEST_CASE (varid_namespace_3); // #8627
132133 TEST_CASE (varid_initList);
133134 TEST_CASE (varid_initListWithBaseTemplate);
134135 TEST_CASE (varid_initListWithScope);
@@ -1825,6 +1826,41 @@ class TestVarID : public TestFixture {
18251826 ASSERT (actual.find (" X@2 = 0" ) != std::string::npos);
18261827 }
18271828
1829+ std::string getLine (const std::string &code, int lineNumber) {
1830+ std::string nr = MathLib::toString (lineNumber);
1831+ const std::string::size_type pos1 = code.find (' \n ' + nr + " : " );
1832+ if (pos1 == std::string::npos)
1833+ return " " ;
1834+ const std::string::size_type pos2 = code.find (' \n ' , pos1+1 );
1835+ if (pos2 == std::string::npos)
1836+ return " " ;
1837+ return code.substr (pos1+1 , pos2-pos1-1 );
1838+ }
1839+
1840+ void varid_namespace_3 () { // #8627
1841+ const char code[] = " namespace foo {\n "
1842+ " struct Bar {\n "
1843+ " explicit Bar(int type);\n "
1844+ " void f();\n "
1845+ " int type;\n " // <- Same varid here ...
1846+ " };\n "
1847+ " \n "
1848+ " Bar::Bar(int type) : type(type) {}\n "
1849+ " \n "
1850+ " void Bar::f() {\n "
1851+ " type = 0;\n " // <- ... and here
1852+ " }\n "
1853+ " }" ;
1854+
1855+ const std::string actual = tokenize (code, false , " test.cpp" );
1856+
1857+ const std::string line5 = getLine (actual, 5 );
1858+ const std::string line11 = getLine (actual, 11 );
1859+
1860+ ASSERT_EQUALS (" 5: int type@2 ;" , getLine (actual,5 ));
1861+ ASSERT_EQUALS (" 11: type@2 = 0 ;" , getLine (actual,11 ));
1862+ }
1863+
18281864 void varid_initList () {
18291865 const char code1[] = " class A {\n "
18301866 " A() : x(0) {}\n "
0 commit comments