I am using folly scope guard, it is working, but it generates a warning saying that the variable is unused:
warning: unused variable ‘g’ [-Wunused-variable]
The code:
folly::ScopeGuard g = folly::makeGuard([&] {close(sock);});
How to avoid such warning?
You can just label the variable as being unused:
folly::ScopeGuard g [[gnu::unused]] = folly::makeGuard([&] {close(sock);});
Or cast it to void:
folly::ScopeGuard g = folly::makeGuard([&] {close(sock);});
(void)g;
Neither is great, imo, but at least this lets you keep the warnings.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With