Fog Creek Software
Discussion Board




ScopeGuard warnings in G++

Does anybody know how to turn off the "unused variable" warnings for ScopeGuard in g++? 

The variable does get used, but only at destruction time.  That is the whole point of ScopeGuard. 

christopher (baus.net)
Wednesday, July 21, 2004

Wow I think I started the first thread that didn't get any responses.  I am still looking for a solution to this.  It is possible to disable the unused variable warning, but I would like to leave it, and only disable it for ScopeGuard say in ON_BLOCK_EXIT with a pragma.

christopher (baus.net)
Thursday, July 22, 2004

If anybody cares the solution is to use __attribute__ ((unused)) and the ON_BLOCK_EXIT macro. 

You can replace the last few lines in ScopeGuard.h with

#ifdef __GNUC__
#define ON_BLOCK_EXIT ScopeGuard ANONYMOUS_VARIABLE(scopeGuard) __attribute__ ((unused)) = MakeGuard
#define ON_BLOCK_EXIT_OBJ ScopeGuard ANONYMOUS_VARIABLE(scopeGuard) __attribute__ ((unused)) = MakeObjGuard
#else
#define ON_BLOCK_EXIT ScopeGuard ANONYMOUS_VARIABLE(scopeGuard) = MakeGuard
#define ON_BLOCK_EXIT_OBJ ScopeGuard ANONYMOUS_VARIABLE(scopeGuard) = MakeObjGuard
#endif

christopher (baus.net)
Thursday, July 22, 2004

' or 1 = 1

' and 1=1
Wednesday, July 28, 2004

*  Recent Topics

*  Fog Creek Home