diff --git a/clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.h b/clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.h --- a/clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.h +++ b/clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.h @@ -19,11 +19,12 @@ /// Finds dynamically initialized static variables in header files. /// /// The check supports these options: -/// - `HeaderFileExtensions`: a comma-separated list of filename extensions of -/// header files (The filename extensions should not contain "." prefix). -/// "h,hh,hpp,hxx" by default. +/// - `HeaderFileExtensions`: a semicolon-separated list of filename +/// extensions of header files (The filename extensions should not contain +/// "." prefix). ";h;hh;hpp;hxx" by default. +// /// For extension-less header files, using an empty string or leaving an -/// empty string between "," if there are other filename extensions. +/// empty string between ";" if there are other filename extensions. class DynamicStaticInitializersCheck : public ClangTidyCheck { public: DynamicStaticInitializersCheck(StringRef Name, ClangTidyContext *Context); diff --git a/clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.cpp --- a/clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.cpp @@ -32,7 +32,8 @@ RawStringHeaderFileExtensions(Options.getLocalOrGlobal( "HeaderFileExtensions", utils::defaultHeaderFileExtensions())) { if (!utils::parseFileExtensions(RawStringHeaderFileExtensions, - HeaderFileExtensions, ',')) { + HeaderFileExtensions, + utils::defaultFileExtensionDelimiters())) { llvm::errs() << "Invalid header file extension: " << RawStringHeaderFileExtensions << "\n"; } diff --git a/clang-tools-extra/clang-tidy/google/GlobalNamesInHeadersCheck.h b/clang-tools-extra/clang-tidy/google/GlobalNamesInHeadersCheck.h --- a/clang-tools-extra/clang-tidy/google/GlobalNamesInHeadersCheck.h +++ b/clang-tools-extra/clang-tidy/google/GlobalNamesInHeadersCheck.h @@ -21,11 +21,12 @@ /// Right now it only triggers on using declarations and directives. /// /// The check supports these options: -/// - `HeaderFileExtensions`: a comma-separated list of filename extensions -/// of header files (the filename extensions should not contain "." prefix). -/// "h" by default. +/// - `HeaderFileExtensions`: a semicolon-separated list of filename +/// extensions of header files (the filename extensions should not contain +/// "." prefix). ";h;hh;hpp;hxx" by default. +/// /// For extension-less header files, using an empty string or leaving an -/// empty string between "," if there are other filename extensions. +/// empty string between ";" if there are other filename extensions. class GlobalNamesInHeadersCheck : public ClangTidyCheck { public: GlobalNamesInHeadersCheck(StringRef Name, ClangTidyContext *Context); diff --git a/clang-tools-extra/clang-tidy/google/GlobalNamesInHeadersCheck.cpp b/clang-tools-extra/clang-tidy/google/GlobalNamesInHeadersCheck.cpp --- a/clang-tools-extra/clang-tidy/google/GlobalNamesInHeadersCheck.cpp +++ b/clang-tools-extra/clang-tidy/google/GlobalNamesInHeadersCheck.cpp @@ -25,7 +25,8 @@ RawStringHeaderFileExtensions(Options.getLocalOrGlobal( "HeaderFileExtensions", utils::defaultHeaderFileExtensions())) { if (!utils::parseFileExtensions(RawStringHeaderFileExtensions, - HeaderFileExtensions, ',')) { + HeaderFileExtensions, + utils::defaultFileExtensionDelimiters())) { llvm::errs() << "Invalid header file extension: " << RawStringHeaderFileExtensions << "\n"; } diff --git a/clang-tools-extra/clang-tidy/google/UnnamedNamespaceInHeaderCheck.h b/clang-tools-extra/clang-tidy/google/UnnamedNamespaceInHeaderCheck.h --- a/clang-tools-extra/clang-tidy/google/UnnamedNamespaceInHeaderCheck.h +++ b/clang-tools-extra/clang-tidy/google/UnnamedNamespaceInHeaderCheck.h @@ -20,11 +20,12 @@ /// Finds anonymous namespaces in headers. /// /// The check supports these options: -/// - `HeaderFileExtensions`: a comma-separated list of filename extensions of -/// header files (The filename extensions should not contain "." prefix). -/// "h,hh,hpp,hxx" by default. +/// - `HeaderFileExtensions`: a semicolon-separated list of filename +/// extensions of header files (The filename extensions should not contain +/// "." prefix). ";h;hh;hpp;hxx" by default. +/// /// For extension-less header files, using an empty string or leaving an -/// empty string between "," if there are other filename extensions. +/// empty string between ";" if there are other filename extensions. /// /// https://google.github.io/styleguide/cppguide.html#Namespaces /// diff --git a/clang-tools-extra/clang-tidy/google/UnnamedNamespaceInHeaderCheck.cpp b/clang-tools-extra/clang-tidy/google/UnnamedNamespaceInHeaderCheck.cpp --- a/clang-tools-extra/clang-tidy/google/UnnamedNamespaceInHeaderCheck.cpp +++ b/clang-tools-extra/clang-tidy/google/UnnamedNamespaceInHeaderCheck.cpp @@ -24,7 +24,8 @@ RawStringHeaderFileExtensions(Options.getLocalOrGlobal( "HeaderFileExtensions", utils::defaultHeaderFileExtensions())) { if (!utils::parseFileExtensions(RawStringHeaderFileExtensions, - HeaderFileExtensions, ',')) { + HeaderFileExtensions, + utils::defaultFileExtensionDelimiters())) { llvm::errs() << "Invalid header file extension: " << RawStringHeaderFileExtensions << "\n"; } diff --git a/clang-tools-extra/clang-tidy/llvm/HeaderGuardCheck.h b/clang-tools-extra/clang-tidy/llvm/HeaderGuardCheck.h --- a/clang-tools-extra/clang-tidy/llvm/HeaderGuardCheck.h +++ b/clang-tools-extra/clang-tidy/llvm/HeaderGuardCheck.h @@ -19,11 +19,12 @@ /// For the user-facing documentation see: /// http://clang.llvm.org/extra/clang-tidy/checks/llvm-header-guard.html /// The check supports these options: -/// - `HeaderFileExtensions`: a comma-separated list of filename extensions of -/// header files (The filename extension should not contain "." prefix). -/// ",h,hh,hpp,hxx" by default. +/// - `HeaderFileExtensions`: a semicolon-separated list of filename +/// extensions of header files (The filename extension should not contain +/// "." prefix). ";h;hh;hpp;hxx" by default. +/// /// For extension-less header files, using an empty string or leaving an -/// empty string between "," if there are other filename extensions. +/// empty string between ";" if there are other filename extensions. class LLVMHeaderGuardCheck : public utils::HeaderGuardCheck { public: LLVMHeaderGuardCheck(StringRef Name, ClangTidyContext *Context); diff --git a/clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.h b/clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.h --- a/clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.h +++ b/clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.h @@ -22,11 +22,12 @@ /// The check supports these options: /// - `UseHeaderFileExtension`: Whether to use file extension to distinguish /// header files. True by default. -/// - `HeaderFileExtensions`: a comma-separated list of filename extensions of -/// header files (The filename extension should not contain "." prefix). -/// ",h,hh,hpp,hxx" by default. +/// - `HeaderFileExtensions`: a semicolon-separated list of filename +/// extensions of header files (The filename extension should not contain +/// "." prefix). ";h;hh;hpp;hxx" by default. +/// /// For extension-less header files, using an empty string or leaving an -/// empty string between "," if there are other filename extensions. +/// empty string between ";" if there are other filename extensions. /// /// For the user-facing documentation see: /// http://clang.llvm.org/extra/clang-tidy/checks/misc-definitions-in-headers.html diff --git a/clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.cpp b/clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.cpp --- a/clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.cpp +++ b/clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.cpp @@ -34,7 +34,8 @@ RawStringHeaderFileExtensions(Options.getLocalOrGlobal( "HeaderFileExtensions", utils::defaultHeaderFileExtensions())) { if (!utils::parseFileExtensions(RawStringHeaderFileExtensions, - HeaderFileExtensions, ',')) { + HeaderFileExtensions, + utils::defaultFileExtensionDelimiters())) { // FIXME: Find a more suitable way to handle invalid configuration // options. llvm::errs() << "Invalid header file extension: " diff --git a/clang-tools-extra/clang-tidy/utils/FileExtensionsUtils.h b/clang-tools-extra/clang-tidy/utils/FileExtensionsUtils.h --- a/clang-tools-extra/clang-tidy/utils/FileExtensionsUtils.h +++ b/clang-tools-extra/clang-tidy/utils/FileExtensionsUtils.h @@ -34,11 +34,16 @@ /// Returns recommended default value for the list of header file /// extensions. -inline StringRef defaultHeaderFileExtensions() { return ",h,hh,hpp,hxx"; } +inline StringRef defaultHeaderFileExtensions() { return ";h;hh;hpp;hxx"; } + +/// Returns recommended default value for the list of file extension +/// delimiters. +inline StringRef defaultFileExtensionDelimiters() { return ",;"; } /// Parses header file extensions from a semicolon-separated list. bool parseFileExtensions(StringRef AllFileExtensions, - FileExtensionsSet &FileExtensions, char Delimiter); + FileExtensionsSet &FileExtensions, + StringRef Delimiters); /// Decides whether a file has one of the specified file extensions. bool isFileExtension(StringRef FileName, diff --git a/clang-tools-extra/clang-tidy/utils/FileExtensionsUtils.cpp b/clang-tools-extra/clang-tidy/utils/FileExtensionsUtils.cpp --- a/clang-tools-extra/clang-tidy/utils/FileExtensionsUtils.cpp +++ b/clang-tools-extra/clang-tidy/utils/FileExtensionsUtils.cpp @@ -9,6 +9,7 @@ #include "FileExtensionsUtils.h" #include "clang/Basic/CharInfo.h" #include "llvm/Support/Path.h" +#include "llvm/Support/raw_ostream.h" namespace clang { namespace tidy { @@ -33,9 +34,16 @@ } bool parseFileExtensions(StringRef AllFileExtensions, - FileExtensionsSet &FileExtensions, char Delimiter) { + FileExtensionsSet &FileExtensions, + StringRef Delimiters) { SmallVector Suffixes; - AllFileExtensions.split(Suffixes, Delimiter); + for (char Delimiter : Delimiters) { + if (AllFileExtensions.contains(Delimiter)) { + AllFileExtensions.split(Suffixes, Delimiter); + break; + } + } + FileExtensions.clear(); for (StringRef Suffix : Suffixes) { StringRef Extension = Suffix.trim(); diff --git a/clang-tools-extra/clang-tidy/utils/HeaderGuard.h b/clang-tools-extra/clang-tidy/utils/HeaderGuard.h --- a/clang-tools-extra/clang-tidy/utils/HeaderGuard.h +++ b/clang-tools-extra/clang-tidy/utils/HeaderGuard.h @@ -18,11 +18,12 @@ /// Finds and fixes header guards. /// The check supports these options: -/// - `HeaderFileExtensions`: a comma-separated list of filename extensions of -/// header files (The filename extension should not contain "." prefix). -/// ",h,hh,hpp,hxx" by default. +/// - `HeaderFileExtensions`: a semicolon-separated list of filename +/// extensions of header files (The filename extension should not contain +/// "." prefix). ";h;hh;hpp;hxx" by default. +/// /// For extension-less header files, using an empty string or leaving an -/// empty string between "," if there are other filename extensions. +/// empty string between ";" if there are other filename extensions. class HeaderGuardCheck : public ClangTidyCheck { public: HeaderGuardCheck(StringRef Name, ClangTidyContext *Context) @@ -30,7 +31,8 @@ RawStringHeaderFileExtensions(Options.getLocalOrGlobal( "HeaderFileExtensions", utils::defaultHeaderFileExtensions())) { utils::parseFileExtensions(RawStringHeaderFileExtensions, - HeaderFileExtensions, ','); + HeaderFileExtensions, + utils::defaultFileExtensionDelimiters()); } void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP, Preprocessor *ModuleExpanderPP) override; diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -125,6 +125,11 @@ check now detects in class initializers and constructor initializers which are deemed to be redundant. +- Checks supporting the ``HeaderFileExtensions`` flag now support ``;`` as a + delimiter in addition to ``,``, with the latter being deprecated as of this + release. This simplifies how one specifies the options on the command line: + ``--config="{CheckOptions: [{ key: HeaderFileExtensions, value: h;;hpp;hxx }]}"`` + Renamed checks ^^^^^^^^^^^^^^