Commit 07f8c474 authored by Orgad Shaneh's avatar Orgad Shaneh Committed by Orgad Shaneh

C++: Fix decltype resolving for template function

The last nail for std::unique_ptr (GCC variant, MSVC still doesn't work).

Use-case:
template<typename T>
static T f();

struct Foo { int bar; };

void fun()
{
    decltype(f<Foo>()) s;
    s.bar; // bar not highlighted
}

Task-number: QTCREATORBUG-14483
Task-number: QTCREATORBUG-8937
Change-Id: I5bab757400b070cf9dbb688a44fd8eafe95ddc61
Reviewed-by: default avatarNikolai Kosjar <nikolai.kosjar@theqtcompany.com>
parent a429ef3d
......@@ -967,7 +967,7 @@ void CreateBindings::lookupInScope(const Name *name, Scope *scope,
if (const TemplateNameId *instantiation = name->asTemplateNameId()) {
if (Template *specialization = s->asTemplate()) {
if (const Symbol *decl = specialization->declaration()) {
if (decl->isFunction()) {
if (decl->isFunction() || decl->isDeclaration()) {
Clone cloner(_control.data());
Subst subst(_control.data());
initializeSubst(cloner, subst, binding, scope,
......
......@@ -1300,12 +1300,8 @@ bool CheckSymbols::maybeAddFunction(const QList<LookupItem> &candidates, NameAST
isConstructor = isConstructorDeclaration(c);
Function *funTy = c->type()->asFunctionType();
if (!funTy) {
//Try to find a template function
if (Template * t = r.type()->asTemplateType())
if ((c = t->declaration()))
funTy = c->type()->asFunctionType();
}
if (!funTy) // Template function has an overridden type
funTy = r.type()->asFunctionType();
if (!funTy)
continue; // TODO: add diagnostic messages and color call-operators calls too?
......
......@@ -2984,6 +2984,21 @@ void CppToolsPlugin::test_completion_data()
) << _("s.") << (QStringList()
<< QLatin1String("Foo")
<< QLatin1String("bar"));
QTest::newRow("typedefed_decltype_of_template_function") << _(
"template<typename T>\n"
"static T f();\n"
"\n"
"struct Foo { int bar; };\n"
"\n"
"void fun()\n"
"{\n"
" decltype(f<Foo>()) s;\n"
" @\n"
"}\n"
) << _("s.") << (QStringList()
<< QLatin1String("Foo")
<< QLatin1String("bar"));
}
void CppToolsPlugin::test_completion_member_access_operator()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment