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 b55ccb29351..bc079920ddb 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
@@ -5986,4 +5986,14 @@ public class AST2CPPTests extends AST2BaseTest {
specs= fdtor.getExceptionSpecification();
assertEquals(1, specs.length);
}
+
+ // int test() {
+ // try {
+ // } catch (const int &ex) {
+ // } catch (const char &ex) {
+ // }
+ // }
+ public void testScopeOfCatchHandler_Bug209579() throws Exception {
+ parseAndCheckBindings(getAboveComment(), ParserLanguage.CPP);
+ }
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTCatchHandler.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTCatchHandler.java
index 805209307c3..5372e80133f 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTCatchHandler.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTCatchHandler.java
@@ -13,22 +13,21 @@ package org.eclipse.cdt.core.dom.ast.cpp;
import org.eclipse.cdt.core.dom.ast.ASTNodeProperty;
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTStatement;
+import org.eclipse.cdt.core.dom.ast.IScope;
/**
- * Catch handler serves as a standalone stage.
+ * Catch handler used for try block statements or for functions with try block.
+ * @see ICPPASTFunctionWithTryBlock
+ * @see ICPPASTTryBlockStatement
*
- * @author jcamelon
+ * @noimplement This interface is not intended to be implemented by clients.
*/
public interface ICPPASTCatchHandler extends IASTStatement {
- /**
- * Constant
- */
public static final ICPPASTCatchHandler[] EMPTY_CATCHHANDLER_ARRAY = new ICPPASTCatchHandler[0];
/**
- * DECLARATION
represnts the nested declaration within the
- * catch handler.
+ * DECLARATION
represents the nested declaration within the catch handler.
*/
public static final ASTNodeProperty DECLARATION = new ASTNodeProperty(
"ICPPASTCatchHandler.DECLARATION - Nested declaration within catch handler"); //$NON-NLS-1$
@@ -41,47 +40,37 @@ public interface ICPPASTCatchHandler extends IASTStatement {
/**
* Set is catch all handler.
- *
- * @param isEllipsis
- * boolean
*/
public void setIsCatchAll(boolean isEllipsis);
/**
* Is this catch handler for all exceptions?
- *
- * @return boolean
*/
public boolean isCatchAll();
/**
* Set the catch body.
- *
- * @param compoundStatement
- * IASTStatement
*/
public void setCatchBody(IASTStatement compoundStatement);
/**
- * Get the cathc body.
- *
- * @return IASTStatement
+ * Get the catch body.
*/
public IASTStatement getCatchBody();
/**
* Set the declaration.
- *
- * @param decl
- * IASTDeclaration
*/
public void setDeclaration(IASTDeclaration decl);
/**
* Get the declaration.
- *
- * @return IASTDeclaration
*/
public IASTDeclaration getDeclaration();
+ /**
+ * Get the scope represented by this catch handler.
+ * @since 5.1
+ */
+ public IScope getScope();
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCatchHandler.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCatchHandler.java
index a4541c85481..59da7ad28f1 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCatchHandler.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCatchHandler.java
@@ -6,7 +6,8 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * IBM - Initial API and implementation
+ * IBM - Initial API and implementation
+ * Markus Schorn (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp;
@@ -14,6 +15,7 @@ import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTStatement;
+import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCatchHandler;
import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent;
@@ -25,6 +27,7 @@ public class CPPASTCatchHandler extends CPPASTNode implements ICPPASTCatchHandle
private boolean isCatchAll;
private IASTStatement body;
private IASTDeclaration declaration;
+ private IScope scope;
public CPPASTCatchHandler() {
}
@@ -103,4 +106,11 @@ public class CPPASTCatchHandler extends CPPASTNode implements ICPPASTCatchHandle
}
}
+
+ public IScope getScope() {
+ if (scope == null) {
+ scope = new CPPBlockScope(this);
+ }
+ return scope;
+ }
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPScope.java
index cac9f80c512..ea698863dff 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPScope.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPScope.java
@@ -459,6 +459,8 @@ abstract public class CPPScope implements ICPPScope, IASTInternalScope {
name = getScopeName();
} catch (DOMException e) {
}
- return name != null ? name.toString() : ""; //$NON-NLS-1$
+
+ final String n= name != null ? name.toString() : ""; //$NON-NLS-1$
+ return getKind().toString() + ' ' + n + ' ' + '(' + super.toString() + ')';
}
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java
index 6c54e698f9b..6dc5494d5ee 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java
@@ -86,6 +86,7 @@ import org.eclipse.cdt.core.dom.ast.IVariable;
import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator;
import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTBinaryExpression;
+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.ICPPASTConversionName;
@@ -770,6 +771,8 @@ public class CPPVisitor {
return ((ICPPASTWhileStatement)parent).getScope();
} else if (parent instanceof ICPPASTTemplateDeclaration) {
return ((ICPPASTTemplateDeclaration)parent).getScope();
+ } else if (parent instanceof ICPPASTCatchHandler) {
+ return ((ICPPASTCatchHandler)parent).getScope();
}
} else if (node instanceof IASTStatement) {
return getContainingScope((IASTStatement) node);