https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71402

--- Comment #5 from Martin Sebor <msebor at gcc dot gnu.org> ---
I understand that and agree that there is a set of use cases where users don't
expect a warning.  There is also another set of cases where a warning would be
helpful:  If the unused variable in the submitted test case were the result of
code changes that removed its uses and the variable was left defined
unintentionally, the user would be served by having this pointed out. 
Otherwise the dynamic initialization would waste resources.

Adding a new warning (let's call it -Wunused-varible-with-dynamic-initializer)
would be one way to provide the functionality that I think would be of use.

Another solution would be to issue the -Wunused-variable warning for the
submitted test case and recommend users to annotate otherwise unused variables
with attribute unused to suppress the warning.  This approach would also be in
line with the intended use of the new (in C++ 17) maybe_unused attribute
(proposed in WG21 document P0212R1).

Reply via email to