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<ObjCIvarRefExpr>,
check::PreStmt<ReturnStmt>,
check::PostCall,
check::Location,
check::Bind > {
+ mutable InitSelfBug InitSelfBugType;
+
+ void checkForInvalidSelf(const Expr *E, CheckerContext &C,
+ const char *errorStr) const;
+
public:
+ ObjCSelfInitChecker() : InitSelfBugType(this) {}
void checkPostObjCMessage(const ObjCMethodCall &Msg, CheckerContext &C) const;
void checkPostStmt(const ObjCIvarRefExpr *E, CheckerContext &C) const;
void checkPreStmt(const ReturnStmt *S, CheckerContext &C) const;
};
} // end anonymous namespace
-namespace {
-
-class InitSelfBug : public BugType {
-public:
- InitSelfBug(const CheckerBase *Checker)
- : BugType(Checker, "Missing \"self = [(super or self) init...]\"",
- categories::CoreFoundationObjectiveC) {}
-};
-
-} // end anonymous namespace
-
namespace {
enum SelfFlagEnum {
/// \brief No flag set.
return true;
}
-static void checkForInvalidSelf(const Expr *E, CheckerContext &C,
- const char *errorStr,
- const CheckerBase *Checker) {
+void ObjCSelfInitChecker::checkForInvalidSelf(const Expr *E, CheckerContext &C,
+ const char *errorStr) const {
if (!E)
return;
if (!N)
return;
- BugReport *report = new BugReport(*new InitSelfBug(Checker), errorStr, N);
+ BugReport *report = new BugReport(InitSelfBugType, errorStr, N);
C.emitReport(report);
}
checkForInvalidSelf(
E->getBase(), C,
"Instance variable used while 'self' is not set to the result of "
- "'[(super or self) init...]'",
- this);
+ "'[(super or self) init...]'");
}
void ObjCSelfInitChecker::checkPreStmt(const ReturnStmt *S,
checkForInvalidSelf(S->getRetValue(), C,
"Returning 'self' while it is not set to the result of "
- "'[(super or self) init...]'",
- this);
+ "'[(super or self) init...]'");
}
// When a call receives a reference to 'self', [Pre/Post]Call pass