From 5b37cddff8e0140420ad776066529cf8f41d64d2 Mon Sep 17 00:00:00 2001 From: Carlos Galvez Date: Wed, 25 Jan 2023 05:26:07 +0000 Subject: [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 --- .../clang-tidy/misc/UseAnonymousNamespaceCheck.cpp | 25 +++++++++++++--------- 1 file changed, 15 insertions(+), 10 deletions(-) (limited to 'clang-tools-extra/clang-tidy/misc/UseAnonymousNamespaceCheck.cpp') 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 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( -- cgit v1.1