semantic-refactor icon indicating copy to clipboard operation
semantic-refactor copied to clipboard

c++: variable scope problems with 'rename'

Open dpathakj opened this issue 8 years ago • 0 comments

In the following code, when I put the cursor on the first occurrence of i (the declaration) and ask for a rename, only the declaration is renamed - not the other occurrences of i (in i < 3, i++, cout << i, etc.).

for (int i = 0; i < 3; i++) {
  cout << i;
}

If I declare 'i' externally, then there are still scoping issues.

for (int i = 0; i < 3; i++) { // incorrectly renamed
  cout << i; // incorrectly renamed
}

int i; // <- run rename on this 'i'
for (i = 0; i < 3; i++) { // these are renamed, correctly

}

then all instances of i are renamed, even those from the first for loop.

dpathakj avatar May 14 '17 18:05 dpathakj