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 357a224e832..dae978d5246 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 @@ -1158,5 +1158,42 @@ public class AST2CPPTests extends AST2BaseTest { assertEquals( name.getNames()[1].toString(), "DEF" ); //$NON-NLS-1$ assertEquals( name.getNames()[2].toString(), "ghi" ); //$NON-NLS-1$ } + + public void _test84679() throws Exception { + StringBuffer buffer = new StringBuffer(); + buffer.append("namespace Y { void f(float); } // NPE on resolve binding \n"); //$NON-NLS-1$ + buffer.append("namespace A { using namespace Y; f(int); } // NPE on resolve binding \n" ); //$NON-NLS-1$ + buffer.append("namespace B { void f(char); } // NPE on resolve binding \n "); //$NON-NLS-1$ + buffer.append("namespace AB { using namespace A; using namespace B; } \n" ); //$NON-NLS-1$ + buffer.append("void h(){ \n"); //$NON-NLS-1$ + buffer.append(" AB::f(1); \n"); //$NON-NLS-1$ + buffer.append(" AB::f(’c’); \n"); //$NON-NLS-1$ + buffer.append("} \n"); //$NON-NLS-1$ + } + + public void testBug84692() throws Exception { + StringBuffer buffer = new StringBuffer(); + buffer.append("struct Node { \n"); //$NON-NLS-1$ + buffer.append(" struct Node* Next; \n"); //$NON-NLS-1$ + buffer.append(" struct Data* Data; \n"); //$NON-NLS-1$ + buffer.append("}; \n"); //$NON-NLS-1$ + buffer.append("struct Data { \n"); //$NON-NLS-1$ + buffer.append(" struct Node * node; \n"); //$NON-NLS-1$ + buffer.append(" friend struct Glob; \n"); //$NON-NLS-1$ + buffer.append("}; \n"); //$NON-NLS-1$ + + IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP); + CPPNameCollector col = new CPPNameCollector(); + CPPVisitor.visitTranslationUnit(tu, col); + + assertEquals(col.size(), 9); + + ICPPClassType Node = (ICPPClassType) col.getName(1).resolveBinding(); + ICPPClassType Data = (ICPPClassType) col.getName(3).resolveBinding(); + + assertInstances( col, Node, 3 ); + assertInstances( col, Data, 2 ); + } + } 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 199c23d8e68..fa6475b8045 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 @@ -708,32 +708,29 @@ public class CPPSemantics { ICPPASTFunctionDeclarator dtor = (ICPPASTFunctionDeclarator) parent; nodes = dtor.getParameters(); } - - if( scope instanceof ICPPClassScope ){ - blockItem = null; - } int idx = -1; + boolean classScope = ( scope instanceof ICPPClassScope ); IASTNode item = ( nodes != null ? (nodes.length > 0 ? nodes[++idx] : null ) : parent ); while( item != null ) { - if( item == null || ( blockItem != null && ((ASTNode)item).getOffset() > ((ASTNode) blockItem).getOffset() )) + if( !classScope && blockItem != null && ((ASTNode)item).getOffset() > ((ASTNode) blockItem).getOffset() ) break; - if( item == blockItem && !data.includeBlockItem( item ) ) - break; - if( item instanceof ICPPASTUsingDirective && !data.ignoreUsingDirectives ) { - if( usingDirectives != null ) - usingDirectives.add( item ); - } else { - possible = collectResult( data, scope, item, (item == parent) ); - if( possible != null ){ - if( found == null ) - found = new ArrayList(2); - found.add( possible ); + if( item != blockItem || data.includeBlockItem( item ) ){ + if( item instanceof ICPPASTUsingDirective && !data.ignoreUsingDirectives ) { + if( usingDirectives != null ) + usingDirectives.add( item ); + } else { + possible = collectResult( data, scope, item, (item == parent) ); + if( possible != null ){ + if( found == null ) + found = new ArrayList(2); + found.add( possible ); + } } } - if( item == blockItem ) + if( item == blockItem && !classScope ) break; if( idx > -1 && ++idx < nodes.length ){ item = nodes[idx];