Propose warnings for partially-unused structured bindings in C++26.
In C++26, enable `-Wunused` warnings for unused variables in structured bindings, now that unnamed placeholders are available.
Ionuț Nicula proposes enabling -Wunused warnings for structured bindings in C++26 mode when some sub-objects are unused. Before C++26, the lack of a placeholder variable (like _) made this awkward. This change could catch errors, particularly in loops where a variable is unintentionally unused due to copy-paste mistakes.
In Details
Structured bindings decompose tuples/structs into individual variables. -Wunused flags unused local variables, but not if the variable is part of a structured binding. C++26 allows auto [_, x, _] = ... to explicitly mark elements as unused, which unblocks the new warning.
For Context
Structured bindings in C++ allow you to unpack the elements of a tuple or struct into individual variables (e.g., auto [x, y, z] = my_tuple;). GCC's -Wunused flag warns about unused variables. This proposal suggests extending -Wunused to detect when only some elements of a structured binding are used, which can indicate a programming error.