[PATCH] D146881: [clang-tidy] Fix findNextTokenSkippingComments & rangeContainsExpansionsOrDirectives

Piotr Zegar via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sat Apr 1 03:21:31 PDT 2023


PiotrZSL added inline comments.


================
Comment at: clang-tools-extra/clang-tidy/utils/LexerUtils.cpp:84-85
+        Lexer::findNextToken(Start, SM, LangOpts);
+    if (!CurrentToken || !CurrentToken->is(tok::comment))
+      return CurrentToken;
+
----------------
carlosgalvezp wrote:
> I'm not sure this logic is correct - `if (CurrentToken` is there to ensure that `CurrentToken` is not a nullopt before dereferencing via `CurrentToken->is`. It should be:
> 
> ```
> if (CurrentToken && !CurrentToken->is(tok::comment))
>   return CurrentToken;
> ```
Current code is correct, it's inversion of what we had in while, simply if no token, or token is not comment, then leave.


================
Comment at: clang-tools-extra/clang-tidy/utils/LexerUtils.cpp:99
 
-  while (Loc < Range.getEnd()) {
+  while (Loc <= Range.getEnd()) {
     if (Loc.isMacroID())
----------------
carlosgalvezp wrote:
> This is a bit unintuitive if we compare it with e.g. STL iterators - `end()` is always "one-past" the end. What's the convention for `SourceRange`, does `end` contain a valid end range, or one-past-the-end?
In SourceRange end is pointing to last token, not to last token + 1.
This is inclusive range.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D146881/new/

https://reviews.llvm.org/D146881



More information about the cfe-commits mailing list