Commit faca3333 authored by Przemyslaw Gorszkowski's avatar Przemyslaw Gorszkowski
Browse files

C++: fix typedef resolving



Fix a case:
struct A
{
  int a;
};

typedef A B;
typedef B* Bptr;
Bptr b;
b->

Task-number: QTCREATORBUG-10021
Change-Id: Ibf5ca801dbdb72744416924c0b8fc03daad5948a
Reviewed-by: default avatarNikolai Kosjar <nikolai.kosjar@digia.com>
parent c79413a4
......@@ -981,7 +981,18 @@ private:
visited.insert(declaration);
// continue working with the typedefed type and scope
*type = declaration->type();
if (type->type()->isPointerType()) {
*type = FullySpecifiedType(
_context.bindings()->control()->pointerType(declaration->type()));
} else if (type->type()->isReferenceType()) {
*type = FullySpecifiedType(
_context.bindings()->control()->referenceType(
declaration->type(),
declaration->type()->asReferenceType()->isRvalueReference()));
} else {
*type = declaration->type();
}
*scope = it.scope();
_binding = it.binding();
foundTypedef = true;
......@@ -1039,20 +1050,7 @@ ClassOrNamespace *ResolveExpression::baseExpression(const QList<LookupItem> &bas
#endif // DEBUG_LOOKUP
if (accessOp == T_ARROW) {
if (PointerType *ptrTy = originalType->asPointerType()) {
FullySpecifiedType type = ptrTy->elementType();
if (! ty->isPointerType())
type = ty;
if (ClassOrNamespace *binding
= findClassForTemplateParameterInExpressionScope(r.binding(),
type)) {
return binding;
}
if (ClassOrNamespace *binding = findClass(type, scope))
return binding;
} else if (PointerType *ptrTy = ty->asPointerType()) {
if (PointerType *ptrTy = ty->asPointerType()) {
FullySpecifiedType type = ptrTy->elementType();
if (ClassOrNamespace *binding
= findClassForTemplateParameterInExpressionScope(r.binding(),
......@@ -1122,12 +1120,9 @@ ClassOrNamespace *ResolveExpression::baseExpression(const QList<LookupItem> &bas
}
} else if (accessOp == T_DOT) {
if (replacedDotOperator) {
if (! isTypeTypedefed(originalType, ty)
|| ! areOriginalAndTypedefedTypePointer(originalType, ty)) {
*replacedDotOperator = originalType->isPointerType() || ty->isPointerType();
if (PointerType *ptrTy = ty->asPointerType())
ty = ptrTy->elementType();
}
*replacedDotOperator = originalType->isPointerType() || ty->isPointerType();
if (PointerType *ptrTy = ty->asPointerType())
ty = ptrTy->elementType();
}
if (ClassOrNamespace *binding
......
......@@ -2355,4 +2355,28 @@ void CppToolsPlugin::test_completion_member_access_operator_data()
<< QLatin1String("S")
<< QLatin1String("m"))
<< true;
QTest::newRow("typedef_of_pointer_of_type_replace_access_operator") << _(
"struct S { int m; };\n"
"typedef struct S SType;\n"
"typedef struct SType *STypePtr;\n"
"STypePtr p;\n"
"@\n"
"}\n"
) << _("p.") << (QStringList()
<< QLatin1String("S")
<< QLatin1String("m"))
<< true;
QTest::newRow("typedef_of_pointer_of_type_no_replace_access_operator") << _(
"struct S { int m; };\n"
"typedef struct S SType;\n"
"typedef struct SType *STypePtr;\n"
"STypePtr p;\n"
"@\n"
"}\n"
) << _("p->") << (QStringList()
<< QLatin1String("S")
<< QLatin1String("m"))
<< false;
}
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