diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java index faa99e82949..33908a65c2c 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java @@ -3120,5 +3120,23 @@ public class AST2CPPTests extends AST2BaseTest { assertTrue( col.getName(4).resolveBinding() instanceof ICPPConstructor ); } + + public void testBug89851() throws Exception { + StringBuffer buffer = new StringBuffer(); + buffer.append( "class B * b; \n"); //$NON-NLS-1$ + buffer.append( "class A { \n"); //$NON-NLS-1$ + buffer.append( " A * a; \n"); //$NON-NLS-1$ + buffer.append( "}; \n"); //$NON-NLS-1$ + buffer.append( "class A; \n"); //$NON-NLS-1$ + + IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.CPP ); //$NON-NLS-1$ + CPPNameCollector col = new CPPNameCollector(); + tu.accept( col ); + + assertTrue( col.getName(0).resolveBinding() instanceof ICPPClassType ); + assertTrue( col.getName(1).resolveBinding() instanceof ICPPVariable ); + assertTrue( col.getName(2).resolveBinding() instanceof ICPPClassType ); + assertTrue( col.getName(3).resolveBinding() instanceof ICPPClassType ); + } } 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 9a32d9ddc92..e65f34c395c 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 @@ -1318,12 +1318,22 @@ public class CPPSemantics { if( obj instanceof ICPPInternalBinding ){ ICPPInternalBinding cpp = (ICPPInternalBinding) obj; IASTNode[] n = cpp.getDeclarations(); - - if( n != null && n.length > 0 ) - nd = (ASTNode) n[0]; - else if( cpp.getDefinition() != null ) - nd = (ASTNode) cpp.getDefinition(); - else + int o, offset = -1; + if( n != null && n.length > 0 ) { + nd = (ASTNode) n[0]; + offset = ((ASTNode) n[0]).getOffset(); + for (int i = 1; i < n.length && n[i] != null; i++) { + o = ((ASTNode) n[i]).getOffset(); + if( o < offset ) + nd = (ASTNode) n[i]; + } + } + if( cpp.getDefinition() != null ){ + if( nd == null || ((ASTNode)cpp.getDefinition()).getOffset() < nd.getOffset() ) + nd = (ASTNode) cpp.getDefinition(); + + } + if( nd == null ) return true; } else if( obj instanceof ASTNode ){ nd = (ASTNode) obj;