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 a5c44956b22..1ea9e8f292f 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 @@ -4889,4 +4889,25 @@ public class AST2CPPTests extends AST2BaseTest { assertSame( f2, col.getName(16).resolveBinding() ); assertSame( BT, col.getName(17).resolveBinding() ); } + + public void testBug103281() throws Exception { + StringBuffer buffer = new StringBuffer(); + buffer.append("struct Except { int blah; }; \n"); //$NON-NLS-1$ + buffer.append("void f() { \n"); //$NON-NLS-1$ + buffer.append(" try { } \n"); //$NON-NLS-1$ + buffer.append(" catch ( Except * e ) { \n"); //$NON-NLS-1$ + buffer.append(" e->blah; \n"); //$NON-NLS-1$ + buffer.append(" } \n"); //$NON-NLS-1$ + buffer.append("} \n"); //$NON-NLS-1$ + + IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP, true, true ); + CPPNameCollector col = new CPPNameCollector(); + tu.accept( col ); + + IField blah = (IField) col.getName(1).resolveBinding(); + IVariable e = (IVariable) col.getName(4).resolveBinding(); + + assertSame( e, col.getName(5).resolveBinding() ); + assertSame( blah, col.getName(6).resolveBinding() ); + } } 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 b9132ea5d5a..61c48ca41f8 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 @@ -62,6 +62,7 @@ import org.eclipse.cdt.core.dom.ast.ITypedef; import org.eclipse.cdt.core.dom.ast.IVariable; import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator; import org.eclipse.cdt.core.dom.ast.c.ICASTFieldDesignator; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCatchHandler; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorChainInitializer; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeclSpecifier; @@ -1346,11 +1347,14 @@ public class CPPSemantics { IASTName[] found = null; if( parent instanceof IASTCompoundStatement ){ - if( parent.getParent() instanceof IASTFunctionDefinition ){ - ICPPASTFunctionDeclarator dtor = (ICPPASTFunctionDeclarator) ((IASTFunctionDefinition)parent.getParent()).getDeclarator(); + IASTNode p = parent.getParent(); + if( p instanceof IASTFunctionDefinition ){ + ICPPASTFunctionDeclarator dtor = (ICPPASTFunctionDeclarator) ((IASTFunctionDefinition)p).getDeclarator(); nodes = dtor.getParameters(); } - if( nodes == null || nodes.length == 0 ){ + if( p instanceof ICPPASTCatchHandler ){ + parent = p; + } else if( nodes == null || nodes.length == 0 ){ IASTCompoundStatement compound = (IASTCompoundStatement) parent; nodes = compound.getStatements(); } @@ -1462,6 +1466,16 @@ public class CPPSemantics { item = nodes[0]; break; } + } else if( parent instanceof ICPPASTCatchHandler ){ + parent = ((ICPPASTCatchHandler)parent).getCatchBody(); + if( parent instanceof IASTCompoundStatement ){ + nodes = ((IASTCompoundStatement)parent).getStatements(); + } + if( nodes.length > 0 ){ + idx = 0; + item = nodes[0]; + break; + } } if( item == null && nodeStackPos >= 0 ){ nodes = nodeStack[nodeStackPos]; @@ -1545,6 +1559,8 @@ public class CPPSemantics { declaration = (IASTDeclaration) node; else if( node instanceof IASTDeclarationStatement ) declaration = ((IASTDeclarationStatement)node).getDeclaration(); + else if( node instanceof ICPPASTCatchHandler ) + declaration = ((ICPPASTCatchHandler)node).getDeclaration(); else if( node instanceof ICPPASTForStatement && checkAux ) { ICPPASTForStatement forStatement = (ICPPASTForStatement) node;