Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarkus Schorn2011-09-16 10:44:46 +0000
committerMarkus Schorn2011-09-16 10:45:28 +0000
commitb9e57bcf8c1aa970a02e72c7dc9d566de6854ee1 (patch)
treea9dc97ca086dd280e2c80a016c8a2332ead02bfb
parent6f21f0999c51ae247aef0f0979c9fd2a522946dc (diff)
downloadorg.eclipse.cdt-b9e57bcf8c1aa970a02e72c7dc9d566de6854ee1.tar.gz
org.eclipse.cdt-b9e57bcf8c1aa970a02e72c7dc9d566de6854ee1.tar.xz
org.eclipse.cdt-b9e57bcf8c1aa970a02e72c7dc9d566de6854ee1.zip
Bug 357320: Class template usage in method definded outside of class body.
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPTemplateResolutionTest.java11
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPTemplates.java56
2 files changed, 40 insertions, 27 deletions
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPTemplateResolutionTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPTemplateResolutionTest.java
index 727c98a3ed..93f1cf2edd 100644
--- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPTemplateResolutionTest.java
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPTemplateResolutionTest.java
@@ -1897,4 +1897,15 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa
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);
+ }
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPTemplates.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPTemplates.java
index fe1e8b40d4..fd0d47050d 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPTemplates.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPTemplates.java
@@ -19,7 +19,6 @@ import java.util.ArrayList;
import java.util.Collections;
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.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.DOMException;
@@ -255,41 +254,44 @@ public class CPPTemplates {
static IBinding isUsedInClassTemplateScope(ICPPClassTemplate ct, IASTName name) {
try {
- IASTName start= name;
+ IScope scope;
ICPPASTFunctionDefinition func= CPPVisitor.findEnclosingFunctionDefinition(name);
if (func != null) {
- start= ASTQueries.findInnermostDeclarator(func.getDeclarator()).getName();
- start= start.getLastName();
+ name= ASTQueries.findInnermostDeclarator(func.getDeclarator()).getName().getLastName();
+ scope= CPPVisitor.getContainingScope(name);
+ } else {
+ scope= CPPVisitor.getContainingScope(name);
+ if (!(scope instanceof IASTInternalScope))
+ return null;
}
-
- IScope scope= CPPVisitor.getContainingScope(start);
- while (scope instanceof IASTInternalScope) {
+
+ while (scope != null) {
if (scope instanceof ISemanticProblem)
return null;
- final IASTInternalScope internalScope = (IASTInternalScope) scope;
if (scope instanceof ICPPClassScope) {
- final IName scopeName = internalScope.getScopeName();
- if (scopeName instanceof IASTName) {
- IBinding b= ((IASTName) scopeName).resolveBinding();
- if (b instanceof IType && ct.isSameType((IType) b)) {
- return CPPTemplates.instantiateWithinClassTemplate(ct);
- }
- if (b instanceof ICPPClassTemplatePartialSpecialization) {
- ICPPClassTemplatePartialSpecialization pspec= (ICPPClassTemplatePartialSpecialization) b;
- 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;
- }
+ ICPPClassType b= ((ICPPClassScope) scope).getClassType();
+ if (b != null && ct.isSameType(b)) {
+ return CPPTemplates.instantiateWithinClassTemplate(ct);
+ }
+ if (b instanceof ICPPClassTemplatePartialSpecialization) {
+ ICPPClassTemplatePartialSpecialization pspec= (ICPPClassTemplatePartialSpecialization) b;
+ 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; }
}
}
- scope= CPPVisitor.getContainingScope(internalScope.getPhysicalNode());
- if (scope == internalScope)
- return null;
+ if (scope instanceof IASTInternalScope) {
+ IASTInternalScope internalScope= (IASTInternalScope) scope;
+ scope= CPPVisitor.getContainingScope(internalScope.getPhysicalNode());
+ if (scope == internalScope)
+ return null;
+ } else {
+ scope= scope.getParent();
+ }
}
} catch (DOMException e) {
}

Back to the top