mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Bug 357320: Class template usage in method definded outside of class body.
This commit is contained in:
parent
6f21f0999c
commit
b9e57bcf8c
2 changed files with 40 additions and 27 deletions
|
@ -1897,4 +1897,15 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa
|
||||||
getBindingFromASTName("f(2,1)", 1, ICPPMethod.class);
|
getBindingFromASTName("f(2,1)", 1, ICPPMethod.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// template<class T> struct C1 {
|
||||||
|
// typedef int iterator;
|
||||||
|
// iterator m1();
|
||||||
|
// };
|
||||||
|
|
||||||
|
// template<class T> typename C1<T>::iterator C1<T>::m1() {
|
||||||
|
// return 0;
|
||||||
|
// }
|
||||||
|
public void testUsageOfClassTemplateOutsideOfClassBody_357320() throws Exception {
|
||||||
|
getBindingFromASTName("m1", 0, ICPPMethod.class);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,6 @@ import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.dom.IName;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.ASTTypeUtil;
|
import org.eclipse.cdt.core.dom.ast.ASTTypeUtil;
|
||||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
||||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||||
|
@ -255,41 +254,44 @@ public class CPPTemplates {
|
||||||
|
|
||||||
static IBinding isUsedInClassTemplateScope(ICPPClassTemplate ct, IASTName name) {
|
static IBinding isUsedInClassTemplateScope(ICPPClassTemplate ct, IASTName name) {
|
||||||
try {
|
try {
|
||||||
IASTName start= name;
|
IScope scope;
|
||||||
ICPPASTFunctionDefinition func= CPPVisitor.findEnclosingFunctionDefinition(name);
|
ICPPASTFunctionDefinition func= CPPVisitor.findEnclosingFunctionDefinition(name);
|
||||||
if (func != null) {
|
if (func != null) {
|
||||||
start= ASTQueries.findInnermostDeclarator(func.getDeclarator()).getName();
|
name= ASTQueries.findInnermostDeclarator(func.getDeclarator()).getName().getLastName();
|
||||||
start= start.getLastName();
|
scope= CPPVisitor.getContainingScope(name);
|
||||||
|
} else {
|
||||||
|
scope= CPPVisitor.getContainingScope(name);
|
||||||
|
if (!(scope instanceof IASTInternalScope))
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
IScope scope= CPPVisitor.getContainingScope(start);
|
while (scope != null) {
|
||||||
while (scope instanceof IASTInternalScope) {
|
|
||||||
if (scope instanceof ISemanticProblem)
|
if (scope instanceof ISemanticProblem)
|
||||||
return null;
|
return null;
|
||||||
final IASTInternalScope internalScope = (IASTInternalScope) scope;
|
|
||||||
if (scope instanceof ICPPClassScope) {
|
if (scope instanceof ICPPClassScope) {
|
||||||
final IName scopeName = internalScope.getScopeName();
|
ICPPClassType b= ((ICPPClassScope) scope).getClassType();
|
||||||
if (scopeName instanceof IASTName) {
|
if (b != null && ct.isSameType(b)) {
|
||||||
IBinding b= ((IASTName) scopeName).resolveBinding();
|
return CPPTemplates.instantiateWithinClassTemplate(ct);
|
||||||
if (b instanceof IType && ct.isSameType((IType) b)) {
|
}
|
||||||
return CPPTemplates.instantiateWithinClassTemplate(ct);
|
if (b instanceof ICPPClassTemplatePartialSpecialization) {
|
||||||
}
|
ICPPClassTemplatePartialSpecialization pspec= (ICPPClassTemplatePartialSpecialization) b;
|
||||||
if (b instanceof ICPPClassTemplatePartialSpecialization) {
|
if (ct.isSameType(pspec.getPrimaryClassTemplate())) {
|
||||||
ICPPClassTemplatePartialSpecialization pspec= (ICPPClassTemplatePartialSpecialization) b;
|
return CPPTemplates.instantiateWithinClassTemplate(pspec);
|
||||||
if (ct.isSameType(pspec.getPrimaryClassTemplate())) {
|
|
||||||
return CPPTemplates.instantiateWithinClassTemplate(pspec);
|
|
||||||
}
|
|
||||||
} else if (b instanceof ICPPClassSpecialization) {
|
|
||||||
ICPPClassSpecialization specialization= (ICPPClassSpecialization) b;
|
|
||||||
if (ct.isSameType(specialization.getSpecializedBinding())) {
|
|
||||||
return specialization;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
} else if (b instanceof ICPPClassSpecialization) {
|
||||||
|
ICPPClassSpecialization specialization= (ICPPClassSpecialization) b;
|
||||||
|
if (ct.isSameType(specialization.getSpecializedBinding())) {
|
||||||
|
return specialization; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
scope= CPPVisitor.getContainingScope(internalScope.getPhysicalNode());
|
if (scope instanceof IASTInternalScope) {
|
||||||
if (scope == internalScope)
|
IASTInternalScope internalScope= (IASTInternalScope) scope;
|
||||||
return null;
|
scope= CPPVisitor.getContainingScope(internalScope.getPhysicalNode());
|
||||||
|
if (scope == internalScope)
|
||||||
|
return null;
|
||||||
|
} else {
|
||||||
|
scope= scope.getParent();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (DOMException e) {
|
} catch (DOMException e) {
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue