This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Strange warning in C++11 range based for loop
- From: Pavel Dzhioev <dzhioev at gmail dot com>
- To: gcc-help at gcc dot gnu dot org
- Date: Tue, 30 Aug 2011 17:58:29 +0400
- Subject: Strange warning in C++11 range based for loop
Hello!
I have some class, that allows to iterate through numeric range.
For example code:
> for (int i: range(N)) {
> Â Âcout << i << endl;
> }
works fine. But if I try repeatedly do some action:
> for (int i: range(N)) {
> Â ÂdoSomething();
> }
compiler gives me warning:
> warning: unused variable `i' [-Wunused-variable]
But at same time classic for-loop:
> for (int i =3D 0; i < N; ++i) {
> Â Â doSomething();
> }
compiles without warnings.
My compiler's version is "g++-4.6 (GCC) 4.6.1", compiler flags
"--std=c++0x -Wall"
I'm wondering, is it planned behavior or bug?
Thank you for help.
--
Pavel Sergeev