diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java index 0662478677f..1d47589ad40 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java @@ -1570,4 +1570,23 @@ public class AST2TemplateTests extends AST2BaseTest { assertSame( ((ICPPTemplateInstance)f2).getTemplateDefinition(), f ); } + public void testRelaxationForTemplateInheritance() throws Exception { + StringBuffer buffer = new StringBuffer(); + buffer.append("template < class T > class A {}; \n"); //$NON-NLS-1$ + buffer.append("template < class T > class B { \n"); //$NON-NLS-1$ + buffer.append(" void init( A * ); \n"); //$NON-NLS-1$ + buffer.append("}; \n"); //$NON-NLS-1$ + buffer.append("template < class T > class C : public B { \n"); //$NON-NLS-1$ + buffer.append(" C( A * a ) { \n"); //$NON-NLS-1$ + buffer.append(" init( a ); \n"); //$NON-NLS-1$ + buffer.append(" } \n"); //$NON-NLS-1$ + buffer.append("}; \n"); //$NON-NLS-1$ + + IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.CPP ); + CPPNameCollector col = new CPPNameCollector(); + tu.accept( col ); + + ICPPMethod init = (ICPPMethod) col.getName(4).resolveBinding(); + assertSame( init, col.getName(19).resolveBinding() ); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPDeferredClassInstance.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPDeferredClassInstance.java index 34190074a8e..dd7fc664c73 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPDeferredClassInstance.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPDeferredClassInstance.java @@ -45,14 +45,14 @@ public class CPPDeferredClassInstance extends CPPInstance implements ICPPClassTy /* (non-Javadoc) * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType#getBases() */ - public ICPPBase[] getBases() { - return ICPPBase.EMPTY_BASE_ARRAY; + public ICPPBase[] getBases() throws DOMException { + return ((ICPPClassType) classTemplate).getBases(); } /* (non-Javadoc) * @see org.eclipse.cdt.core.dom.ast.ICompositeType#getFields() */ - public IField[] getFields() throws DOMException { + public IField[] getFields() { // TODO Auto-generated method stub return null; } @@ -60,7 +60,7 @@ public class CPPDeferredClassInstance extends CPPInstance implements ICPPClassTy /* (non-Javadoc) * @see org.eclipse.cdt.core.dom.ast.ICompositeType#findField(java.lang.String) */ - public IField findField(String name) throws DOMException { + public IField findField(String name) { // TODO Auto-generated method stub return null; } @@ -68,7 +68,7 @@ public class CPPDeferredClassInstance extends CPPInstance implements ICPPClassTy /* (non-Javadoc) * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType#getDeclaredFields() */ - public ICPPField[] getDeclaredFields() throws DOMException { + public ICPPField[] getDeclaredFields() { // TODO Auto-generated method stub return null; } @@ -76,7 +76,7 @@ public class CPPDeferredClassInstance extends CPPInstance implements ICPPClassTy /* (non-Javadoc) * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType#getMethods() */ - public ICPPMethod[] getMethods() throws DOMException { + public ICPPMethod[] getMethods() { // TODO Auto-generated method stub return null; } @@ -84,7 +84,7 @@ public class CPPDeferredClassInstance extends CPPInstance implements ICPPClassTy /* (non-Javadoc) * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType#getAllDeclaredMethods() */ - public ICPPMethod[] getAllDeclaredMethods() throws DOMException { + public ICPPMethod[] getAllDeclaredMethods() { // TODO Auto-generated method stub return null; } @@ -92,7 +92,7 @@ public class CPPDeferredClassInstance extends CPPInstance implements ICPPClassTy /* (non-Javadoc) * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType#getDeclaredMethods() */ - public ICPPMethod[] getDeclaredMethods() throws DOMException { + public ICPPMethod[] getDeclaredMethods() { // TODO Auto-generated method stub return null; } @@ -100,14 +100,14 @@ public class CPPDeferredClassInstance extends CPPInstance implements ICPPClassTy /* (non-Javadoc) * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType#getConstructors() */ - public ICPPConstructor[] getConstructors() throws DOMException { + public ICPPConstructor[] getConstructors() { return ICPPConstructor.EMPTY_CONSTRUCTOR_ARRAY; } /* (non-Javadoc) * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType#getFriends() */ - public IBinding[] getFriends() throws DOMException { + public IBinding[] getFriends() { // TODO Auto-generated method stub return null; } @@ -124,8 +124,7 @@ public class CPPDeferredClassInstance extends CPPInstance implements ICPPClassTy * @see org.eclipse.cdt.core.dom.ast.ICompositeType#getKey() */ public int getKey() throws DOMException { - // TODO Auto-generated method stub - return 0; + return ((ICPPClassType)classTemplate).getKey(); } /* (non-Javadoc) @@ -165,7 +164,17 @@ public class CPPDeferredClassInstance extends CPPInstance implements ICPPClassTy * @see org.eclipse.cdt.core.dom.ast.IType#isSameType(org.eclipse.cdt.core.dom.ast.IType) */ public boolean isSameType(IType type) { - // TODO Auto-generated method stub - return type == this; + if( type == this ) + return true; + + //allow some fuzziness here. + if( !(type instanceof CPPDeferredClassInstance ) ) + return false; + + ICPPClassTemplate typeClass = (ICPPClassTemplate) ((CPPDeferredClassInstance)type).getSpecializedBinding(); + if( typeClass != classTemplate ) + return false; + + return true; } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPSemantics.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPSemantics.java index b7e7645c4d3..a96c26dbdaa 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPSemantics.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPSemantics.java @@ -2844,7 +2844,10 @@ public class CPPSemantics { parent = bases[i].getBaseClass(); boolean isVisible = ( wrapper.getVisibility() == ICPPBase.v_public); - if( parent == clsBase ){ + if( parent.isSameType( clsBase ) || + (clsBase instanceof ICPPSpecialization && //allow some flexibility with templates + ((IType)((ICPPSpecialization)clsBase).getSpecializedBinding()).isSameType( parent ) ) ) + { if( needVisibility && !isVisible ) return -1; return 1;