Just a gut feeling. Properly solving this might require solving the halting problem: you don't know the variable is unused until you actually evaluate the code. Otherwise you can only aim for detecting very trivial cases.
Yes. See my comment below. The bug is trivially avoided by adhering to a coding standard that actually makes the code better. See my other comment below.