-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[clang-tidy][IncludeCleaner] Fix analysis supression in presence of verbatim spellings #68185
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,7 @@ | |
#include "clang/Lex/Preprocessor.h" | ||
#include "clang/Tooling/Core/Replacement.h" | ||
#include "clang/Tooling/Inclusions/HeaderIncludes.h" | ||
#include "clang/Tooling/Inclusions/StandardLibrary.h" | ||
#include "llvm/ADT/DenseSet.h" | ||
#include "llvm/ADT/STLExtras.h" | ||
#include "llvm/ADT/SmallVector.h" | ||
|
@@ -97,9 +98,12 @@ bool IncludeCleanerCheck::shouldIgnore(const include_cleaner::Header &H) { | |
return llvm::any_of(IgnoreHeadersRegex, [&H](const llvm::Regex &R) { | ||
switch (H.kind()) { | ||
case include_cleaner::Header::Standard: | ||
// We don't trim braces around standard library headers deliberately, so | ||
// that they are only matched as <vector>, otherwise having just | ||
// `.*/vector` might yield false positives. | ||
return R.match(H.standard().name()); | ||
case include_cleaner::Header::Verbatim: | ||
return R.match(H.verbatim()); | ||
return R.match(H.verbatim().trim("<>\"")); | ||
case include_cleaner::Header::Physical: | ||
return R.match(H.physical().getFileEntry().tryGetRealPathName()); | ||
} | ||
|
@@ -179,12 +183,14 @@ void IncludeCleanerCheck::check(const MatchFinder::MatchResult &Result) { | |
if (getCurrentMainFile().endswith(PHeader)) | ||
continue; | ||
} | ||
|
||
if (llvm::none_of( | ||
IgnoreHeadersRegex, | ||
[Resolved = (*I.Resolved).getFileEntry().tryGetRealPathName()]( | ||
const llvm::Regex &R) { return R.match(Resolved); })) | ||
Unused.push_back(&I); | ||
auto StdHeader = tooling::stdlib::Header::named( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe you could move this passage into the handling of standard headers in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ATM Did you have something else in mind? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, thanks, then what about something like (apologies for small mistakes, just typing into the comment window):
I'm trying to simplify the flow in the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that would be even better, but it would be a regression to current users. ATM this code is checking both the StdHeader and the Resolved header. In your suggestion we would only check for one or the other. |
||
I.quote(), PP->getLangOpts().CPlusPlus ? tooling::stdlib::Lang::CXX | ||
: tooling::stdlib::Lang::C); | ||
if (StdHeader && shouldIgnore(*StdHeader)) | ||
continue; | ||
if (shouldIgnore(*I.Resolved)) | ||
continue; | ||
Unused.push_back(&I); | ||
} | ||
|
||
llvm::StringRef Code = SM->getBufferData(SM->getMainFileID()); | ||
|
Uh oh!
There was an error while loading. Please reload this page.