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 05:19:20 PDT 2016


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.

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;
   }




More information about the cfe-commits mailing list