You can disable this warnings by -Wno-unused-variable
, though this is a bit dangerous (you loose all realy unused variables).
One possible solution is to actually use the variable, but do nothing with it. For example, case it to void:
(void) g;
which can be made into a macro:
#define IGNORE_UNUSED(x) (void) x;
Alternatively, you can use the boost aproach: declare a templated function that does nothing and use it
template <typename T>
void ignore_unused (T const &) { }
...
folly::ScopeGuard g = folly::makeGuard([&] {close(sock);});
ignore_unused(g);