aboutsummaryrefslogtreecommitdiff
path: root/clang-tools-extra/clang-tidy/misc/UseAnonymousNamespaceCheck.cpp
diff options
context:
space:
mode:
authorCarlos Galvez <carlosgalvezp@gmail.com>2023-01-25 05:26:07 +0000
committerCarlos Galvez <carlosgalvezp@gmail.com>2023-02-19 13:44:11 +0000
commit5b37cddff8e0140420ad776066529cf8f41d64d2 (patch)
treee217c546cd0c7f193d6b354c38a800bf2a49417d /clang-tools-extra/clang-tidy/misc/UseAnonymousNamespaceCheck.cpp
parent1235ed913356d493563d730cb7997bcca633397d (diff)
downloadllvm-5b37cddff8e0140420ad776066529cf8f41d64d2.zip
llvm-5b37cddff8e0140420ad776066529cf8f41d64d2.tar.gz
llvm-5b37cddff8e0140420ad776066529cf8f41d64d2.tar.bz2
[clang-tidy] Introduce HeaderFileExtensions and ImplementationFileExtensions options
Re-introduce the patch that was reverted previously. In the first attempt, the checks would not be able to read from the global option, since getLocalOrGlobal only works with string types. Additional logic is needed in order to support both use cases in the transition period. All that logic will be removed when the local options are fully removed. We have a number of checks designed to analyze problems in header files only, for example: bugprone-suspicious-include google-build-namespaces llvm-header-guard misc-definitions-in-header ... All these checks duplicate the same logic and options to determine whether a location is placed in the main source file or in the header. More checks are coming up with similar requirements. Thus, to remove duplication, let's move this option to the top-level configuration of clang-tidy (since it's something all checks should share). Add a deprecation notice for all checks that use the local option, prompting to update to the global option. Differential Revision: https://reviews.llvm.org/D142655
Diffstat (limited to 'clang-tools-extra/clang-tidy/misc/UseAnonymousNamespaceCheck.cpp')
-rw-r--r--clang-tools-extra/clang-tidy/misc/UseAnonymousNamespaceCheck.cpp25
1 files changed, 15 insertions, 10 deletions
diff --git a/clang-tools-extra/clang-tidy/misc/UseAnonymousNamespaceCheck.cpp b/clang-tools-extra/clang-tidy/misc/UseAnonymousNamespaceCheck.cpp
index 7e4bba2..a6337f5 100644
--- a/clang-tools-extra/clang-tidy/misc/UseAnonymousNamespaceCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/UseAnonymousNamespaceCheck.cpp
@@ -17,7 +17,7 @@ namespace {
AST_POLYMORPHIC_MATCHER_P(isInHeaderFile,
AST_POLYMORPHIC_SUPPORTED_TYPES(FunctionDecl,
VarDecl),
- utils::FileExtensionsSet, HeaderFileExtensions) {
+ FileExtensionsSet, HeaderFileExtensions) {
return utils::isExpansionLocInHeaderFile(
Node.getBeginLoc(), Finder->getASTContext().getSourceManager(),
HeaderFileExtensions);
@@ -31,15 +31,20 @@ AST_MATCHER(VarDecl, isStaticDataMember) { return Node.isStaticDataMember(); }
UseAnonymousNamespaceCheck::UseAnonymousNamespaceCheck(
StringRef Name, ClangTidyContext *Context)
- : ClangTidyCheck(Name, Context),
- RawStringHeaderFileExtensions(Options.getLocalOrGlobal(
- "HeaderFileExtensions", utils::defaultHeaderFileExtensions())) {
- if (!utils::parseFileExtensions(RawStringHeaderFileExtensions,
- HeaderFileExtensions,
- utils::defaultFileExtensionDelimiters())) {
- this->configurationDiag("Invalid header file extension: '%0'")
- << RawStringHeaderFileExtensions;
- }
+ : ClangTidyCheck(Name, Context) {
+ std::optional<StringRef> HeaderFileExtensionsOption =
+ Options.get("HeaderFileExtensions");
+ RawStringHeaderFileExtensions =
+ HeaderFileExtensionsOption.value_or(utils::defaultHeaderFileExtensions());
+ if (HeaderFileExtensionsOption) {
+ if (!utils::parseFileExtensions(RawStringHeaderFileExtensions,
+ HeaderFileExtensions,
+ utils::defaultFileExtensionDelimiters())) {
+ this->configurationDiag("Invalid header file extension: '%0'")
+ << RawStringHeaderFileExtensions;
+ }
+ } else
+ HeaderFileExtensions = Context->getHeaderFileExtensions();
}
void UseAnonymousNamespaceCheck::storeOptions(