This is an archive of the discontinued LLVM Phabricator instance.

[AST] Add new printing policy to suppress printing template arguments
AbandonedPublic

Authored by khuttun on Apr 2 2018, 6:13 AM.

Details

Reviewers
sepavloff
alexfh
Summary

The purpose of this addition is to be able to write AST matchers that match class template member functions by fully qualified name, without the need to explicitly specify the template arguments in the name.

For example, to match the call to S::f here

template <typename T>
struct S {
  void f();
};

void foo() {
  S<int> s;
  s.f();
}

the matcher currently needs to specify the template arguments:

callExpr(callee(functionDecl(hasName("::S<int>::f"))))

With the help of this change, it's possible to create a version of hasName that ignores the template arguments. The matcher could then be written as

callExpr(callee(functionDecl(hasNameIgnoringTemplateArgs("::S::f"))))

The motivation for this change is to be able to add checking of class template member functions to clang-tidy checker bugprone-unused-return-value: http://clang.llvm.org/extra/clang-tidy/checks/bugprone-unused-return-value.html

The discussion about this can be found in the code review for the checker: https://reviews.llvm.org/D41655?id=130461#inline-374438

Diff Detail

Event Timeline

khuttun created this revision.Apr 2 2018, 6:13 AM
khuttun abandoned this revision.Apr 3 2018, 11:06 AM

Figured out a better way to do this by using FunctionDecl::getInstantiatedFromMemberFunction