}
}
-
void CallAndMessageChecker::checkPreCall(const CallEvent &Call,
CheckerContext &C) const {
ProgramStateRef State = C.getState();
}
const Decl *D = Call.getDecl();
- const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(D);
- if (FD) {
- // If we have a declaration, we can make sure we pass enough parameters to
- // the function.
- unsigned Params = FD->getNumParams();
+ if (D && (isa<FunctionDecl>(D) || isa<BlockDecl>(D))) {
+ // If we have a function or block declaration, we can make sure we pass
+ // enough parameters.
+ unsigned Params = Call.parameters().size();
if (Call.getNumArgs() < Params) {
ExplodedNode *N = C.generateErrorNode();
if (!N)
SmallString<512> Str;
llvm::raw_svector_ostream os(Str);
- os << "Function taking " << Params << " argument"
- << (Params == 1 ? "" : "s") << " is called with less ("
+ if (isa<FunctionDecl>(D)) {
+ os << "Function ";
+ } else {
+ assert(isa<BlockDecl>(D));
+ os << "Block ";
+ }
+ os << "taking " << Params << " argument"
+ << (Params == 1 ? "" : "s") << " is called with fewer ("
<< Call.getNumArgs() << ")";
C.emitReport(
else
BT = &BT_call_arg;
+ const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(D);
for (unsigned i = 0, e = Call.getNumArgs(); i != e; ++i) {
const ParmVarDecl *ParamDecl = nullptr;
if(FD && i < FD->getNumParams())
});
}
@end
+
+// The incorrect block variable initialization below is a hard compile-time
+// error in C++.
+#if !defined(__cplusplus)
+void call_block_with_fewer_arguments() {
+ void (^b)() = ^(int a) { };
+ b(); // expected-warning {{Block taking 1 argument is called with fewer (0)}}
+}
+#endif
void knr_one_argument(a) int a; { }
void call_with_less_arguments() {
- knr_one_argument(); // expected-warning{{too few arguments}} expected-warning{{Function taking 1 argument}}
+ knr_one_argument(); // expected-warning{{too few arguments}} expected-warning{{Function taking 1 argument is called with fewer (0)}}
}
void it_takes_two(int a, int b);
void function_pointer_arity_mismatch() {
void(*fptr)() = it_takes_two;
- fptr(1); // no-crash expected-warning {{Function taking 2 arguments is called with less (1)}}
+ fptr(1); // no-crash expected-warning {{Function taking 2 arguments is called with fewer (1)}}
}
void block_arity_mismatch() {
- void(^b)() = ^(int a, int b) { }; // no-crash
- b(1);
+ void(^b)() = ^(int a, int b) { };
+ b(1); // no-crash expected-warning {{Block taking 2 arguments is called with fewer (1)}}
}