Author: owenca
Date: 2022-01-07T21:12:18-08:00
New Revision: d97025ad3a70c322843232036e2a11598b9fb9a6

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

LOG: [clang-format][NFC] Fix a bug in getPreviousToken() in the parser

Differential Revision: https://reviews.llvm.org/D116318

Added: 
    

Modified: 
    clang/lib/Format/UnwrappedLineParser.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index 2bf5cedd2ae4c..c1c87c776f714 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -32,7 +32,7 @@ class FormatTokenSource {
   // Returns the next token in the token stream.
   virtual FormatToken *getNextToken() = 0;
 
-  // Returns the token precedint the token returned by the last call to
+  // Returns the token preceding the token returned by the last call to
   // getNextToken() in the token stream, or nullptr if no such token exists.
   virtual FormatToken *getPreviousToken() = 0;
 
@@ -246,8 +246,7 @@ class IndexedTokenSource : public FormatTokenSource {
   }
 
   FormatToken *getPreviousToken() override {
-    assert(Position > 0);
-    return Tokens[Position - 1];
+    return Position > 0 ? Tokens[Position - 1] : nullptr;
   }
 
   FormatToken *peekNextToken() override {


        
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to