[PATCH] D74669: [clang-tidy] New check: misc-no-include-cpp

Jonathan Roelofs via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Feb 17 09:45:07 PST 2020


jroelofs marked an inline comment as done.
jroelofs added inline comments.


================
Comment at: clang-tools-extra/clang-tidy/bugprone/SuspiciousIncludeCheck.cpp:59
+        Optional<FileEntryRef> File = PP->LookupFile(
+            HashLoc /* FIXME: lies */, (FileName + RE).str(), IsAngled, nullptr,
+            nullptr, CurDir, nullptr, nullptr, nullptr, nullptr, nullptr);
----------------
njames93 wrote:
> jroelofs wrote:
> > FIXME: is this a reasonable `SourceLocation` to give to `LookupFile`?
> Main thing is to make sure that the same location is used for the warnings and the notes.
> I personally found this the most pleasing diagnostics
> 
> ```
> SourceLocation DiagLoc = FilenameRange.getBegin().getLocWithOffset(1);
> ```
> 
> ```
> /home/nathan/src/llvm-project/build/Release/tools/clang/tools/extra/test/clang-tidy/checkers/Output/bugprone-suspicious-include.cpp.tmp.cpp:7:11: warning: suspicious #include of file with .cpp extension [bugprone-suspicious-include]
> #include "a.cpp"
>           ^
> /home/nathan/src/llvm-project/build/Release/tools/clang/tools/extra/test/clang-tidy/checkers/Output/bugprone-suspicious-include.cpp.tmp.cpp:7:11: note: did you mean to include 'a'?
> /home/nathan/src/llvm-project/build/Release/tools/clang/tools/extra/test/clang-tidy/checkers/Output/bugprone-suspicious-include.cpp.tmp.cpp:7:11: note: did you mean to include 'a.h'?
> /home/nathan/src/llvm-project/build/Release/tools/clang/tools/extra/test/clang-tidy/checkers/Output/bugprone-suspicious-include.cpp.tmp.cpp:7:11: note: did you mean to include 'a.hpp'?
> ```
I don't have much experience with modules to lean on for intuition on what this check should do with them. I've added a test to codify what the pass currently does in that case, but if there's something better it should be trying when searching for suggestions, let's make it do that instead.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D74669/new/

https://reviews.llvm.org/D74669





More information about the cfe-commits mailing list