It would need to be whitelist based like unused-non-trivial-variable I would like a test that warns you if you have stuff like QFileInfo obj; if (bla) { // use obj } else { // don't use obj } And tell you to move the obj declaration inside the first if block