From: Jordan Rose Date: Wed, 7 May 2014 03:30:04 +0000 (+0000) Subject: [analyzer] Use a lazily-initialized BugType in ObjCSelfInitChecker. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f66a16c418951c88538e330036d8f69fdc009992;p=clang [analyzer] Use a lazily-initialized BugType in ObjCSelfInitChecker. Follow-up to Nico's leak-stopping patch in r208110. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@208155 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/StaticAnalyzer/Checkers/ObjCSelfInitChecker.cpp b/lib/StaticAnalyzer/Checkers/ObjCSelfInitChecker.cpp index 3eec6815c9..51bc7e66dc 100644 --- a/lib/StaticAnalyzer/Checkers/ObjCSelfInitChecker.cpp +++ b/lib/StaticAnalyzer/Checkers/ObjCSelfInitChecker.cpp @@ -55,13 +55,6 @@ static bool isInitMessage(const ObjCMethodCall &Msg); static bool isSelfVar(SVal location, CheckerContext &C); namespace { -class InitSelfBug : public BugType { -public: - InitSelfBug(const CheckerBase *Checker) - : BugType(Checker, "Missing \"self = [(super or self) init...]\"", - categories::CoreFoundationObjectiveC) {} -}; - class ObjCSelfInitChecker : public Checker< check::PostObjCMessage, check::PostStmt, check::PreStmt, @@ -69,13 +62,13 @@ class ObjCSelfInitChecker : public Checker< check::PostObjCMessage, check::PostCall, check::Location, check::Bind > { - mutable InitSelfBug InitSelfBugType; + mutable std::unique_ptr BT; void checkForInvalidSelf(const Expr *E, CheckerContext &C, const char *errorStr) const; public: - ObjCSelfInitChecker() : InitSelfBugType(this) {} + ObjCSelfInitChecker() {} void checkPostObjCMessage(const ObjCMethodCall &Msg, CheckerContext &C) const; void checkPostStmt(const ObjCIvarRefExpr *E, CheckerContext &C) const; void checkPreStmt(const ReturnStmt *S, CheckerContext &C) const; @@ -164,7 +157,10 @@ void ObjCSelfInitChecker::checkForInvalidSelf(const Expr *E, CheckerContext &C, if (!N) return; - BugReport *report = new BugReport(InitSelfBugType, errorStr, N); + if (!BT) + BT.reset(new BugType(this, "Missing \"self = [(super or self) init...]\"", + categories::CoreFoundationObjectiveC)); + BugReport *report = new BugReport(*BT, errorStr, N); C.emitReport(report); }