https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108257
Bug ID: 108257 Summary: Incorrect (non-unique) mangling of structured binding's backing variable Product: gcc Version: 13.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: arthur.j.odwyer at gmail dot com Target Milestone: --- C++20 permits structured bindings (decomposition declarations) to be `static`. This means we can use them in inline functions, where they need to be mangled in the context of that inline function. Clang seems to get this right; GCC forgets to include the context. // https://godbolt.org/z/aKanscav3 struct A { int x,y; }; inline int f() { static auto [a,b] = A{1,2}; return a; } inline int g() { static auto [a,b] = A{3,4}; return a; } int (*pf)() = f; int (*pg)() = g; int main() { printf("%d %d\n", f(), g()); printf("%d %d\n", pf(), pg()); } This program should print "1 3" twice. On GCC, it fails to assemble, because the symbol name `_ZNDC1a1bEE` is used for both backing variables. On Clang, the symbol names are `_ZZ1fvEDC1a1bE` and `_ZZ1gvEDC1a1bE` instead. (Totally off-topic, it is awful that the name of the backing variable includes all of the names of the individual bindings, concatenated. That can easily produce humongous symbol names, and interacts unusually poorly with (UB) macro-expansion. If anyone wants to go talk to the Itanium ABI folks and get everyone to switch to a simple "mangling number" scheme like we have already built for lambda closure types, that would be awesome. Notice that you already need a "mangling number" scheme *on top* of the current design, because of https://godbolt.org/z/cYqxzxfxe — so I'm just proposing to make the scheme simpler, if the Itanium ABI folks are willing to change it.)