On Sunday, 7 January 2018 at 00:22:15 UTC, H. S. Teoh wrote:
On Sun, Jan 07, 2018 at 12:18:27AM +0000, Ivan Trombley via Digitalmars-d wrote:
While working with SDL, I found that I kept using the same pattern over and
over:
- Get the current clip rectangle.
- Set a new clip rectangle.
- restore the old clip rectangle on scope (exit).

Instead of writing that code again and again, I wrote a simple function that returns a struct which restores the old clip rectangle in it's destructor. This works great but now dscanner complains about the variable being unused.

Is there a way tell dscanner that a variable is intentionally unused?

IMO, dscanner should be fixed to suppress that warning when the variable in question has a non-trivial dtor that may produce side-effects at the end of the scope. In such cases, it may be that the whole reason for the variable is to trigger the dtor's side-effects, as is your case here, so technically it isn't "unused".


T

Unfortunately this is not possible without a big refactoring. The struct can be declared in another module and D-Scanner only sees the VariableDeclaration because its scope is limited to the current module.

Reply via email to