a warning and then threw away the AST. While I'm in there, tighten up the
code to actually reject completely bogus cases (sending a message to a
struct). We still allow sending a message to an int, which doesn't make
sense but GCC allows it and is easy to support.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@66468
91177308-0d34-0410-b5e6-
96231b3b80d8
"invalid receiver to message expression")
DIAG(warn_bad_receiver_type, WARNING,
"bad receiver type %0")
+DIAG(err_bad_receiver_type, ERROR,
+ "bad receiver type %0")
DIAG(error_objc_throw_expects_object, ERROR,
"invalid %0 argument (expected an ObjC object type)")
DIAG(error_rethrow_used_outside_catch, ERROR,
// Handle messages to id.
if (ReceiverCType == Context.getCanonicalType(Context.getObjCIdType()) ||
- ReceiverCType->getAsBlockPointerType()) {
+ ReceiverCType->isBlockPointerType()) {
ObjCMethodDecl *Method = LookupInstanceMethodInGlobalPool(
Sel, SourceRange(lbrac,rbrac));
if (!Method)
}
if (Method && DiagnoseUseOfDecl(Method, receiverLoc))
return true;
- } else {
+ } else if (!Context.getObjCIdType().isNull() &&
+ (ReceiverCType->isPointerType() ||
+ (ReceiverCType->isIntegerType() &&
+ ReceiverCType->isScalarType()))) {
+ // Implicitly convert integers and pointers to 'id' but emit a warning.
Diag(lbrac, diag::warn_bad_receiver_type)
<< RExpr->getType() << RExpr->getSourceRange();
+ ImpCastExprToType(RExpr, Context.getObjCIdType());
+ } else {
+ // Reject other random receiver types (e.g. structs).
+ Diag(lbrac, diag::err_bad_receiver_type)
+ << RExpr->getType() << RExpr->getSourceRange();
return true;
}
@end
void __raiseExc1() {
- [objc_lookUpClass("NSString") retain]; // expected-warning {{ "bad receiver type 'int'" }}
+ [objc_lookUpClass("NSString") retain]; // expected-warning {{ "bad receiver type 'int'" }} \
+ expected-warning {{method '-retain' not found}}
}
typedef const struct __CFString * CFStringRef;
void func() {
CFStringRef obj;
- [obj self]; // expected-warning {{bad receiver type 'CFStringRef' (aka 'struct __CFString const *')}}
+ [obj self]; // expected-warning {{bad receiver type 'CFStringRef' (aka 'struct __CFString const *')}} \\
+ expected-warning {{method '-self' not found}}
}
return 0;
}
+
+// PR3766
+struct S { int X; } S;
+
+int test5(int X) {
+ int a = [X somemsg]; // expected-warning {{bad receiver type 'int'}} \
+ expected-warning {{method '-somemsg' not found}} \
+ expected-warning {{incompatible pointer to integer conversion initializing 'id', expected 'int'}}
+ int b = [S somemsg]; // expected-error {{bad receiver type 'struct S'}}
+}
+
+
+
[super m];
}
void f0(int super) {
- [super m]; // expected-warning{{bad receiver type 'int'}}
+ [super m]; // expected-warning{{bad receiver type 'int'}} \
+ expected-warning {{method '-m' not found (return type defaults to 'id')}}
}
void f1(int puper) {
[super m]; // expected-error{{use of undeclared identifier 'super'}}