Fix an inconsistency in Sema::ConvertArgumentsForCall in that

the callee note diagnostic was not emitted in the case where
there were too few arguments.

llvm-svn: 136437
This commit is contained in:
Peter Collingbourne 2011-07-29 00:24:42 +00:00
parent 8ab4ea8571
commit 3bc84ca376
6 changed files with 18 additions and 11 deletions

View File

@ -3696,11 +3696,11 @@ def err_typecheck_call_too_few_args_at_least : Error<
def err_typecheck_call_too_many_args : Error<
"too many arguments to %select{function|block|method}0 call, "
"expected %1, have %2">;
def note_typecheck_call_too_many_args : Note<
"%0 declared here">;
def err_typecheck_call_too_many_args_at_most : Error<
"too many arguments to %select{function|block|method}0 call, "
"expected at most %1, have %2">;
def note_callee_decl : Note<
"%0 declared here">;
def warn_call_wrong_number_of_arguments : Warning<
"too %select{few|many}0 arguments in call to %1">;
def err_atomic_builtin_must_be_pointer : Error<

View File

@ -3231,10 +3231,18 @@ Sema::ConvertArgumentsForCall(CallExpr *Call, Expr *Fn,
// If too few arguments are available (and we don't have default
// arguments for the remaining parameters), don't make the call.
if (NumArgs < NumArgsInProto) {
if (!FDecl || NumArgs < FDecl->getMinRequiredArguments())
return Diag(RParenLoc, diag::err_typecheck_call_too_few_args)
if (!FDecl || NumArgs < FDecl->getMinRequiredArguments()) {
Diag(RParenLoc, diag::err_typecheck_call_too_few_args)
<< Fn->getType()->isBlockPointerType()
<< NumArgsInProto << NumArgs << Fn->getSourceRange();
// Emit the location of the prototype.
if (FDecl && !FDecl->getBuiltinID())
Diag(FDecl->getLocStart(), diag::note_callee_decl)
<< FDecl;
return true;
}
Call->setNumArgs(Context, NumArgsInProto);
}
@ -3251,9 +3259,8 @@ Sema::ConvertArgumentsForCall(CallExpr *Call, Expr *Fn,
// Emit the location of the prototype.
if (FDecl && !FDecl->getBuiltinID())
Diag(FDecl->getLocStart(),
diag::note_typecheck_call_too_many_args)
<< FDecl;
Diag(FDecl->getLocStart(), diag::note_callee_decl)
<< FDecl;
// This deletes the extra arguments.
Call->setNumArgs(Context, NumArgsInProto);

View File

@ -5,7 +5,7 @@ struct A {
};
struct B : public A {
void f(int a);
void f(int a); // expected-note{{'f' declared here}}
};
void m() {

View File

@ -41,7 +41,7 @@ namespace N1 {
void m()
{
void f(int, int);
void f(int, int); // expected-note{{'f' declared here}}
f(4); // expected-error{{too few arguments to function call}}
void f(int, int = 5); // expected-note{{previous definition}}
f(4); // okay

View File

@ -4,7 +4,7 @@
// Test with pch.
// RUN: %clang_cc1 -emit-pch -o %t %S/functions.h
// RUN: %clang_cc1 -include-pch %t -fsyntax-only -verify %s
// expected-note{{'f1' declared here}}
int f0(int x0, int y0, ...) { return x0 + y0; }
// expected-note{{passing argument to parameter here}}
float *test_f1(int val, double x, double y) {

View File

@ -163,7 +163,7 @@ void test17(int x) {
}
// PR6501
void test18_a(int a); // expected-note {{'test18_a' declared here}}
void test18_a(int a); // expected-note 2 {{'test18_a' declared here}}
void test18(int b) {
test18_a(b, b); // expected-error {{too many arguments to function call, expected 1, have 2}}
test18_a(); // expected-error {{too few arguments to function call, expected 1, have 0}}