https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109515
Bug ID: 109515 Summary: Diagnostic request: warning on out-of-order structured bindings names Product: gcc Version: 12.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: barry.revzin at gmail dot com Target Milestone: --- Consider this example: struct div_t { int quot; int rem; }; auto div(int, int) -> div_t; int main() { auto [rem, quot] = div(1, 2); return quot; } I'm using structured bindings, but div_t's members are in the order quot then rem, but I accidentally typed rem then quot. This is a bug! Currently, nobody warns here though. At the very least, if I'm: (a) using a name in a structured binding, (b) where we fall into the 3rd case of structured bindings (struct, not array/tuple), (c) the name I'm using is the name of one of the members of the type, and (d) the structured binding is in the wrong place I think that's a situation where a warning would have a low false-positive rate, could be a useful -Wall (or at least -Wextra) kind of warning. There's a more expansive potential diagnostic, if I used names that weren't names of members at all, but I think that sort of warning would have to be opt-in.