[Bug c++/116731] Incorrect behavior of -Wrange-loop-construct in GCC 14
rogerio.souza at gmail dot com
gcc-bugzilla@gcc.gnu.org
Fri Dec 19 20:08:12 GMT 2025
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116731
--- Comment #17 from Rogério de Souza Moraes <rogerio.souza at gmail dot com> ---
This issue still happens on GCC 14.3 and 15.2. With small changes the warning
is raised again when using -std=c++23 and -std=c++26.
Example (https://godbolt.org/z/1jha8rqzY):
******************************************
#include <unordered_map>
int main() {
const std::unordered_map<int, int> m;
for (const auto _: m) {}
}
******************************************
Log message:
<source>: In function 'int main()':
<source>:5:21: warning: loop variable '_' creates a copy from type 'const
std::pair<const int, int>' [-Wrange-loop-construct]
5 | for (const auto _: m) {}
| ^
<source>:5:21: note: use reference type to prevent copying
5 | for (const auto _: m) {}
| ^
| &
ASM generation compiler returned: 0
<source>: In function 'int main()':
<source>:5:21: warning: loop variable '_' creates a copy from type 'const
std::pair<const int, int>' [-Wrange-loop-construct]
5 | for (const auto _: m) {}
| ^
<source>:5:21: note: use reference type to prevent copying
5 | for (const auto _: m) {}
| ^
| &
Should I file a new bugzilla?
Regards,
Rogerio
More information about the Gcc-bugs
mailing list