https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119334
Bug ID: 119334 Summary: error: loop variable '<structured bindings>' creates a copy from type 'const std::pair<int, int>' [-Werror=range-loop-construct] Product: gcc Version: 14.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: rogerio.souza at gmail dot com Target Milestone: --- The code below returns the warning "<source>:10:21: warning: loop variable '<structured bindings>' creates a copy from type 'const std::pair<int, int>' [-Wrange-loop-construct]" from GCC 11.0 to 14.2. Using GCC from trunk the warning is not raised. I used all levels of optimization and all have failed. The command line to reproduce is "g++ -fpic -std=c++17 -pthread -O3 -Wall -DNDEBUG". Below is the source code "https://godbolt.org/z/5TeaqoEen": *********************************** #include <vector> #include <utility> void bar(int x, int y); std::vector<std::pair<int, int>> v; void foo() { for (const auto [x, y] : v) bar(x, y); for (const auto p : v) bar(p.first, p.second); } *********************************** Regards, Rogerio