C++: Fix lookup for instantiation by class object

Task-number: QTCREATORBUG-14352
Change-Id: I2ce4bc1d0dba2414afe050e80607b581686081a9
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@theqtcompany.com>
This commit is contained in:
Orgad Shaneh
2015-04-24 09:55:20 +03:00
committed by Orgad Shaneh
parent ee37f60bff
commit 9b30795c02
10 changed files with 99 additions and 81 deletions

View File

@@ -332,7 +332,6 @@ void CppToolsPlugin::test_completion()
QEXPECT_FAIL("enum_in_function_in_struct_in_function_anon", "QTCREATORBUG-13757", Abort);
QEXPECT_FAIL("enum_in_class_accessed_in_member_func_cxx11", "QTCREATORBUG-13757", Abort);
QEXPECT_FAIL("enum_in_class_accessed_in_member_func_inline_cxx11", "QTCREATORBUG-13757", Abort);
QEXPECT_FAIL("pointer_indirect_specialization_double_indirection", "QTCREATORBUG-14141", Abort);
QEXPECT_FAIL("pointer_indirect_specialization_double_indirection_with_base", "QTCREATORBUG-14141", Abort);
QEXPECT_FAIL("recursive_instantiation_of_template_type", "QTCREATORBUG-14237", Abort);
QCOMPARE(actualCompletions, expectedCompletions);
@@ -2830,6 +2829,28 @@ void CppToolsPlugin::test_completion_data()
<< QLatin1String("Foo")
<< QLatin1String("bar"));
QTest::newRow("instantiation_of_indirect_typedef") << _(
"template<typename _Tp>\n"
"struct Indirect { _Tp t; };\n"
"\n"
"template<typename T>\n"
"struct Temp\n"
"{\n"
" typedef T MyT;\n"
" typedef Indirect<MyT> indirect;\n"
"};\n"
"\n"
"struct Foo { int bar; };\n"
"\n"
"void func()\n"
"{\n"
" Temp<Foo>::indirect i;\n"
" @\n"
"}\n"
) << _("i.t.") << (QStringList()
<< QLatin1String("Foo")
<< QLatin1String("bar"));;
QTest::newRow("pointer_indirect_specialization_double_indirection_with_base") << _(
"template<typename _Tp>\n"
"struct Traits { };\n"

View File

@@ -212,13 +212,15 @@ Function *SymbolFinder::findMatchingDefinition(Symbol *declaration,
return 0;
}
Class *SymbolFinder::findMatchingClassDeclaration(Symbol *declaration, const Snapshot &snapshot)
Class *SymbolFinder::findMatchingClassDeclaration(Symbol *declaration, const Snapshot &snapshot,
const LookupContext *context)
{
if (!declaration->identifier())
return 0;
QString declFile = QString::fromUtf8(declaration->fileName(), declaration->fileNameLength());
const bool useLocalContext = !context;
foreach (const QString &file, fileIterationOrder(declFile, snapshot)) {
Document::Ptr doc = snapshot.document(file);
if (!doc) {
@@ -230,9 +232,13 @@ Class *SymbolFinder::findMatchingClassDeclaration(Symbol *declaration, const Sna
declaration->identifier()->size()))
continue;
LookupContext context(doc, snapshot);
QScopedPointer<LookupContext> localContext;
if (useLocalContext) {
localContext.reset(new LookupContext(doc, snapshot));
context = localContext.data();
}
LookupScope *type = context.lookupType(declaration);
LookupScope *type = context->lookupType(declaration);
if (!type)
continue;

View File

@@ -59,7 +59,8 @@ public:
bool strict = false);
CPlusPlus::Class *findMatchingClassDeclaration(CPlusPlus::Symbol *declaration,
const CPlusPlus::Snapshot &snapshot);
const CPlusPlus::Snapshot &snapshot,
const CPlusPlus::LookupContext *context = 0);
void findMatchingDeclaration(const CPlusPlus::LookupContext &context,
CPlusPlus::Function *functionType,