aboutsummaryrefslogtreecommitdiff
path: root/clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
diff options
context:
space:
mode:
authorRichard <legalize@xmission.com>2022-01-01 22:47:22 -0700
committerRichard <legalize@xmission.com>2022-01-23 09:23:04 -0700
commitd2e8fb331835fcc565929720781a5fd64e66fc17 (patch)
tree0ffe4231de17f85dc558497587fa925f17339635 /clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
parent2e26633af0c88ea23e3e8783ef60e621f282d3fb (diff)
downloadllvm-d2e8fb331835fcc565929720781a5fd64e66fc17.zip
llvm-d2e8fb331835fcc565929720781a5fd64e66fc17.tar.gz
llvm-d2e8fb331835fcc565929720781a5fd64e66fc17.tar.bz2
[clang-tidy] Add readability-duplicate-include check
Looks for duplicate includes and removes them. Every time an include directive is processed, check a vector of filenames to see if the included file has already been included. If so, it issues a warning and a replacement to remove the entire line containing the duplicated include directive. When a macro is defined or undefined, the vector of filenames is cleared. This enables including the same file multiple times, but getting different expansions based on the set of active macros at the time of inclusion. For example: #undef NDEBUG #include "assertion.h" // ...code with assertions enabled #define NDEBUG #include "assertion.h" // ...code with assertions disabled Since macros are redefined between the inclusion of assertion.h, they are not flagged as redundant. Differential Revision: https://reviews.llvm.org/D7982
Diffstat (limited to 'clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp')
-rw-r--r--clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp3
1 files changed, 3 insertions, 0 deletions
diff --git a/clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp b/clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
index 2d65402..b0493d4 100644
--- a/clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
@@ -16,6 +16,7 @@
#include "ContainerSizeEmptyCheck.h"
#include "ConvertMemberFunctionsToStatic.h"
#include "DeleteNullPointerCheck.h"
+#include "DuplicateIncludeCheck.h"
#include "ElseAfterReturnCheck.h"
#include "FunctionCognitiveComplexityCheck.h"
#include "FunctionSizeCheck.h"
@@ -71,6 +72,8 @@ public:
"readability-convert-member-functions-to-static");
CheckFactories.registerCheck<DeleteNullPointerCheck>(
"readability-delete-null-pointer");
+ CheckFactories.registerCheck<DuplicateIncludeCheck>(
+ "readability-duplicate-include");
CheckFactories.registerCheck<ElseAfterReturnCheck>(
"readability-else-after-return");
CheckFactories.registerCheck<FunctionCognitiveComplexityCheck>(