r265934 - [clang-format] Walk backwards from end() instead of forwards from rend().

Benjamin Kramer via cfe-commits cfe-commits at lists.llvm.org
Mon Apr 11 10:02:56 PDT 2016


On Mon, Apr 11, 2016 at 6:48 PM, David Blaikie <dblaikie at gmail.com> wrote:
>
>
> On Mon, Apr 11, 2016 at 5:19 AM, Benjamin Kramer via cfe-commits
> <cfe-commits at lists.llvm.org> wrote:
>>
>> Author: d0k
>> Date: Mon Apr 11 07:19:19 2016
>> New Revision: 265934
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=265934&view=rev
>> Log:
>> [clang-format] Walk backwards from end() instead of forwards from rend().
>>
>> This should've been forwards from rbegin(), reverse iterators are just
>> too confusing to be used by mere mortals. Fixes out-of-bounds walks over
>> the list.
>
>
> Was/is the 2 correct then? (if it was next(rbegin, 2) that'd be equivalent
> to prev(end, 3), yes?)

I think it is from looking at the test case, looping in martin to see
whether I'm right :)

>>
>>
>> Modified:
>>     cfe/trunk/lib/Format/UnwrappedLineParser.cpp
>>
>> Modified: cfe/trunk/lib/Format/UnwrappedLineParser.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/UnwrappedLineParser.cpp?rev=265934&r1=265933&r2=265934&view=diff
>>
>> ==============================================================================
>> --- cfe/trunk/lib/Format/UnwrappedLineParser.cpp (original)
>> +++ cfe/trunk/lib/Format/UnwrappedLineParser.cpp Mon Apr 11 07:19:19 2016
>> @@ -718,7 +718,7 @@ void UnwrappedLineParser::readTokenWithJ
>>    if (PreviousMustBeValue && Line && Line->Tokens.size() > 1) {
>>      // If the token before the previous one is an '@', the previous token
>> is an
>>      // annotation and can precede another identifier/value.
>> -    const FormatToken *PrePrevious = std::next(Line->Tokens.rend(),
>> 2)->Tok;
>> +    const FormatToken *PrePrevious = std::prev(Line->Tokens.end(),
>> 2)->Tok;
>>      if (PrePrevious->is(tok::at))
>>        return;
>>    }
>>
>>
>> _______________________________________________
>> cfe-commits mailing list
>> cfe-commits at lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
>


More information about the cfe-commits mailing list