1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Correct assignment of template declaration to names of constructor using template ids, bug 259600.

This commit is contained in:
Markus Schorn 2009-01-08 16:05:09 +00:00
parent 8e652c282f
commit 42fab5f121
2 changed files with 42 additions and 4 deletions

View file

@ -3574,4 +3574,24 @@ public class AST2TemplateTests extends AST2BaseTest {
BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), true); BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), true);
bh.assertNonProblem("A<B, int>", 9, ICPPConstructor.class); bh.assertNonProblem("A<B, int>", 9, ICPPConstructor.class);
} }
// template <class T>
// class DumbPtr {
// public:
// DumbPtr<T> (const DumbPtr<T>& aObj);
// ~DumbPtr<T> ();
// };
// template <class T>
// DumbPtr<T>::DumbPtr<T>/**/ (const DumbPtr<T>& aObj) {
// }
// template <class T>
// DumbPtr<T>::~DumbPtr<T>/**/ () {
// }
public void testCtorWithTemplateID_259600() throws Exception {
final String code = getAboveComment();
parseAndCheckBindings(code, ParserLanguage.CPP);
BindingAssertionHelper bh= new BindingAssertionHelper(code, true);
ICPPConstructor ctor= bh.assertNonProblem("DumbPtr<T>/**/", 10);
ICPPMethod dtor= bh.assertNonProblem("~DumbPtr<T>/**/", 11);
}
} }

View file

@ -83,6 +83,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateTypeParameter;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier;
import org.eclipse.cdt.core.parser.util.ArrayUtil; import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.core.parser.util.CharArraySet; import org.eclipse.cdt.core.parser.util.CharArraySet;
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
import org.eclipse.cdt.core.parser.util.ObjectMap; import org.eclipse.cdt.core.parser.util.ObjectMap;
import org.eclipse.cdt.core.parser.util.ObjectSet; import org.eclipse.cdt.core.parser.util.ObjectSet;
import org.eclipse.cdt.internal.core.dom.parser.ASTInternal; import org.eclipse.cdt.internal.core.dom.parser.ASTInternal;
@ -224,6 +225,8 @@ public class CPPTemplates {
IScope scope= CPPVisitor.getContainingScope(start); IScope scope= CPPVisitor.getContainingScope(start);
while (scope instanceof IASTInternalScope) { while (scope instanceof IASTInternalScope) {
if (scope instanceof IProblemBinding)
return null;
final IASTInternalScope internalScope = (IASTInternalScope) scope; final IASTInternalScope internalScope = (IASTInternalScope) scope;
if (scope instanceof ICPPClassScope) { if (scope instanceof ICPPClassScope) {
final IName scopeName = internalScope.getScopeName(); final IName scopeName = internalScope.getScopeName();
@ -246,6 +249,8 @@ public class CPPTemplates {
} }
} }
scope= CPPVisitor.getContainingScope(internalScope.getPhysicalNode()); scope= CPPVisitor.getContainingScope(internalScope.getPhysicalNode());
if (scope == internalScope)
return null;
} }
} catch (DOMException e) { } catch (DOMException e) {
} }
@ -930,8 +935,7 @@ public class CPPTemplates {
// last name can be associated even if it is not a template-id // last name can be associated even if it is not a template-id
final ICPPASTQualifiedName qname= (ICPPASTQualifiedName) parent; final ICPPASTQualifiedName qname= (ICPPASTQualifiedName) parent;
final IASTName lastName = qname.getLastName(); final IASTName lastName = qname.getLastName();
final boolean lastIsTemplate= lastName instanceof ICPPASTTemplateId || final boolean lastIsTemplate= tdecl.isAssociatedWithLastName();
tdecl.isAssociatedWithLastName();
if (name == lastName) { if (name == lastName) {
if (lastIsTemplate) { if (lastIsTemplate) {
return tdecl; return tdecl;
@ -988,7 +992,8 @@ public class CPPTemplates {
int additionalLevels= 0; int additionalLevels= 0;
if (name instanceof ICPPASTQualifiedName) { if (name instanceof ICPPASTQualifiedName) {
ICPPASTQualifiedName qname= (ICPPASTQualifiedName) name; ICPPASTQualifiedName qname= (ICPPASTQualifiedName) name;
final boolean lastIsID = qname.getLastName() instanceof ICPPASTTemplateId; final IASTName lastName = qname.getLastName();
final boolean lastIsID = lastName instanceof ICPPASTTemplateId;
// count template-ids // count template-ids
int idcount= 0; int idcount= 0;
@ -1000,7 +1005,20 @@ public class CPPTemplates {
} }
} }
if (lastIsID) { boolean isCtorWithTemplateID= false;
if (lastIsID && ns.length > 1) {
IASTName secondLastName= ns[ns.length-2];
if (secondLastName instanceof ICPPASTTemplateId) {
final char[] lastNamesLookupKey = lastName.getLookupKey();
if (CharArrayUtils.equals(lastNamesLookupKey, ((ICPPASTTemplateId) secondLastName).getLookupKey()) ||
(lastNamesLookupKey.length > 0 && lastNamesLookupKey[0] == '~')) {
isCtorWithTemplateID= true;
idcount--;
}
}
}
if (lastIsID && !isCtorWithTemplateID) {
additionalLevels= idcount-tdeclcount; additionalLevels= idcount-tdeclcount;
} else { } else {
additionalLevels= idcount+1-tdeclcount; additionalLevels= idcount+1-tdeclcount;