This is an archive of the discontinued LLVM Phabricator instance.

[clang-tidy] Added virtual isLanguageVersionSupported to ClangTidyCheck
ClosedPublic

Authored by njames93 on Feb 27 2020, 12:26 PM.

Details

Summary

Motivated by Tune inspections to a specific C++ standard.
Moves the isLanguageVersionSupported virtual function from MakeSmartPtrCheck to the base ClangTidyCheck class.
This will disable registering matchers or pp callbacks on unsupported language versions for a check.
Having it as a standalone function is cleaner than manually disabling the check in the register function and should hopefully
encourage check developers to actually restrict the check based on language version.
As an added bonus this could enable automatic detection of what language version a check runs on for the purpose of documentation generation

Diff Detail

Event Timeline

njames93 created this revision.Feb 27 2020, 12:26 PM

Language and/or its standard is checked in other places too. Should all similar places be refactored?

Language and/or its standard is checked in other places too. Should all similar places be refactored?

They should but I feel they should be in follow up patches, the only reason MakeSmartPtrCheck is in here is because by coincidence it used the same name as what I planned and I got a compile warning about it.
I also don't know exactly where all occurrences are.

Language and/or its standard is checked in other places too. Should all similar places be refactored?

They should but I feel they should be in follow up patches, the only reason MakeSmartPtrCheck is in here is because by coincidence it used the same name as what I planned and I got a compile warning about it.
I also don't know exactly where all occurrences are.

Just grep for getLangOpts().

Language and/or its standard is checked in other places too. Should all similar places be refactored?

They should but I feel they should be in follow up patches, the only reason MakeSmartPtrCheck is in here is because by coincidence it used the same name as what I planned and I got a compile warning about it.
I also don't know exactly where all occurrences are.

Just grep for getLangOpts().

Thanks for that tip, I've put the full implementation in a child revision.

gribozavr2 accepted this revision.Feb 28 2020, 4:29 AM
gribozavr2 added inline comments.
clang-tools-extra/clang-tidy/ClangTidyCheck.h
86

Please update the doc comment on registerMatchers and registerPPCallbacks that there is now a precondition that isLanguageVersionSupported must return true.

This revision is now accepted and ready to land.Feb 28 2020, 4:29 AM
gribozavr2 added inline comments.Feb 28 2020, 4:35 AM
clang-tools-extra/clang-tidy/ClangTidyCheck.h
109

Not a critical thing, but I feel like it would be better to put isLanguageVersionSupported before register functions. That logical order makes more sense to a reader that is not familiar with the class.

njames93 updated this revision to Diff 247226.Feb 28 2020, 4:40 AM
  • Updated docs to include precondition
njames93 marked an inline comment as done.Feb 28 2020, 4:40 AM
njames93 updated this revision to Diff 247230.Feb 28 2020, 5:03 AM
njames93 marked an inline comment as done.
  • Moved isLanguageVersionSupported above register functions
This revision was automatically updated to reflect the committed changes.