def warn_call_wrong_number_of_arguments : Warning<
"too %select{few|many}0 arguments in call to %1">;
def err_deleted_function_use : Error<"attempt to use a deleted function">;
+
+def err_cannot_pass_objc_interface_to_vararg : Error<
+ "cannot pass object with interface type %0 by-value through variadic "
+ "%select{function|block|method}1">;
+
def warn_cannot_pass_non_pod_arg_to_vararg : Warning<
"cannot pass object of non-POD type %0 through variadic "
"%select{function|block|method}1; call will abort at runtime">;
// DefaultVariadicArgumentPromotion - Like DefaultArgumentPromotion, but
// will warn if the resulting type is not a POD type.
- void DefaultVariadicArgumentPromotion(Expr *&Expr, VariadicCallType CT);
+ bool DefaultVariadicArgumentPromotion(Expr *&Expr, VariadicCallType CT);
// UsualArithmeticConversions - performs the UsualUnaryConversions on it's
// operands and then handles various conversions that are common to binary
UsualUnaryConversions(Expr);
}
-// DefaultVariadicArgumentPromotion - Like DefaultArgumentPromotion, but
-// will warn if the resulting type is not a POD type.
-void Sema::DefaultVariadicArgumentPromotion(Expr *&Expr, VariadicCallType CT) {
+/// DefaultVariadicArgumentPromotion - Like DefaultArgumentPromotion, but
+/// will warn if the resulting type is not a POD type, and rejects ObjC
+/// interfaces passed by value. This returns true if the argument type is
+/// completely illegal.
+bool Sema::DefaultVariadicArgumentPromotion(Expr *&Expr, VariadicCallType CT) {
DefaultArgumentPromotion(Expr);
- if (!Expr->getType()->isPODType()) {
- Diag(Expr->getLocStart(),
- diag::warn_cannot_pass_non_pod_arg_to_vararg) <<
- Expr->getType() << CT;
+ if (Expr->getType()->isObjCInterfaceType()) {
+ Diag(Expr->getLocStart(),
+ diag::err_cannot_pass_objc_interface_to_vararg)
+ << Expr->getType() << CT;
+ return true;
}
+
+ if (!Expr->getType()->isPODType())
+ Diag(Expr->getLocStart(), diag::warn_cannot_pass_non_pod_arg_to_vararg)
+ << Expr->getType() << CT;
+
+ return false;
}
// Promote the arguments (C99 6.5.2.2p7).
for (unsigned i = NumArgsInProto; i != NumArgs; i++) {
Expr *Arg = Args[i];
- DefaultVariadicArgumentPromotion(Arg, CallType);
+ Invalid |= DefaultVariadicArgumentPromotion(Arg, CallType);
Call->setArg(i, Arg);
}
}
unsigned NumNamedArgs = Sel.getNumArgs();
assert(NumArgs >= NumNamedArgs && "Too few arguments for selector!");
- bool anyIncompatibleArgs = false;
+ bool IsError = false;
for (unsigned i = 0; i < NumNamedArgs; i++) {
Expr *argExpr = Args[i];
assert(argExpr && "CheckMessageArgumentTypes(): missing expression");
if (Args[i] != argExpr) // The expression was converted.
Args[i] = argExpr; // Make sure we store the converted expression.
- anyIncompatibleArgs |=
+ IsError |=
DiagnoseAssignmentResult(Result, argExpr->getLocStart(), lhsType, rhsType,
argExpr, "sending");
}
// Promote additional arguments to variadic methods.
if (Method->isVariadic()) {
for (unsigned i = NumNamedArgs; i < NumArgs; ++i)
- DefaultVariadicArgumentPromotion(Args[i], VariadicMethod);
+ IsError |= DefaultVariadicArgumentPromotion(Args[i], VariadicMethod);
} else {
// Check for extra arguments to non-variadic methods.
if (NumArgs != NumNamedArgs) {
}
}
- return anyIncompatibleArgs;
+ return IsError;
}
bool Sema::isSelfExpr(Expr *RExpr) {
else if (NumArgs > NumArgsInProto)
NumArgsToCheck = NumArgsInProto;
+ bool IsError = false;
+
// Initialize the implicit object parameter.
- if (PerformObjectArgumentInitialization(Object, Method))
- return true;
+ IsError |= PerformObjectArgumentInitialization(Object, Method);
TheCall->setArg(0, Object);
+
// Check the argument types.
for (unsigned i = 0; i != NumArgsToCheck; i++) {
Expr *Arg;
// Pass the argument.
QualType ProtoArgType = Proto->getArgType(i);
- if (PerformCopyInitialization(Arg, ProtoArgType, "passing"))
- return true;
+ IsError |= PerformCopyInitialization(Arg, ProtoArgType, "passing");
} else {
Arg = new (Context) CXXDefaultArgExpr(Method->getParamDecl(i));
}
// Promote the arguments (C99 6.5.2.2p7).
for (unsigned i = NumArgsInProto; i != NumArgs; i++) {
Expr *Arg = Args[i];
-
- DefaultVariadicArgumentPromotion(Arg, VariadicMethod);
+ IsError |= DefaultVariadicArgumentPromotion(Arg, VariadicMethod);
TheCall->setArg(i + 1, Arg);
}
}
+ if (IsError) return true;
+
return CheckFunctionCall(Method, TheCall.take()).release();
}
void somefunc(foo x) {} // expected-error {{Objective-C interface type 'foo' cannot be passed by value}}
foo somefunc2() {} // expected-error {{Objective-C interface type 'foo' cannot be returned by value}}
+
+// rdar://6780761
+void f0(foo *a0) {
+ extern void g0(int x, ...);
+ g0(1, *(foo*)0); // expected-error {{cannot pass object with interface type 'foo' by-value through variadic function}}
+}