[PATCH] D146881: [clang-tidy] Fix findNextTokenSkippingComments & rangeContainsExpansionsOrDirectives
Carlos Galvez via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sat Apr 1 02:27:12 PDT 2023
carlosgalvezp added a comment.
I'm surprised we don't have unit tests that catch this?
================
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;
+
----------------
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;
```
================
Comment at: clang-tools-extra/clang-tidy/utils/LexerUtils.cpp:99
- while (Loc < Range.getEnd()) {
+ while (Loc <= Range.getEnd()) {
if (Loc.isMacroID())
----------------
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?
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