forked from qt-creator/qt-creator
C++: use pointer in template specialization and initialization
Fix code completion for using pointer in template specialization and initialization. Example: template <typename T> struct S {}; template <typename T> struct S<T*> { T* t; }; struct Foo { int foo; }; int main() { S<Foo*> s; s.t-> //no code completion return 0; } Task-number: QTCREATORBUG-12638 Change-Id: Idcd461806a22f08b76236f2db6346f157b12f5d3 Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
@@ -1084,6 +1084,10 @@ ClassOrNamespace *ClassOrNamespace::nestedType(const Name *name, ClassOrNamespac
|
||||
|
||||
Subst subst(_control.data());
|
||||
if (_factory->expandTemplates()) {
|
||||
const TemplateNameId *templSpecId
|
||||
= templateSpecialization->name()->asTemplateNameId();
|
||||
const unsigned templSpecArgumentCount = templSpecId ?
|
||||
templSpecId->templateArgumentCount() : 0;
|
||||
Clone cloner(_control.data());
|
||||
for (unsigned i = 0; i < argumentCountOfSpecialization; ++i) {
|
||||
const TypenameArgument *tParam
|
||||
@@ -1098,6 +1102,12 @@ ClassOrNamespace *ClassOrNamespace::nestedType(const Name *name, ClassOrNamespac
|
||||
templId->templateArgumentAt(i):
|
||||
cloner.type(tParam->type(), &subst);
|
||||
|
||||
if (i < templSpecArgumentCount
|
||||
&& templSpecId->templateArgumentAt(i)->isPointerType()) {
|
||||
if (PointerType *pointerType = ty->asPointerType())
|
||||
ty = pointerType->elementType();
|
||||
}
|
||||
|
||||
subst.bind(cloner.name(name, &subst), ty);
|
||||
}
|
||||
|
||||
|
@@ -2295,6 +2295,35 @@ void CppToolsPlugin::test_completion_data()
|
||||
) << _("derived.t.") << (QStringList()
|
||||
<< QLatin1String("foo")
|
||||
<< QLatin1String("Foo"));
|
||||
|
||||
QTest::newRow("template_specialization_and_initialization_with_pointer1") << _(
|
||||
"template <typename T>\n"
|
||||
"struct S {};\n"
|
||||
"template <typename T>\n"
|
||||
"struct S<T*> { T *t; };\n"
|
||||
"struct Foo { int foo; };\n"
|
||||
"void fun() {\n"
|
||||
" S<Foo*> s;\n"
|
||||
" @\n"
|
||||
"}\n"
|
||||
) << _("s.t->") << (QStringList()
|
||||
<< QLatin1String("foo")
|
||||
<< QLatin1String("Foo"));
|
||||
|
||||
// this is not a valid code(is not compile) but it caused a crash
|
||||
QTest::newRow("template_specialization_and_initialization_with_pointer2") << _(
|
||||
"template <typename T1, typename T2 = int>\n"
|
||||
"struct S {};\n"
|
||||
"template <typename T1, typename T2>\n"
|
||||
"struct S<T1*> { T1 *t; };\n"
|
||||
"struct Foo { int foo; };\n"
|
||||
"void fun() {\n"
|
||||
" S<Foo*> s;\n"
|
||||
" @\n"
|
||||
"}\n"
|
||||
) << _("s.t->") << (QStringList()
|
||||
<< QLatin1String("foo")
|
||||
<< QLatin1String("Foo"));
|
||||
}
|
||||
|
||||
void CppToolsPlugin::test_completion_member_access_operator()
|
||||
|
Reference in New Issue
Block a user