From 059cfde67737fb1d0d1a4c46ee62a387a07ca0b4 Mon Sep 17 00:00:00 2001 From: Przemyslaw Gorszkowski Date: Thu, 3 Jul 2014 13:53:22 +0200 Subject: [PATCH] C++: template base class and default argument for template class Fix code completion for case: struct Foo { int bar; }; template struct Base { T t; }; template struct Derived : Base {}; int main() { Derived<> foo; foo.t.// no code completion return 0; } Task-number: QTCREATORBUG-12606 Change-Id: Iadf2fae172739d0a5844c6b437fd2686616e64e7 Reviewed-by: Erik Verbruggen --- src/libs/cplusplus/LookupContext.cpp | 12 +++++++----- src/plugins/cpptools/cppcompletion_test.cpp | 14 ++++++++++++++ 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/libs/cplusplus/LookupContext.cpp b/src/libs/cplusplus/LookupContext.cpp index aae1b25ff10..c90fdb005d7 100644 --- a/src/libs/cplusplus/LookupContext.cpp +++ b/src/libs/cplusplus/LookupContext.cpp @@ -1158,11 +1158,13 @@ ClassOrNamespace *ClassOrNamespace::nestedType(const Name *name, ClassOrNamespac } } else { SubstitutionMap map; - for (unsigned i = 0; - i < argumentCountOfSpecialization && i < argumentCountOfInitialization; - ++i) { - map.bind(templateSpecialization->templateParameterAt(i)->name(), - templId->templateArgumentAt(i)); + for (unsigned i = 0; i < argumentCountOfSpecialization; ++i) { + const Name *name = templateSpecialization->templateParameterAt(i)->name(); + FullySpecifiedType ty = (i < argumentCountOfInitialization) ? + templId->templateArgumentAt(i): + templateSpecialization->templateParameterAt(i)->type(); + + map.bind(name, ty); } SubstitutionEnvironment env; env.enter(&map); diff --git a/src/plugins/cpptools/cppcompletion_test.cpp b/src/plugins/cpptools/cppcompletion_test.cpp index a55968da4a9..e50a2a01b2d 100644 --- a/src/plugins/cpptools/cppcompletion_test.cpp +++ b/src/plugins/cpptools/cppcompletion_test.cpp @@ -2281,6 +2281,20 @@ void CppToolsPlugin::test_completion_data() << QLatin1String("Derived") << QLatin1String("foo") << QLatin1String("Foo")); + + QTest::newRow("default_arguments_for_class_templates_and_template_base_class_QTCREATORBUG-12606") << _( + "struct Foo { int foo; };\n" + "template \n" + "struct Base { T t; };\n" + "template \n" + "struct Derived : Base {};\n" + "void fun() {\n" + " Derived<> derived;\n" + " @\n" + "}\n" + ) << _("derived.t.") << (QStringList() + << QLatin1String("foo") + << QLatin1String("Foo")); } void CppToolsPlugin::test_completion_member_access_operator()