You can disable these warnings with -Wno-unused-variable, although this is a bit dangerous (you will lose all really unused variables).
One possible solution is to actually use this variable, but do nothing with it. For example, if it is not valid:
(void) g;
which can be done in a macro:
#define IGNORE_UNUSED(x) (void) x;
boost aproach: ,
template <typename T>
void ignore_unused (T const &) { }
...
folly::ScopeGuard g = folly::makeGuard([&] {close(sock);});
ignore_unused(g);