This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]