[clang] 4de0680 - Fix use of pointer arithmetic instead of iterators.

Manuel Klimek via cfe-commits cfe-commits at lists.llvm.org
Tue Jul 5 01:26:22 PDT 2022


Author: Manuel Klimek
Date: 2022-07-05T08:23:42Z
New Revision: 4de0680fbf4e4a9b9136ab5ee1ca549954eb8590

URL: https://github.com/llvm/llvm-project/commit/4de0680fbf4e4a9b9136ab5ee1ca549954eb8590
DIFF: https://github.com/llvm/llvm-project/commit/4de0680fbf4e4a9b9136ab5ee1ca549954eb8590.diff

LOG: Fix use of pointer arithmetic instead of iterators.

Added: 
    

Modified: 
    clang/lib/Format/UnwrappedLineParser.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp
index d3383292f7a38..97c3d86282a02 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -15,6 +15,7 @@
 #include "UnwrappedLineParser.h"
 #include "FormatToken.h"
 #include "TokenAnnotator.h"
+#include "clang/Basic/TokenKinds.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/raw_ostream.h"
@@ -1910,15 +1911,12 @@ void UnwrappedLineParser::parseStructuralElement(
         break;
 
       auto OneTokenSoFar = [&]() {
-        const UnwrappedLineNode *Tok = &Line->Tokens.front(),
-                                *End = Tok + Line->Tokens.size();
-        while (Tok != End && Tok->Tok->is(tok::comment))
-          ++Tok;
-        // In Verilog, macro invocations start with a backtick which the code
-        // treats as a hash.  Skip it.
-        if (Style.isVerilog() && Tok != End && Tok->Tok->is(tok::hash))
-          ++Tok;
-        return End - Tok == 1;
+        auto I = Line->Tokens.begin(), E = Line->Tokens.end();
+        while (I != E && I->Tok->is(tok::comment))
+          ++I;
+        while (I != E && Style.isVerilog() && I->Tok->is(tok::hash))
+          ++I;
+        return I != E && (++I == E);
       };
       if (OneTokenSoFar()) {
         if (FormatTok->is(tok::colon) && !Line->MustBeDeclaration) {


        


More information about the cfe-commits mailing list