Unless I'm missing something, this should do the trick:
g++ -c -O2 -Wall -Wno-unused-variable foo.cpp
I was hoping there was some way to modify ON_BLOCK_EXIT, so I could leave
the unused variable warning, but only disable it for ScopeGuard with a
pragma.