Commit 209078e5 authored by Przemyslaw Gorszkowski's avatar Przemyslaw Gorszkowski Committed by Orgad Shaneh

C++: fix dereferencing of nested type and operator '*'

Fixed case:
template<class T>
struct List
{
  struct iterator
  {
    T &operator*() { return t; }
    T t;
  };
  iterator begin() { return iterator(); }
};

struct Foo { int bar; };

void func()
{
  List<Foo> list;
  (*list.begin()).; // code completion doesn't work
}

Task-number: QTCREATORBUG-13799
Change-Id: Ia3f5c1631c2f6a25d7fb1186b4ef506354ed22be
Reviewed-by: Orgad Shaneh's avatarOrgad Shaneh <orgads@gmail.com>
Reviewed-by: default avatarNikolai Kosjar <nikolai.kosjar@theqtcompany.com>
parent 25989cbf
......@@ -612,7 +612,7 @@ bool ResolveExpression::visit(UnaryExpressionAST *ast)
added = true;
} else if (namedTy != 0) {
const Name *starOp = control()->operatorNameId(OperatorNameId::StarOp);
if (ClassOrNamespace *b = _context.lookupType(namedTy->name(), p.scope())) {
if (ClassOrNamespace *b = _context.lookupType(namedTy->name(), p.scope(), p.binding())) {
foreach (const LookupItem &r, b->find(starOp)) {
Symbol *overload = r.declaration();
if (Function *funTy = overload->type()->asFunctionType()) {
......
......@@ -2513,6 +2513,26 @@ void CppToolsPlugin::test_completion_data()
) << _("s->") << (QStringList()
<< QLatin1String("Foo")
<< QLatin1String("bar"));
QTest::newRow("dereference_of_nested_type_opertor_*") << _(
"template<typename T>\n"
"struct QList\n"
"{\n"
" struct iterator\n"
" {\n"
" T &operator*() { return t; }\n"
" T t;\n"
" };\n"
" iterator begin() { return iterator(); }\n"
"};\n"
"struct Foo { int bar; };\n"
"void fun() {\n"
" QList<Foo> list;\n"
" @\n"
"}\n"
) << _("(*list.begin()).") << (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