mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-28 11:25:35 +02:00
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>
This commit is contained in:
parent
e091732356
commit
f3141139f8
2 changed files with 16 additions and 6 deletions
|
@ -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 {
|
||||
// };
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Add table
Reference in a new issue