Re: Strange warning in C++11 range based for loop

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 30 August 2011 17:46, Pavel Dzhioev wrote:
> I have changed my opinion, after reading standart draft. It says:
>> The range-based for statement
>>     for ( for-range-declaration : expression ) statement
>> is equivalent to
>> {
>>    auto && __range = ( expression );
>>    for ( auto __begin = begin-expr, __end = end-expr; __begin != __end; ++__begin )
>>    {
>>          for-range-declaration = *__begin;
>>          statement
>>    }
>>}
> So formally `i' is unused variable in my case.

Formally, yes, but the grammar does not allow you to omit the name, as in:

  for (auto : range(N))

or even
  for (: range(N))

and your example is reasonable, so I can see an argument for disabling
the warning.

On the other hand, it could be useful sometimes:

for (auto i : get_range())
{
    for (auto j : get_range2(i))
    {
        frobnicate(i);   // OOPS should be frobnicate(j)
    }
}

Here it might be useful to be warned that 'j' is unused



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux