forked from qt-creator/qt-creator
C++: Fix auto variable resolving for template class constructor call
Code snippet:
template<class T> struct MyStruct { int value; };
int main() {
auto s = MyStruct<int>();
s.value; // "value" is not found
}
This fixes find usages for unique_ptr declared as auto like this:
auto ptr = std::unique_ptr<MyStruct>(new MyStruct());
ptr->value;
Also fixes in-place constructors:
std::unique_ptr<MyStruct>(new MyStruct())->value;
Fixes: QTCREATORBUG-15364
Change-Id: I8d452a77fe85e63665ec8d4c4afbcf8aad063121
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
@@ -818,6 +818,10 @@ void CreateBindings::lookupInScope(const Name *name, Scope *scope,
|
||||
if (Symbol *inst = instantiateTemplateFunction(name, s->asTemplate()))
|
||||
item.setType(inst->type());
|
||||
|
||||
if (Template *templ = s->asTemplate())
|
||||
if (templ->declaration() && templ->declaration()->asClass())
|
||||
item.setType(control()->namedType(name));
|
||||
|
||||
result->append(item);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -880,12 +880,18 @@ bool ResolveExpression::visit(CallAST *ast)
|
||||
|
||||
if (NamedType *namedTy = ty->asNamedType()) {
|
||||
if (ClassOrNamespace *b = _context.lookupType(namedTy->name(), scope)) {
|
||||
foreach (const LookupItem &r, b->find(functionCallOp)) {
|
||||
Symbol *overload = r.declaration();
|
||||
if (Function *funTy = overload->type()->asFunctionType()) {
|
||||
if (maybeValidPrototype(funTy, actualArgumentCount)) {
|
||||
if (Function *proto = instantiate(namedTy->name(), funTy)->asFunctionType())
|
||||
addResult(proto->returnType().simplified(), scope);
|
||||
if (b->templateId() && result.declaration() && result.declaration()->asTemplate()) {
|
||||
// Template class constructor
|
||||
addResult(ty.simplified(), scope);
|
||||
} else {
|
||||
// operator()
|
||||
foreach (const LookupItem &r, b->find(functionCallOp)) {
|
||||
Symbol *overload = r.declaration();
|
||||
if (Function *funTy = overload->type()->asFunctionType()) {
|
||||
if (maybeValidPrototype(funTy, actualArgumentCount)) {
|
||||
if (Function *proto = instantiate(namedTy->name(), funTy)->asFunctionType())
|
||||
addResult(proto->returnType().simplified(), scope);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user