diff --git a/lib/templatesimplifier.cpp b/lib/templatesimplifier.cpp index 0f1e8c809..14fe48163 100644 --- a/lib/templatesimplifier.cpp +++ b/lib/templatesimplifier.cpp @@ -850,7 +850,13 @@ void TemplateSimplifier::getTemplateInstantiations() // look for function instantiation with type deduction // fixme: only single argument functions supported if (tok->strAt(1) == "(") { - std::string fullName = qualification + (qualification.empty() ? "" : " :: ") + tok->str(); + std::string fullName; + if (!qualification.empty()) + fullName = qualification + " :: " + tok->str(); + else if (!scopeName.empty()) + fullName = scopeName + " :: " + tok->str(); + else + fullName = tok->str(); // get all declarations with this name for (auto pos = functionNameMap.lower_bound(tok->str()); pos != functionNameMap.upper_bound(tok->str()); ++pos) { diff --git a/test/testsimplifytemplate.cpp b/test/testsimplifytemplate.cpp index d84211abc..17b8caa94 100644 --- a/test/testsimplifytemplate.cpp +++ b/test/testsimplifytemplate.cpp @@ -247,6 +247,7 @@ private: TEST_CASE(templateTypeDeduction1); // #8962 TEST_CASE(templateTypeDeduction2); + TEST_CASE(templateTypeDeduction3); TEST_CASE(simplifyTemplateArgs1); TEST_CASE(simplifyTemplateArgs2); @@ -5258,6 +5259,28 @@ private: TODO_ASSERT_EQUALS(expected, actual, tok(code)); } + void templateTypeDeduction3() { // #9975 + const char code[] = "struct A {\n" + " int a = 1;\n" + " void f() { g(1); }\n" + " template void g(T x) { a = 2; }\n" + "};\n" + "int main() {\n" + " A a;\n" + " a.f();\n" + "}"; + const char exp[] = "struct A { " + "int a ; a = 1 ; " + "void f ( ) { g ( 1 ) ; } " + "void g ( int x ) ; " + "} ; " + "int main ( ) { " + "A a ; " + "a . f ( ) ; " + "} void A :: g ( int x ) { a = 2 ; }"; + ASSERT_EQUALS(exp, tok(code)); + } + void simplifyTemplateArgs1() { ASSERT_EQUALS("foo<2> = 2 ; foo<2> ;", tok("template foo = N; foo < ( 2 ) >;")); ASSERT_EQUALS("foo<2> = 2 ; foo<2> ;", tok("template foo = N; foo < 1 + 1 >;"));