[PATCH] D63288: [clang-tidy] Generalize TransformerClangTidyCheck to take a rule generator.

Yitzhak Mandelbaum via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jun 25 12:06:05 PDT 2019


ymandel marked an inline comment as done.
ymandel added inline comments.


================
Comment at: clang-tools-extra/unittests/clang-tidy/TransformerClangTidyCheckTest.cpp:92
+  const std::string Input = "void log(int);";
+  EXPECT_EQ(Input, test::runCheckOnCode<NeedsC99Check>(Input));
+}
----------------
ymandel wrote:
> ymandel wrote:
> > gribozavr wrote:
> > > Would adding `-std=c99` to `ExtraArgs`, and setting `Filename` to `input.c` work?
> > No, nothing seems to work. I can't find a way to ever set bits in LangOptions. I'm rather confused why that's the case...
> I found the answer: getLangOpts() is not guaranteed to work at check-creation time. This makes sense, since a single check may be run against many different files.  I'd say its a flaw in the API though since it seems like a feature of the check, when its really a feature of the file. We should update the API to warn about this and possibly improve it to avoid the confusion.
> 
> I'll update the code to save the std::function and invoke at registerMatchers() time instead.
Never mind my previous point -- this only holds for the particular way that runCheckOnCode is implemented (which is arguably a bug). For the real clang tidy, LangOpts is a feature of the tool invocation and is therefore constant across the lifetime of the check.

I will send a change to runCheckOnCode that fixes this -- that is, ensures LangOpts is set *before* the Check is constructed, and then this will work correctly.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63288





More information about the cfe-commits mailing list