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 2a290535765..7bb7b366402 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 @@ -2575,5 +2575,45 @@ public class AST2CPPTests extends AST2BaseTest { IFunction printf = (IFunction) col.getName(6).resolveBinding(); assertInstances( col, printf, 3 ); } + + public void testBug86554() throws Exception { + StringBuffer buffer = new StringBuffer(); + buffer.append("int max( int a, int b, int c ) { \n"); //$NON-NLS-1$ + buffer.append(" int m = ( a > b ) ? a : b; \n"); //$NON-NLS-1$ + buffer.append(" return ( m > c ) ? m : c; \n"); //$NON-NLS-1$ + buffer.append("} \n"); //$NON-NLS-1$ + + IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP); + CPPNameCollector col = new CPPNameCollector(); + tu.getVisitor().visitTranslationUnit(col); + + IVariable m = (IVariable) col.getName(11).resolveBinding(); + IParameter a = (IParameter) col.getName(1).resolveBinding(); + IParameter b = (IParameter) col.getName(2).resolveBinding(); + IParameter c = (IParameter) col.getName(3).resolveBinding(); + + assertInstances( col, m, 3 ); + assertInstances( col, a, 3 ); + assertInstances( col, b, 3 ); + assertInstances( col, c, 3 ); + } + + public void testBug86621() throws Exception { + StringBuffer buffer = new StringBuffer(); + buffer.append("int g(); \n"); //$NON-NLS-1$ + buffer.append("struct X { static int g(); }; \n"); //$NON-NLS-1$ + buffer.append("struct Y : X { static int i ; }; \n"); //$NON-NLS-1$ + buffer.append("int Y::i = g(); \n"); //$NON-NLS-1$ + + IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP); + CPPNameCollector col = new CPPNameCollector(); + tu.getVisitor().visitTranslationUnit(col); + + IFunction g1 = (IFunction) col.getName(0).resolveBinding(); + ICPPMethod g2 = (ICPPMethod) col.getName(9).resolveBinding(); + + assertInstances( col, g1, 1 ); + assertInstances( col, g2, 2 ); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVisitor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVisitor.java index 13fd2ea634e..571ac90028e 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVisitor.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVisitor.java @@ -547,6 +547,13 @@ public class CPPVisitor implements ICPPASTVisitor { return dtor.getFunctionScope(); else if( prop == IASTFunctionDefinition.DECLARATOR ) return ((IASTCompoundStatement)((IASTFunctionDefinition)dtor.getParent()).getBody()).getScope(); + } else if( node instanceof IASTInitializerExpression ){ + IASTDeclarator dtor = (IASTDeclarator) node.getParent(); + IASTName name = dtor.getName(); + if( name instanceof ICPPASTQualifiedName ){ + IASTName [] ns = ((ICPPASTQualifiedName)name).getNames(); + return getContainingScope( ns[ ns.length - 1 ] ); + } } else if( node instanceof IASTExpression ){ IASTNode parent = node.getParent(); if( parent instanceof IASTForStatement ){