diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 113d68e8b66d..c4973de403d8 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -5171,8 +5171,11 @@ void Tokenizer::setVarIdPass2() tok2 = tok2->link(); // Skip initialization list - if (Token::simpleMatch(tok2, ") :")) + if (Token::simpleMatch(tok2, ") :")) { tok2 = skipInitializerList(tok2->next()); + //if (Token::simpleMatch(tok2, "{")) + // tok2 = tok2->link(); + } } } diff --git a/test/testvarid.cpp b/test/testvarid.cpp index 47a782475b02..eb280d0240b2 100644 --- a/test/testvarid.cpp +++ b/test/testvarid.cpp @@ -102,6 +102,7 @@ class TestVarID : public TestFixture { TEST_CASE(varid68); // #11740 - switch (str_chars(&strOut)[0]) TEST_CASE(varid69); TEST_CASE(varid70); // #12660 - function + TEST_CASE(varid71); // #12676 - wrong varid in uninstantiated templated constructor TEST_CASE(varid_for_1); TEST_CASE(varid_for_2); TEST_CASE(varid_cpp_keywords_in_c_code); @@ -1294,6 +1295,72 @@ class TestVarID : public TestFixture { ASSERT_EQUALS(expected3, tokenize(code3, true)); } + void varid71() { + const char code[] = "namespace myspace {\n" + "\n" + "template \n" + "class CounterTest {\n" + "public:\n" + " CounterTest(T _obj);\n" + " template \n" + " CounterTest(const CounterTest& ptr);\n" + " T obj;\n" + " int count;\n" + "};\n" + "\n" + "template \n" + "CounterTest::CounterTest(T _obj) : obj(_obj) {\n" + " count = 0;\n" + "}\n" + "\n" + "template \n" + "template \n" + "CounterTest::CounterTest(const CounterTest& p) : obj(0) {\n" + " count = p.count;\n" + "}\n" + "\n" + "}\n" + "\n" + "using namespace myspace;\n" + "CounterTest myobj(0);\n"; + const char expected[] = "1: namespace myspace {\n" + "2:\n" + "3: class CounterTest ;\n" + "4:\n" + "|\n" + "17:\n" + "18: template < typename T >\n" + "19: template < typename T2 >\n" + "20: CounterTest < T > :: CounterTest ( const CounterTest < T2 > & p@1 ) : obj ( 0 ) {\n" + "21: count = p@1 . count@2 ;\n" + "22: }\n" + "23:\n" + "24: }\n" + "25:\n" + "26: using namespace myspace ;\n" + "27: myspace :: CounterTest myobj@3 ( 0 ) ;\n" + "4: class myspace :: CounterTest {\n" + "5: public:\n" + "6: CounterTest ( int _obj@4 ) ;\n" + "7: template < typename T2 >\n" + "8: CounterTest ( const myspace :: CounterTest < T2 > & ptr@5 ) ;\n" + "9: int obj@6 ;\n" + "10: int count@7 ;\n" + "11: } ;\n" + "12:\n" + "13:\n" + "14: myspace :: CounterTest :: CounterTest ( int _obj@8 ) : obj@6 ( _obj@8 ) {\n" + "15: count@2 = 0 ;\n" + "16: }\n" + "17:\n" + "18:\n" + "19:\n" + "20: myspace :: CounterTest :: CounterTest ( const myspace :: CounterTest < T2 > & p@9 ) : obj@6 ( 0 ) {\n" + "21: count@2 = p@9 . count@10 ;\n" + "22: }\n"; + ASSERT_EQUALS(expected, tokenize(code, true)); + } + void varid_for_1() { const char code[] = "void foo(int a, int b) {\n" " for (int a=1,b=2;;) {}\n" diff --git a/tools/defines/float.c b/tools/defines/float.c index 1d53f8185101..318874147404 100644 --- a/tools/defines/float.c +++ b/tools/defines/float.c @@ -2,7 +2,7 @@ #include "stdio.h" #define PRINT_DEF(d, f) \ - fprintf(stdout, ";"#d"=%"#f, d) + fprintf(stdout, ";"#d "=%"#f, d) int main(void) { diff --git a/tools/defines/limits.c b/tools/defines/limits.c index 8f2d9c90a7d4..0407aefac22c 100644 --- a/tools/defines/limits.c +++ b/tools/defines/limits.c @@ -2,7 +2,7 @@ #include "stdio.h" #define PRINT_DEF(d, f) \ - fprintf(stdout, ";"#d"=%"#f, d) + fprintf(stdout, ";"#d "=%"#f, d) int main(void) { diff --git a/tools/defines/stdint.c b/tools/defines/stdint.c index bd899140de25..72fc6c6ead81 100644 --- a/tools/defines/stdint.c +++ b/tools/defines/stdint.c @@ -2,7 +2,7 @@ #include "stdio.h" #define PRINT_DEF(d, f) \ - fprintf(stdout, ";"#d"=%"#f, d) + fprintf(stdout, ";"#d "=%"#f, d) #define PRINT_DEF_N(d1, d2, f) \ do { \ @@ -40,5 +40,5 @@ int main(void) PRINT_DEF(WINT_MIN, d); PRINT_DEF(WINT_MAX, d); - return 0; + return 0; }