[PATCH] D111909: [clang-tidy] DefinitionsInHeadersCheck: Added option for checking C Code
Max Schroetter via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Oct 15 15:25:47 PDT 2021
schrc3b6 created this revision.
Herald added a subscriber: xazax.hun.
schrc3b6 added a reviewer: alexfh.
schrc3b6 updated this revision to Diff 380104.
schrc3b6 added a comment.
schrc3b6 published this revision for review.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.
fixed typo
Eventhough there are no OCR rules in the C standard, to my
knowledge, it is recommended to not include definitions in header files.
This Patch introduces the CheckCCode Option which add C99 to the
language check. Since this checker was original written for C++ it
is off by default.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D111909
Files:
clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.cpp
clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.h
clang-tools-extra/docs/clang-tidy/checks/misc-definitions-in-headers.rst
Index: clang-tools-extra/docs/clang-tidy/checks/misc-definitions-in-headers.rst
===================================================================
--- clang-tools-extra/docs/clang-tidy/checks/misc-definitions-in-headers.rst
+++ clang-tools-extra/docs/clang-tidy/checks/misc-definitions-in-headers.rst
@@ -102,3 +102,8 @@
When `true`, the check will use the file extension to distinguish header
files. Default is `true`.
+
+.. option:: CheckCCode
+
+ When `true` C99 is added to the minimum language requirements for this
+ Cecker. Default is `false` because this Checker was not build for C.
Index: clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.h
===================================================================
--- clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.h
+++ clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.h
@@ -22,6 +22,8 @@
/// The check supports these options:
/// - `UseHeaderFileExtension`: Whether to use file extension to distinguish
/// header files. True by default.
+/// - `CheckCCode`: Adds C99 to the minimum Language Requirements for this
+/// Checker. Disabled by default because this Checker wasn't build for C.
/// - `HeaderFileExtensions`: a semicolon-separated list of filename
/// extensions of header files (The filename extension should not contain
/// "." prefix). ";h;hh;hpp;hxx" by default.
@@ -35,6 +37,9 @@
public:
DefinitionsInHeadersCheck(StringRef Name, ClangTidyContext *Context);
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
+ if (CheckCCode) {
+ return LangOpts.CPlusPlus11 || LangOpts.C99;
+ }
return LangOpts.CPlusPlus11;
}
void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
@@ -43,6 +48,7 @@
private:
const bool UseHeaderFileExtension;
+ const bool CheckCCode;
const std::string RawStringHeaderFileExtensions;
utils::FileExtensionsSet HeaderFileExtensions;
};
Index: clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.cpp
===================================================================
--- clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.cpp
+++ clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.cpp
@@ -31,6 +31,7 @@
ClangTidyContext *Context)
: ClangTidyCheck(Name, Context),
UseHeaderFileExtension(Options.get("UseHeaderFileExtension", true)),
+ CheckCCode(Options.get("CheckCCode", false)),
RawStringHeaderFileExtensions(Options.getLocalOrGlobal(
"HeaderFileExtensions", utils::defaultHeaderFileExtensions())) {
if (!utils::parseFileExtensions(RawStringHeaderFileExtensions,
@@ -44,6 +45,7 @@
void DefinitionsInHeadersCheck::storeOptions(
ClangTidyOptions::OptionMap &Opts) {
Options.store(Opts, "UseHeaderFileExtension", UseHeaderFileExtension);
+ Options.store(Opts, "CheckCCode", CheckCCode);
Options.store(Opts, "HeaderFileExtensions", RawStringHeaderFileExtensions);
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D111909.380104.patch
Type: text/x-patch
Size: 3041 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20211015/ced1562c/attachment-0001.bin>
More information about the cfe-commits
mailing list