forked from OSchip/llvm-project
[clang-tidy] prevent generated checks from triggering assertions on anonymous functions
Skeleton checks generated by clang-tidy add_check.py cause assertions to fail when run over anonymous functions(lambda functions). This patch introduces an additional check to verify that the target function is not anonymous before calling getName(). The code snippet from the [[ https://clang.llvm.org/extra/clang-tidy/Contributing.html | clang-tidy tutorial ]]is also updated. Reviewed By: alexfh, DavidTruby Differential Revision: https://reviews.llvm.org/D85218
This commit is contained in:
parent
9bd97d0363
commit
35bee3503f
|
@ -136,7 +136,7 @@ void %(check_name)s::registerMatchers(MatchFinder *Finder) {
|
|||
void %(check_name)s::check(const MatchFinder::MatchResult &Result) {
|
||||
// FIXME: Add callback implementation.
|
||||
const auto *MatchedDecl = Result.Nodes.getNodeAs<FunctionDecl>("x");
|
||||
if (MatchedDecl->getName().startswith("awesome_"))
|
||||
if (!MatchedDecl->getIdentifier() || MatchedDecl->getName().startswith("awesome_"))
|
||||
return;
|
||||
diag(MatchedDecl->getLocation(), "function %%0 is insufficiently awesome")
|
||||
<< MatchedDecl;
|
||||
|
|
|
@ -202,7 +202,7 @@ can further inspect them and report diagnostics.
|
|||
|
||||
void AwesomeFunctionNamesCheck::check(const MatchFinder::MatchResult &Result) {
|
||||
const auto *MatchedDecl = Result.Nodes.getNodeAs<FunctionDecl>("x");
|
||||
if (MatchedDecl->getName().startswith("awesome_"))
|
||||
if (!MatchedDecl->getIdentifier() || MatchedDecl->getName().startswith("awesome_"))
|
||||
return;
|
||||
diag(MatchedDecl->getLocation(), "function %0 is insufficiently awesome")
|
||||
<< MatchedDecl
|
||||
|
|
Loading…
Reference in New Issue