Bug 472101 - Do not include variables declared in the condition of an
authorNathan Ridge <zeratul976@hotmail.com>
Sun, 12 Jul 2015 02:34:57 +0000 (22:34 -0400)
committerGerrit Code Review @ Eclipse.org <gerrit@eclipse.org>
Sun, 12 Jul 2015 06:21:21 +0000 (02:21 -0400)
if, while, or switch statement in the enclosing block scope

Change-Id: Idd90d85f705af11c84f31ca830eb86682a046b87
Signed-off-by: Nathan Ridge <zeratul976@hotmail.com>
core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java
core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java

index 520c156..87bd065 100644 (file)
@@ -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 {
        //      };
index 6071b15..be938c1 100644 (file)
@@ -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();