[PATCH] D18475: [clang-tidy] Add more detection rules for redundant c_str calls.

Samuel Benzaquen via cfe-commits cfe-commits at lists.llvm.org
Tue Mar 29 10:38:23 PDT 2016


sbenza added a comment.

In http://reviews.llvm.org/D18475#385789, @alexfh wrote:

> Looks good to me. Adding Samuel, since he has done a lot of similar stuff by now and might have good ideas on improving this and making this more general.


There are two things I've done before that might apply here.
First, you can move the function+arg into data and just loop through it to make the matchers.
Eg:

  struct Case {
    StringRef Func;
    unsigned Arg;
  };
  const Case Cases[] = {...};
  for (Case C : Cases) {
    Finder->addMatcher(...);
  }

This reduces the amount of code duplication.

Another thing I've done is to find matching overloads dynamically instead of hardcoding the list of functions.
The idea is that you match something like `callExpr(hasAnyArgument(StringCStrCallExpr))` and then you figure out if that function has a matching overload that takes `const string&` on that specific argument.
This is flexible, but might give false positives.


http://reviews.llvm.org/D18475





More information about the cfe-commits mailing list