1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-09-08 11:03:28 +02:00

Method templates with name of method, bug 292051.

This commit is contained in:
Markus Schorn 2009-10-14 12:00:38 +00:00
parent 0cfed67288
commit 6ddc2fc4ca
3 changed files with 27 additions and 9 deletions

View file

@ -7451,6 +7451,22 @@ public class AST2CPPTests extends AST2BaseTest {
IASTImplicitNameOwner expr= (IASTImplicitNameOwner) rstmt.getReturnValue();
assertEquals(0, expr.getImplicitNames().length);
}
// class Test {
// template <int T> void t() {}
// inline void t();
// };
//
// inline void Test::t() {
// t<1>();
// }
public void testMethodTemplateWithSameName_292051() throws Exception {
final String code = getAboveComment();
parseAndCheckBindings(code, ParserLanguage.CPP);
BindingAssertionHelper bh= new BindingAssertionHelper(code, true);
ICPPMethod m= bh.assertNonProblem("t<1>", 1);
assertTrue(m.isInline());
}
}

View file

@ -29,7 +29,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateScope;
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
import org.eclipse.cdt.internal.core.dom.parser.ASTInternal;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
import org.eclipse.cdt.internal.core.dom.parser.ASTQueries;
/**
* A template for a method.
@ -44,12 +44,12 @@ public class CPPMethodTemplate extends CPPFunctionTemplate implements ICPPMethod
//first check if we already know it
if( declarations != null ){
for (IASTName declaration : declarations) {
IASTNode parent = declaration.getParent();
while( !(parent instanceof IASTDeclaration) )
parent = parent.getParent();
IASTNode parent = declaration.getParent();
while (!(parent instanceof IASTDeclaration) && parent != null)
parent = parent.getParent();
IASTDeclaration decl = (IASTDeclaration) parent.getParent();
if( decl instanceof ICPPASTCompositeTypeSpecifier )
IASTDeclaration decl = (IASTDeclaration) parent;
if (decl instanceof ICPPASTCompositeTypeSpecifier)
return decl;
}
}
@ -67,13 +67,13 @@ public class CPPMethodTemplate extends CPPFunctionTemplate implements ICPPMethod
if (decl instanceof IASTSimpleDeclaration) {
IASTDeclarator[] dtors = ((IASTSimpleDeclaration) decl).getDeclarators();
for (IASTDeclarator dtor : dtors) {
IASTName name = CPPVisitor.findInnermostDeclarator(dtor).getName();
IASTName name = ASTQueries.findInnermostDeclarator(dtor).getName();
if (CharArrayUtils.equals(name.getLookupKey(), myName) && name.resolveBinding() == this) {
return member;
}
}
} else if (decl instanceof IASTFunctionDefinition) {
IASTName name = CPPVisitor.findInnermostDeclarator(((IASTFunctionDefinition) decl).getDeclarator()).getName();
IASTName name = ASTQueries.findInnermostDeclarator(((IASTFunctionDefinition) decl).getDeclarator()).getName();
if (CharArrayUtils.equals(name.getLookupKey(), myName) && name.resolveBinding() == this) {
return member;
}

View file

@ -2920,7 +2920,9 @@ public class CPPSemantics {
if (!(function instanceof ICPPTemplateDefinition))
return false;
}
}
} else if (function instanceof ICPPTemplateDefinition) {
return false;
}
declarator= ASTQueries.findTypeRelevantDeclarator(declarator);
try {