microsoft / GSL

Guidelines Support Library
Other
6.13k stars 737 forks source link

final_action has an unused class member #1065

Closed diamante0018 closed 1 year ago

diamante0018 commented 1 year ago

Hello All, The class final_action has a private member called invoke of type bool. If I'm reading the source code correctly, this variable is only assigned the value 'true' but it is never used afterwards. In other words, it is only assigned a value but it is never read from.

https://github.com/microsoft/GSL/blob/7d49d4b45d2cc37171351268c6cce43c32dc28a0/include/gsl/util#L83

Should it be removed if it has no use? Thanks for your attention.

P.S. If it turns out this variable can be removed, or perhaps the source code could use an update to explain the existence of an unused variable with a comment, let me know so I may open a pull request as I would like to contribute.

beinhaerter commented 1 year ago

This std::exchange writes false to invoke.

diamante0018 commented 1 year ago

I see. That was very silly of me not to notice it. I didn't understand the purpose of that code but I now understand the purpose of invoke. Seems to be there to avoid double execution of the final action. Thanks for the clarification.