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

Conrad Poelman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Nov 13 08:09:45 PST 2019


poelmanc marked an inline comment as done.
poelmanc 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;
----------------
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);
```


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