@@ -99,7 +99,7 @@ class NilArgChecker : public Checker<check::PreObjCMessage,
99
99
check::PostStmt<ObjCDictionaryLiteral>,
100
100
check::PostStmt<ObjCArrayLiteral>,
101
101
EventDispatcher<ImplicitNullDerefEvent>> {
102
- mutable std::unique_ptr< APIMisuse> BT;
102
+ const APIMisuse BT{ this , " nil argument " } ;
103
103
104
104
mutable llvm::SmallDenseMap<Selector, unsigned , 16 > StringSelectors;
105
105
mutable Selector ArrayWithObjectSel;
@@ -218,10 +218,7 @@ void NilArgChecker::generateBugReport(ExplodedNode *N,
218
218
SourceRange Range,
219
219
const Expr *E,
220
220
CheckerContext &C) const {
221
- if (!BT)
222
- BT.reset (new APIMisuse (this , " nil argument" ));
223
-
224
- auto R = std::make_unique<PathSensitiveBugReport>(*BT, Msg, N);
221
+ auto R = std::make_unique<PathSensitiveBugReport>(BT, Msg, N);
225
222
R->addRange (Range);
226
223
bugreporter::trackExpressionValue (N, E, *R);
227
224
C.emitReport (std::move (R));
@@ -350,7 +347,7 @@ void NilArgChecker::checkPostStmt(const ObjCDictionaryLiteral *DL,
350
347
351
348
namespace {
352
349
class CFNumberChecker : public Checker < check::PreStmt<CallExpr> > {
353
- mutable std::unique_ptr< APIMisuse> BT;
350
+ const APIMisuse BT{ this , " Bad use of CFNumber APIs " } ;
354
351
mutable IdentifierInfo *ICreate = nullptr , *IGetValue = nullptr ;
355
352
public:
356
353
CFNumberChecker () = default ;
@@ -524,10 +521,7 @@ void CFNumberChecker::checkPreStmt(const CallExpr *CE,
524
521
<< " bits of the integer value will be "
525
522
<< (isCreate ? " lost." : " garbage." );
526
523
527
- if (!BT)
528
- BT.reset (new APIMisuse (this , " Bad use of CFNumber APIs" ));
529
-
530
- auto report = std::make_unique<PathSensitiveBugReport>(*BT, os.str (), N);
524
+ auto report = std::make_unique<PathSensitiveBugReport>(BT, os.str (), N);
531
525
report->addRange (CE->getArg (2 )->getSourceRange ());
532
526
C.emitReport (std::move (report));
533
527
}
@@ -539,7 +533,7 @@ void CFNumberChecker::checkPreStmt(const CallExpr *CE,
539
533
540
534
namespace {
541
535
class CFRetainReleaseChecker : public Checker <check::PreCall> {
542
- mutable APIMisuse BT{this , " null passed to CF memory management function" };
536
+ const APIMisuse BT{this , " null passed to CF memory management function" };
543
537
const CallDescriptionSet ModelledCalls = {
544
538
{CDM::CLibrary, {" CFRetain" }, 1 },
545
539
{CDM::CLibrary, {" CFRelease" }, 1 },
@@ -600,7 +594,8 @@ class ClassReleaseChecker : public Checker<check::PreObjCMessage> {
600
594
mutable Selector retainS;
601
595
mutable Selector autoreleaseS;
602
596
mutable Selector drainS;
603
- mutable std::unique_ptr<BugType> BT;
597
+ const APIMisuse BT{
598
+ this , " message incorrectly sent to class instead of class instance" };
604
599
605
600
public:
606
601
void checkPreObjCMessage (const ObjCMethodCall &msg, CheckerContext &C) const ;
@@ -609,10 +604,7 @@ class ClassReleaseChecker : public Checker<check::PreObjCMessage> {
609
604
610
605
void ClassReleaseChecker::checkPreObjCMessage (const ObjCMethodCall &msg,
611
606
CheckerContext &C) const {
612
- if (!BT) {
613
- BT.reset (new APIMisuse (
614
- this , " message incorrectly sent to class instead of class instance" ));
615
-
607
+ if (releaseS.isNull ()) {
616
608
ASTContext &Ctx = C.getASTContext ();
617
609
releaseS = GetNullarySelector (" release" , Ctx);
618
610
retainS = GetNullarySelector (" retain" , Ctx);
@@ -639,7 +631,7 @@ void ClassReleaseChecker::checkPreObjCMessage(const ObjCMethodCall &msg,
639
631
" of class '" << Class->getName ()
640
632
<< " ' and not the class directly" ;
641
633
642
- auto report = std::make_unique<PathSensitiveBugReport>(* BT, os.str (), N);
634
+ auto report = std::make_unique<PathSensitiveBugReport>(BT, os.str (), N);
643
635
report->addRange (msg.getSourceRange ());
644
636
C.emitReport (std::move (report));
645
637
}
@@ -658,7 +650,8 @@ class VariadicMethodTypeChecker : public Checker<check::PreObjCMessage> {
658
650
mutable Selector orderedSetWithObjectsS;
659
651
mutable Selector initWithObjectsS;
660
652
mutable Selector initWithObjectsAndKeysS;
661
- mutable std::unique_ptr<BugType> BT;
653
+ const APIMisuse BT{this , " Arguments passed to variadic method aren't all "
654
+ " Objective-C pointer types" };
662
655
663
656
bool isVariadicMessage (const ObjCMethodCall &msg) const ;
664
657
@@ -717,11 +710,7 @@ VariadicMethodTypeChecker::isVariadicMessage(const ObjCMethodCall &msg) const {
717
710
718
711
void VariadicMethodTypeChecker::checkPreObjCMessage (const ObjCMethodCall &msg,
719
712
CheckerContext &C) const {
720
- if (!BT) {
721
- BT.reset (new APIMisuse (this ,
722
- " Arguments passed to variadic method aren't all "
723
- " Objective-C pointer types" ));
724
-
713
+ if (arrayWithObjectsS.isNull ()) {
725
714
ASTContext &Ctx = C.getASTContext ();
726
715
arrayWithObjectsS = GetUnarySelector (" arrayWithObjects" , Ctx);
727
716
dictionaryWithObjectsAndKeysS =
@@ -792,8 +781,7 @@ void VariadicMethodTypeChecker::checkPreObjCMessage(const ObjCMethodCall &msg,
792
781
ArgTy.print (os, C.getLangOpts ());
793
782
os << " '" ;
794
783
795
- auto R =
796
- std::make_unique<PathSensitiveBugReport>(*BT, os.str (), *errorNode);
784
+ auto R = std::make_unique<PathSensitiveBugReport>(BT, os.str (), *errorNode);
797
785
R->addRange (msg.getArgSourceRange (I));
798
786
C.emitReport (std::move (R));
799
787
}
0 commit comments