We do not see this often in the code. In fact, every case I've encountered has been a bug in our code and is always the result of a second developer inheriting the code and not realizing the earlier 'foo'. Default VS compiler warnings don't flag this though I'm attempting to move everyone to /W4 and/or /analyze builds.
I encountered this b/c I've been going through the PREfast (Team System Static Code Analysis) warnings report for our project. I was attempting to rename the inner foo to something different with the VA Rename refactoring when I noticed it marked the incorrect items. This made me a little wary of the Rename refactoring.
I agree, code of this nature should not be in the project as it can cause bugs.
I noticed a similar bug with the references picking up items from an earlier scope but did not create another test case -- I believe the earlier scope was in a case statement. Something like:
{ case 1: { int bar; . . . }
case 2: { int bar;
bar = 5; // I believe highlighting refs on this picked up bar from an earlier case as well. }
I didn't isolate it to a repro test case but will keep an eye out for it.