The following code snippet has a memory leak that I spent too much time chasing down. The problem is that inside Foo(), the local variable x_ hides the member variable x_.
Use -Wshadow.
By the way, neither -W nor -Wall enables -Wshadow.
It's nice to have the compiler help avoid this kind of problem, but that won't even be necessary if you use conventions that help avoid creating it in the first place, such reserving names of the form x_
for member variables, not local variables.
We use these warts on the beginnings of names - a_ argument d_ data member s_ static data in class f_ static data in file
... and no wart for local variables.
Truly, the Lakos book is your friend.
FWIW I wouldn't have this problem because I use a naming convention to distinguish member data from local variables: my member data identifiers are invariably prefixed with m_
.