[PATCH] D56160: [clang-tidy] modernize-use-trailing-return-type check

Bernhard Manfred Gruber via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sat May 4 08:28:34 PDT 2019


bernhardmgruber updated this revision to Diff 198143.
bernhardmgruber marked 9 inline comments as done.
bernhardmgruber added a comment.

It took a long while to figure out how to handle certain macro cases. Here is what I came up with:

When tokenizing the source code from the beginning of the function to the function name, I now use clang's `Preprocessor` to lex these tokens again and expand macros on the way. I analyse the top-level macros if they just contain specifiers or qualifiers and store this information in a `ClassifiedToken`. When I later try to expand the return type location to include qualifiers, or when I want to remove specifiers from the return type range, I can use this information to also include/reprosition macros which I can regard as qualifiers or specifiers. This currently solves a lot of cases where macros are part of the return type.

Function style macros as part of the return type are not supported, as they are harder to lex and expand. The check currently provides no fixit in these cases.

Other changes:

- `expandIfMacroId()` now expands recursively because the `SourceLocation` might be inside nested macros
- renamed `nonMacroTokensBeforeFunctionName()` into `classifyTokensBeforeFunctionName()`
- improved some comments
- overriding `registerPPCallbacks` to hijack a reference to the preprocessor
- expanding macro ids in the initial return type source range gotten from the `FunctionDecl`


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

https://reviews.llvm.org/D56160

Files:
  clang-tidy/modernize/CMakeLists.txt
  clang-tidy/modernize/ModernizeTidyModule.cpp
  clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp
  clang-tidy/modernize/UseTrailingReturnTypeCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/modernize-use-trailing-return-type.rst
  test/clang-tidy/modernize-use-trailing-return-type.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D56160.198143.patch
Type: text/x-patch
Size: 57727 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190504/87cf55d7/attachment-0001.bin>


More information about the cfe-commits mailing list