Skip to main content
aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorNathan Ridge2015-07-12 02:34:57 +0000
committerGerrit Code Review @ Eclipse.org2015-07-12 06:21:21 +0000
commitf3141139f82703b541dd1102cc37f9c525d68c9b (patch)
treebc9dea2fc6571c6b5c127ccdbf57e4378b0d7ca4 /core
parente091732356ee050ecc494ff4e62cacababe2bb1e (diff)
downloadorg.eclipse.cdt-f3141139f82703b541dd1102cc37f9c525d68c9b.tar.gz
org.eclipse.cdt-f3141139f82703b541dd1102cc37f9c525d68c9b.tar.xz
org.eclipse.cdt-f3141139f82703b541dd1102cc37f9c525d68c9b.zip
Bug 472101 - Do not include variables declared in the condition of an
if, while, or switch statement in the enclosing block scope Change-Id: Idd90d85f705af11c84f31ca830eb86682a046b87 Signed-off-by: Nathan Ridge <zeratul976@hotmail.com>
Diffstat (limited to 'core')
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java10
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java12
2 files changed, 16 insertions, 6 deletions
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 520c156573..87bd065f7c 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
@@ -10090,6 +10090,16 @@ public class AST2CPPTests extends AST2TestBase {
assertNotSame(g1, g2);
assertSame(g2, g3);
}
+
+ // int test() {
+ // extern int *e();
+ // if (auto r = e()) { return *r; }
+ // int r = 12;
+ // return r;
+ // }
+ public void testVariableDeclarationInIfStatement() throws Exception {
+ parseAndCheckBindings();
+ }
// class A : A {
// };
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java
index 6071b15347..be938c1e1b 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java
@@ -1503,6 +1503,12 @@ public class CPPSemantics {
} else {
nodes= new IASTNode[] {initDeclaration};
}
+ } else if (parent instanceof ICPPASTSwitchStatement) {
+ nodes = new IASTNode[] { ((ICPPASTSwitchStatement) parent).getControllerDeclaration() };
+ } else if (parent instanceof ICPPASTIfStatement) {
+ nodes = new IASTNode[] { ((ICPPASTIfStatement) parent).getConditionDeclaration() };
+ } else if (parent instanceof ICPPASTWhileStatement) {
+ nodes = new IASTNode[] { ((ICPPASTWhileStatement) parent).getConditionDeclaration() };
} else if (parent instanceof ICPPASTRangeBasedForStatement) {
ICPPASTRangeBasedForStatement forStatement = (ICPPASTRangeBasedForStatement) parent;
final IASTDeclaration decl = forStatement.getDeclaration();
@@ -1632,12 +1638,6 @@ public class CPPSemantics {
declaration = ((IASTDeclarationStatement) node).getDeclaration();
} else if (node instanceof ICPPASTCatchHandler) {
declaration = ((ICPPASTCatchHandler) node).getDeclaration();
- } else if (node instanceof ICPPASTSwitchStatement) {
- declaration = ((ICPPASTSwitchStatement) node).getControllerDeclaration();
- } else if (node instanceof ICPPASTIfStatement) {
- declaration = ((ICPPASTIfStatement) node).getConditionDeclaration();
- } else if (node instanceof ICPPASTWhileStatement) {
- declaration = ((ICPPASTWhileStatement) node).getConditionDeclaration();
} else if (node instanceof IASTParameterDeclaration) {
IASTParameterDeclaration parameterDeclaration = (IASTParameterDeclaration) node;
IASTDeclarator dtor = parameterDeclaration.getDeclarator();

Back to the top