From 07f8c474be629de75780d235df62a50ae6f27870 Mon Sep 17 00:00:00 2001 From: Orgad Shaneh Date: Fri, 22 May 2015 15:39:55 +0300 Subject: [PATCH] C++: Fix decltype resolving for template function The last nail for std::unique_ptr (GCC variant, MSVC still doesn't work). Use-case: template static T f(); struct Foo { int bar; }; void fun() { decltype(f()) s; s.bar; // bar not highlighted } Task-number: QTCREATORBUG-14483 Task-number: QTCREATORBUG-8937 Change-Id: I5bab757400b070cf9dbb688a44fd8eafe95ddc61 Reviewed-by: Nikolai Kosjar --- src/libs/cplusplus/LookupContext.cpp | 2 +- src/plugins/cpptools/cppchecksymbols.cpp | 8 ++------ src/plugins/cpptools/cppcompletion_test.cpp | 15 +++++++++++++++ 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/libs/cplusplus/LookupContext.cpp b/src/libs/cplusplus/LookupContext.cpp index 4468ae96efa..d9e1b59d4f4 100644 --- a/src/libs/cplusplus/LookupContext.cpp +++ b/src/libs/cplusplus/LookupContext.cpp @@ -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, diff --git a/src/plugins/cpptools/cppchecksymbols.cpp b/src/plugins/cpptools/cppchecksymbols.cpp index 860d849e8d2..585c2c16616 100644 --- a/src/plugins/cpptools/cppchecksymbols.cpp +++ b/src/plugins/cpptools/cppchecksymbols.cpp @@ -1300,12 +1300,8 @@ bool CheckSymbols::maybeAddFunction(const QList &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? diff --git a/src/plugins/cpptools/cppcompletion_test.cpp b/src/plugins/cpptools/cppcompletion_test.cpp index e9c35198cb5..00b796f0a85 100644 --- a/src/plugins/cpptools/cppcompletion_test.cpp +++ b/src/plugins/cpptools/cppcompletion_test.cpp @@ -2984,6 +2984,21 @@ void CppToolsPlugin::test_completion_data() ) << _("s.") << (QStringList() << QLatin1String("Foo") << QLatin1String("bar")); + + QTest::newRow("typedefed_decltype_of_template_function") << _( + "template\n" + "static T f();\n" + "\n" + "struct Foo { int bar; };\n" + "\n" + "void fun()\n" + "{\n" + " decltype(f()) s;\n" + " @\n" + "}\n" + ) << _("s.") << (QStringList() + << QLatin1String("Foo") + << QLatin1String("bar")); } void CppToolsPlugin::test_completion_member_access_operator()