diff --git a/core/org.eclipse.cdt.core.tests/failures/org/eclipse/cdt/core/parser/failedTests/FailedCompleteParseASTTest.java b/core/org.eclipse.cdt.core.tests/failures/org/eclipse/cdt/core/parser/failedTests/FailedCompleteParseASTTest.java index 38744ac9c6b..635edd7a1a1 100644 --- a/core/org.eclipse.cdt.core.tests/failures/org/eclipse/cdt/core/parser/failedTests/FailedCompleteParseASTTest.java +++ b/core/org.eclipse.cdt.core.tests/failures/org/eclipse/cdt/core/parser/failedTests/FailedCompleteParseASTTest.java @@ -172,24 +172,6 @@ public class FailedCompleteParseASTTest extends CompleteParseBaseTest // assertFalse(j.hasNext()); } - public void testThisInTemplatedMemberFunction_bug71331() throws Exception { - // dereferencing 'this' in a templated member function - try { - parse("class A { \n int f() {return 0;} \n template int g(T*) { return this->f(); } \n }; \n");//$NON-NLS-1$ - fail(); - } catch (ParserException e) { - assertTrue( e.getMessage().equals( "FAILURE" ) ); //$NON-NLS-1$ - } -// Iterator i = parse("class A { \n int f() {return 0;} \n template int g(T*) { return this->f(); } \n }; \n").getDeclarations();//$NON-NLS-1$ -// IASTAbstractTypeSpecifierDeclaration cd = (IASTAbstractTypeSpecifierDeclaration) i.next(); -// assertFalse(i.hasNext()); -// IASTClassSpecifier cs = (IASTClassSpecifier) cd.getTypeSpecifier(); -// Iterator j = cs.getDeclarations(); -// IASTMethod md = (IASTMethod) j.next(); -// IASTTemplateDeclaration tmd = (IASTTemplateDeclaration) j.next(); -// assertFalse(j.hasNext()); - } - public void testParametrizedTypeDefinition_bug69751() throws Exception { try { // a typedef refers to an unknown type in a template parameter diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTTemplateTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTTemplateTest.java index b366ab4acd7..239895926ee 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTTemplateTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTTemplateTest.java @@ -1057,4 +1057,15 @@ public class CompleteParseASTTemplateTest extends CompleteParseBaseTest { IASTMethod m = (IASTMethod) j.next(); assertFalse(j.hasNext()); } + + public void testThisInTemplatedMemberFunction_bug71331() throws Exception { + Iterator i = parse("class A { \n int f() {return 0;} \n template int g(T*) { return this->f(); } \n }; \n").getDeclarations();//$NON-NLS-1$ + IASTAbstractTypeSpecifierDeclaration cd = (IASTAbstractTypeSpecifierDeclaration) i.next(); + assertFalse(i.hasNext()); + IASTClassSpecifier cs = (IASTClassSpecifier) cd.getTypeSpecifier(); + Iterator j = cs.getDeclarations(); + IASTMethod md = (IASTMethod) j.next(); + IASTTemplateDeclaration tmd = (IASTTemplateDeclaration) j.next(); + assertFalse(j.hasNext()); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/DerivableContainerSymbol.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/DerivableContainerSymbol.java index cf3971ed2ad..94ce33122e3 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/DerivableContainerSymbol.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/DerivableContainerSymbol.java @@ -272,13 +272,27 @@ public class DerivableContainerSymbol extends ContainerSymbol implements IDeriva return false; } + if( obj instanceof ITemplateSymbol ){ + ISymbol templated = ((ITemplateSymbol)obj).getTemplatedSymbol(); + if( templated instanceof IParameterizedSymbol ){ + obj = (IParameterizedSymbol) templated; + } else { + return false; + } + } + + IContainerSymbol containing = obj.getContainingSymbol(); + if( containing instanceof ITemplateSymbol ){ + containing = containing.getContainingSymbol(); + } + ITypeInfo type = obj.getTypeInfo(); if( ( !type.isType( ITypeInfo.t_function ) && !type.isType( ITypeInfo.t_constructor) ) || type.checkBit( ITypeInfo.isStatic ) ){ return false; } - if( obj.getContainingSymbol().isType( ITypeInfo.t_class, ITypeInfo.t_union ) ){ + if( containing.isType( ITypeInfo.t_class, ITypeInfo.t_union ) ){ //check to see if there is already a this object, since using declarations //of function will have them from the original declaration boolean foundThis = false; @@ -296,7 +310,6 @@ public class DerivableContainerSymbol extends ContainerSymbol implements IDeriva if( !foundThis ){ ISymbol thisObj = getSymbolTable().newSymbol( ParserSymbolTable.THIS, ITypeInfo.t_type ); thisObj.setTypeSymbol( obj.getContainingSymbol() ); - //thisObj.setCVQualifier( obj.getCVQualifier() ); ITypeInfo.PtrOp ptr = new ITypeInfo.PtrOp(); ptr.setType( ITypeInfo.PtrOp.t_pointer ); thisObj.getTypeInfo().setBit( obj.getTypeInfo().checkBit( ITypeInfo.isConst ), ITypeInfo.isConst );