I ask for a LOKI_ON_BLOCK_EXIT that does not emit a compiler warning about an unused variable on GCC and MSVC.
one use of ScopeGuard is as a convenient RAII "cleanup" mechanism, that is without calling "Dismiss()" later.
The problem then is that GCC and MSVC emit compiler warnings about an unused variable.
This happens both when using a dummy variable without dismissing it and more critically when using "LOKI_ON_BLOCK_EXIT", which is specifically designed for that purpose.
As seen here, others have been looking for an answer, but with little success:
For GCC, there is a nice and simple solution which could be implemented by the Loki library:
typedef const ScopeGuardImplBase& ScopeGuard;
__attribute__((unused)) typedef const ScopeGuardImplBase& ScopeGuard;
Unfortunately there is no MSVC equivalent.
Now with C++11, there might be light at the end of the tunnel:
One way to silence the warning about unused variable in both GCC and MSVC is to get rid of the const-reference:
typedef const ScopeGuardImplBase& ScopeGuard; -> typedef ScopeGuardImplBase ScopeGuard;
It's clear that this creates problems for the general ScopeGuard case where the type is dependent from the number and types of arguments passed. But for LOKI_ON_BLOCK_EXIT, this shouldn't matter. What's still missing is a way to "pass the value without copying". Here C++11 r-value-refences are the fitting solution.
You see, there are a few open questions, but my hope is that they can be figured out eventually.
Best regards, ZenJu
Log in to post a comment.