digitalmars.D - Dscanner: intentionally unused variable
- Ivan Trombley (11/11) Jan 06 2018 While working with SDL, I found that I kept using the same
- H. S. Teoh (9/21) Jan 06 2018 IMO, dscanner should be fixed to suppress that warning when the variable
- Basile B. (5/28) Jan 07 2018 Unfortunately this is not possible without a big refactoring. The
- SimonN (8/19) Jan 06 2018 Another way would be to have the RAII wrapper in a with
- Ivan Trombley (2/9) Jan 07 2018 This works good enough. Thanks.
- Basile B. (7/18) Jan 07 2018 You can disable the "unused variable check" for the module in the
- Ivan Trombley (4/7) Jan 07 2018 If the output is clogged with warnings then it's more difficult
- Jacob Carlborg (6/18) Jan 07 2018 I don't know about D-Scanner but I know that other similar tools allow
- visitor (3/10) Jan 07 2018 It seems a simple underscore "_" as a variable name tells
- visitor (2/13) Jan 07 2018 Any number of underscores but underscores only apparently.
- Ivan Trombley (2/5) Jan 07 2018 That works too. Thanks.
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?
Jan 06 2018
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 -- Don't throw out the baby with the bathwater. Use your hands...
Jan 06 2018
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: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.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
Jan 07 2018
On Sunday, 7 January 2018 at 00:18:27 UTC, Ivan Trombley 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?Another way would be to have the RAII wrapper in a with statement, but it produces extra indentation, which you might not like: with (MyStruct(100, 200)) { // code that uses the new clip rectangle } -- Simon
Jan 06 2018
On Sunday, 7 January 2018 at 03:41:18 UTC, SimonN wrote:Another way would be to have the RAII wrapper in a with statement, but it produces extra indentation, which you might not like: with (MyStruct(100, 200)) { // code that uses the new clip rectangle } -- SimonThis works good enough. Thanks.
Jan 07 2018
On Sunday, 7 January 2018 at 00:18:27 UTC, Ivan Trombley 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?You can disable the "unused variable check" for the module in the dscanner.ini file located in the project directory see https://github.com/dlang-community/D-Scanner#selecting-modules-for-a-specific-check. More simple is to understand D-Scanner limitations and accept that warnings are only warnings and that a message doesn't necessarily mean that there's something to do.
Jan 07 2018
On Sunday, 7 January 2018 at 08:46:40 UTC, Basile B. wrote:More simple is to understand D-Scanner limitations and accept that warnings are only warnings and that a message doesn't necessarily mean that there's something to do.If the output is clogged with warnings then it's more difficult to see the actual issues, limiting the value of dscanner. It makes sense to try to find a reasonable solution.
Jan 07 2018
On 2018-01-07 01:18, Ivan Trombley 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?I don't know about D-Scanner but I know that other similar tools allow you to prefix the name of a variable with an underscore to indicate that the variable is intentionally unused. -- /Jacob Carlborg
Jan 07 2018
On Sunday, 7 January 2018 at 16:14:11 UTC, Jacob Carlborg wrote:On 2018-01-07 01:18, Ivan Trombley wrote:It seems a simple underscore "_" as a variable name tells Dscanner exactly that.Is there a way tell dscanner that a variable is intentionally unused?I don't know about D-Scanner but I know that other similar tools allow you to prefix the name of a variable with an underscore to indicate that the variable is intentionally unused.
Jan 07 2018
On Sunday, 7 January 2018 at 16:29:42 UTC, visitor wrote:On Sunday, 7 January 2018 at 16:14:11 UTC, Jacob Carlborg wrote:Any number of underscores but underscores only apparently.On 2018-01-07 01:18, Ivan Trombley wrote:It seems a simple underscore "_" as a variable name tells Dscanner exactly that.Is there a way tell dscanner that a variable is intentionally unused?I don't know about D-Scanner but I know that other similar tools allow you to prefix the name of a variable with an underscore to indicate that the variable is intentionally unused.
Jan 07 2018
On Sunday, 7 January 2018 at 17:02:02 UTC, visitor wrote:That works too. Thanks.It seems a simple underscore "_" as a variable name tells Dscanner exactly that.Any number of underscores but underscores only apparently.
Jan 07 2018