[Bug c++/125697] New: Spurious -Wrange-loop-construct warning
junyi@hudson-trading.com
gcc-bugzilla@gcc.gnu.org
Tue Jun 9 19:25:44 GMT 2026
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125697
Bug ID: 125697
Summary: Spurious -Wrange-loop-construct warning
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: junyi@hudson-trading.com
Target Milestone: ---
The source code producing the warning:
```
template <typename> struct pair {
int first;
int second;
template <typename _U1> pair(const pair<_U1> &&);
};
void reproRangeLoopConstruct(const pair<int> (&arr)[1]) {
for (const auto x : arr)
;
}
static_assert(__is_trivially_copyable(pair<int>));
static_assert(sizeof(pair<int>) == 8);
```
The GCC version used:
```
Using built-in specs.
COLLECT_GCC=./gcc/xg++
Target: x86_64-pc-linux-gnu
Configured with: ../configure
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 17.0.0 20260609 (experimental) (GCC)
```
The output:
```
repro.cc: In function ‘void reproRangeLoopConstruct(const pair<int> (&)[1])’:
repro.cc:7:19: warning: loop variable ‘x’ creates a copy from type ‘const
pair<int>’ [-Wrange-loop-construct]
7 | for (const auto x : arr)
| ^
repro.cc:7:19: note: use reference type to prevent copying
7 | for (const auto x : arr)
| ^
| &
```
More information about the Gcc-bugs
mailing list