In Visual Studio, I often use objects only for RAII purposes. For example:
ScopeGuard close_guard = MakeGuard( &close_file, file );
The whole purpose of *close_guard* is to make sure that the file will be close on function exit, it is not used anywhere else. However, Visual Studio gives me a warning that a "local variable is initialized but not referenced". I want to turn this warning off for this specific case.
How do you deal with this kind of situation? Visual Studio thinks that this object is useless, but this is wrong since it has a non-trivial destructor.
I wouldn't want to use a #pragma warning directive for this since it would turn off this warning even for legitimate reasons.