[PATCH] D70144: clang-tidy: modernize-use-equals-default avoid adding redundant semicolons

Jonas Toth via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Nov 13 08:27:42 PST 2019


JonasToth added inline comments.


================
Comment at: clang-tools-extra/clang-tidy/modernize/UseEqualsDefaultCheck.cpp:306
+  if (ApplyFix) {
+    // Peek ahead to see if there's a semicolon after Body->getSourceRange()
+    Optional<Token> Token;
----------------
poelmanc wrote:
> JonasToth wrote:
> > There should be utility code in `clang-tidy/util/` that deals with custom lexing, that should be able to do the job.
> Thanks for the quick feedback! I looked there and couldn't find a utility function that searched (a) //forward// rather than backwards, and (b) for any token //not// of a given list of types. Here's a new helper function that could be placed in LexerUtils.h if you think it's generally useful:
> 
> ```
> // Analogous to findNextAnyTokenKind, finds next token not of
> // the given set of TokenKinds. Useful for skipping comments.
> template <typename TokenKind, typename... TokenKinds>
> Optional<Token> findNextTokenSkippingKind(SourceLocation Start,
>                                           const SourceManager &SM,
>                                           const LangOptions &LangOpts,
>                                           TokenKind TK, TokenKinds... TKs) {
>   Optional<Token> CurrentToken;
>   do {
>     Optional<Token> CurrentToken = Lexer::findNextToken(Start, SM, LangOpts);
>   } while (CurrentToken && CurrentToken.isOneOf(TK, TKs...));
>   return CurrentToken;
> }
> ```
> 
> Then the `do` loop below can be simplified to:
> ```
>   Optional<Token> Token = findNextTokenSkippingKind(
>           Body->getSourceRange().getEnd().getLocWithOffset(1),
>           Result.Context->getSourceManager(), Result.Context->getLangOpts(),
>           tok::comment);
> ```
There is `findNextAnyTokenKind`, not sure if it is actually practical to use in this case.

You can implement a skipping function as well. I think that is useful in other contexts (I recall that I had to do similiar skipping already at some point, not sure where it was :( )


Repository:
  rCTE Clang Tools Extra

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

https://reviews.llvm.org/D70144





More information about the cfe-commits mailing list