[all-commits] [llvm/llvm-project] d2e8fb: [clang-tidy] Add readability-duplicate-include check

Richard Thomson via All-commits all-commits at lists.llvm.org
Sun Jan 23 08:23:25 PST 2022


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: d2e8fb331835fcc565929720781a5fd64e66fc17
      https://github.com/llvm/llvm-project/commit/d2e8fb331835fcc565929720781a5fd64e66fc17
  Author: Richard <legalize at xmission.com>
  Date:   2022-01-23 (Sun, 23 Jan 2022)

  Changed paths:
    M clang-tools-extra/clang-tidy/readability/CMakeLists.txt
    A clang-tools-extra/clang-tidy/readability/DuplicateIncludeCheck.cpp
    A clang-tools-extra/clang-tidy/readability/DuplicateIncludeCheck.h
    M clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
    M clang-tools-extra/docs/ReleaseNotes.rst
    M clang-tools-extra/docs/clang-tidy/checks/list.rst
    A clang-tools-extra/docs/clang-tidy/checks/readability-duplicate-include.rst
    A clang-tools-extra/test/clang-tidy/checkers/Inputs/readability-duplicate-include/readability-duplicate-include.h
    A clang-tools-extra/test/clang-tidy/checkers/Inputs/readability-duplicate-include/readability-duplicate-include2.h
    A clang-tools-extra/test/clang-tidy/checkers/Inputs/readability-duplicate-include/system/iostream
    A clang-tools-extra/test/clang-tidy/checkers/Inputs/readability-duplicate-include/system/string.h
    A clang-tools-extra/test/clang-tidy/checkers/Inputs/readability-duplicate-include/system/sys/types.h
    A clang-tools-extra/test/clang-tidy/checkers/Inputs/readability-duplicate-include/system/types.h
    A clang-tools-extra/test/clang-tidy/checkers/readability-duplicate-include.cpp

  Log Message:
  -----------
  [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




More information about the All-commits mailing list