7
7
// ===----------------------------------------------------------------------===//
8
8
9
9
#include " UseNullptrCheck.h"
10
+ #include " ../utils/Matchers.h"
11
+ #include " ../utils/OptionsUtils.h"
10
12
#include " clang/AST/ASTContext.h"
11
13
#include " clang/AST/RecursiveASTVisitor.h"
12
14
#include " clang/ASTMatchers/ASTMatchFinder.h"
@@ -33,11 +35,13 @@ AST_MATCHER(Type, sugaredNullptrType) {
33
35
// / to null within.
34
36
// / Finding sequences of explicit casts is necessary so that an entire sequence
35
37
// / can be replaced instead of just the inner-most implicit cast.
36
- StatementMatcher makeCastSequenceMatcher () {
37
- StatementMatcher ImplicitCastToNull = implicitCastExpr (
38
+ StatementMatcher makeCastSequenceMatcher (llvm::ArrayRef<StringRef> NameList ) {
39
+ auto ImplicitCastToNull = implicitCastExpr (
38
40
anyOf (hasCastKind (CK_NullToPointer), hasCastKind (CK_NullToMemberPointer)),
39
41
unless (hasImplicitDestinationType (qualType (substTemplateTypeParmType ()))),
40
- unless (hasSourceExpression (hasType (sugaredNullptrType ()))));
42
+ unless (hasSourceExpression (hasType (sugaredNullptrType ()))),
43
+ unless (hasImplicitDestinationType (
44
+ qualType (matchers::matchesAnyListedTypeName (NameList)))));
41
45
42
46
auto IsOrHasDescendant = [](auto InnerMatcher) {
43
47
return anyOf (InnerMatcher, hasDescendant (InnerMatcher));
@@ -477,16 +481,21 @@ class CastSequenceVisitor : public RecursiveASTVisitor<CastSequenceVisitor> {
477
481
478
482
UseNullptrCheck::UseNullptrCheck (StringRef Name, ClangTidyContext *Context)
479
483
: ClangTidyCheck(Name, Context),
480
- NullMacrosStr(Options.get(" NullMacros" , " NULL" )) {
484
+ NullMacrosStr(Options.get(" NullMacros" , " NULL" )),
485
+ IgnoredTypes(utils::options::parseStringList(Options.get(
486
+ " IgnoredTypes" ,
487
+ " std::_CmpUnspecifiedParam::;^std::__cmp_cat::__unspec" ))) {
481
488
StringRef (NullMacrosStr).split (NullMacros, " ," );
482
489
}
483
490
484
491
void UseNullptrCheck::storeOptions (ClangTidyOptions::OptionMap &Opts) {
485
492
Options.store (Opts, " NullMacros" , NullMacrosStr);
493
+ Options.store (Opts, " IgnoredTypes" ,
494
+ utils::options::serializeStringList (IgnoredTypes));
486
495
}
487
496
488
497
void UseNullptrCheck::registerMatchers (MatchFinder *Finder) {
489
- Finder->addMatcher (makeCastSequenceMatcher (), this );
498
+ Finder->addMatcher (makeCastSequenceMatcher (IgnoredTypes ), this );
490
499
}
491
500
492
501
void UseNullptrCheck::check (const MatchFinder::MatchResult &Result) {
0 commit comments