[cfe-commits] r156607 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaExpr.cpp lib/Sema/SemaOverload.cpp test/Sema/exprs.c test/SemaCXX/default1.cpp test/SemaCXX/overload-call.cpp test/SemaCXX/overload-member-call.cpp

Richard Smith richard-llvm at metafoo.co.uk
Thu May 10 22:16:41 PDT 2012


Author: rsmith
Date: Fri May 11 00:16:41 2012
New Revision: 156607

URL: http://llvm.org/viewvc/llvm-project?rev=156607&view=rev
Log:
PR11857: When the wrong number of arguments are provided for a function
which expects exactly one argument, include the name of the argument in
the diagnostic text. Patch by Terry Long!

Modified:
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/trunk/lib/Sema/SemaExpr.cpp
    cfe/trunk/lib/Sema/SemaOverload.cpp
    cfe/trunk/test/Sema/exprs.c
    cfe/trunk/test/SemaCXX/default1.cpp
    cfe/trunk/test/SemaCXX/overload-call.cpp
    cfe/trunk/test/SemaCXX/overload-member-call.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=156607&r1=156606&r2=156607&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Fri May 11 00:16:41 2012
@@ -2039,6 +2039,17 @@
     "not viable: requires%select{ at least| at most|}2 %3 argument%s3, but %4 "
     "%plural{1:was|:were}4 provided">;
 
+def note_ovl_candidate_arity_one : Note<"candidate "
+    "%select{function|function|constructor|function|function|constructor|"
+    "constructor (the implicit default constructor)|"
+    "constructor (the implicit copy constructor)|"
+    "constructor (the implicit move constructor)|"
+    "function (the implicit copy assignment operator)|"
+    "function (the implicit move assignment operator)|"
+    "constructor (inherited)}0 %select{|template }1"
+    "not viable: requires%select{ at least| at most|}2 argument %3, but "
+    "%plural{0:none|:%4}4 were provided">;
+
 def note_ovl_candidate_deleted : Note<
     "candidate %select{function|function|constructor|"
     "function |function |constructor |"
@@ -4558,10 +4569,18 @@
   "too few %select{|||execution configuration }0arguments to "
   "%select{function|block|method|kernel function}0 call, "
   "expected %1, have %2">;
+def err_typecheck_call_too_few_args_one : Error<
+  "too few %select{|||execution configuration }0arguments to "
+  "%select{function|block|method|kernel function}0 call, "
+  "argument %1 was not specified">;
 def err_typecheck_call_too_few_args_at_least : Error<
   "too few %select{|||execution configuration }0arguments to "
   "%select{function|block|method|kernel function}0 call, "
   "expected at least %1, have %2">;
+def err_typecheck_call_too_few_args_at_least_one : Error<
+  "too few %select{|||execution configuration }0arguments to "
+  "%select{function|block|method|kernel function}0 call, "
+  "at least argument %1 must be specified">;
 def err_typecheck_call_too_many_args : Error<
   "too many %select{|||execution configuration }0arguments to "
   "%select{function|block|method|kernel function}0 call, "

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=156607&r1=156606&r2=156607&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Fri May 11 00:16:41 2012
@@ -3380,11 +3380,18 @@
   // arguments for the remaining parameters), don't make the call.
   if (NumArgs < NumArgsInProto) {
     if (NumArgs < MinArgs) {
-      Diag(RParenLoc, MinArgs == NumArgsInProto
-                        ? diag::err_typecheck_call_too_few_args
-                        : diag::err_typecheck_call_too_few_args_at_least)
-        << FnKind
-        << MinArgs << NumArgs << Fn->getSourceRange();
+      if (MinArgs == 1 && FDecl && FDecl->getParamDecl(0)->getDeclName())
+        Diag(RParenLoc, MinArgs == NumArgsInProto && !Proto->isVariadic()
+                          ? diag::err_typecheck_call_too_few_args_one
+                          : diag::err_typecheck_call_too_few_args_at_least_one)
+          << FnKind
+          << FDecl->getParamDecl(0) << Fn->getSourceRange();
+      else
+        Diag(RParenLoc, MinArgs == NumArgsInProto && !Proto->isVariadic()
+                          ? diag::err_typecheck_call_too_few_args
+                          : diag::err_typecheck_call_too_few_args_at_least)
+          << FnKind
+          << MinArgs << NumArgs << Fn->getSourceRange();
 
       // Emit the location of the prototype.
       if (FDecl && !FDecl->getBuiltinID() && !IsExecConfig)

Modified: cfe/trunk/lib/Sema/SemaOverload.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOverload.cpp?rev=156607&r1=156606&r2=156607&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaOverload.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOverload.cpp Fri May 11 00:16:41 2012
@@ -8149,9 +8149,14 @@
   std::string Description;
   OverloadCandidateKind FnKind = ClassifyOverloadCandidate(S, Fn, Description);
 
-  S.Diag(Fn->getLocation(), diag::note_ovl_candidate_arity)
-    << (unsigned) FnKind << (Fn->getDescribedFunctionTemplate() != 0) << mode
-    << modeCount << NumFormalArgs;
+  if (modeCount == 1 && Fn->getParamDecl(0)->getDeclName())
+    S.Diag(Fn->getLocation(), diag::note_ovl_candidate_arity_one)
+      << (unsigned) FnKind << (Fn->getDescribedFunctionTemplate() != 0) << mode
+      << Fn->getParamDecl(0) << NumFormalArgs;
+  else
+    S.Diag(Fn->getLocation(), diag::note_ovl_candidate_arity)
+      << (unsigned) FnKind << (Fn->getDescribedFunctionTemplate() != 0) << mode
+      << modeCount << NumFormalArgs;
   MaybeEmitInheritedConstructorNote(S, Fn);
 }
 

Modified: cfe/trunk/test/Sema/exprs.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/exprs.c?rev=156607&r1=156606&r2=156607&view=diff
==============================================================================
--- cfe/trunk/test/Sema/exprs.c (original)
+++ cfe/trunk/test/Sema/exprs.c Fri May 11 00:16:41 2012
@@ -162,11 +162,17 @@
   x = sizeof(x/0);  // no warning.
 }
 
-// PR6501
+// PR6501 & PR11857
 void test18_a(int a); // expected-note 2 {{'test18_a' declared here}}
+void test18_b(int); // expected-note {{'test18_b' declared here}}
+void test18_c(int a, int b); // expected-note {{'test18_c' declared here}}
+void test18_d(int a, ...); // expected-note {{'test18_d' 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}}
+  test18_a(); // expected-error {{too few arguments to function call, argument 'a' was not specified}}
+  test18_b(); // expected-error {{too few arguments to function call, expected 1, have 0}}
+  test18_c(b); // expected-error {{too few arguments to function call, expected 2, have 1}}
+  test18_d(); // expected-error {{too few arguments to function call, at least argument 'a' must be specified}}
 }
 
 // PR7569

Modified: cfe/trunk/test/SemaCXX/default1.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/default1.cpp?rev=156607&r1=156606&r2=156607&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/default1.cpp (original)
+++ cfe/trunk/test/SemaCXX/default1.cpp Fri May 11 00:16:41 2012
@@ -47,6 +47,6 @@
   void j (int f = 4);
   {
     void j (int f); // expected-note{{'j' declared here}}
-    j(); // expected-error{{too few arguments to function call, expected 1, have 0}}
+    j(); // expected-error{{too few arguments to function call, argument 'f' was not specified}}
   }
 }

Modified: cfe/trunk/test/SemaCXX/overload-call.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/overload-call.cpp?rev=156607&r1=156606&r2=156607&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/overload-call.cpp (original)
+++ cfe/trunk/test/SemaCXX/overload-call.cpp Fri May 11 00:16:41 2012
@@ -319,14 +319,20 @@
 namespace test1 {
   template <class T> void foo(T t, unsigned N); // expected-note {{candidate function [with T = int] not viable: no known conversion from 'const char [6]' to 'unsigned int' for 2nd argument}}
   void foo(int n, char N); // expected-note {{candidate function not viable: no known conversion from 'const char [6]' to 'char' for 2nd argument}} 
-  void foo(int n); // expected-note {{candidate function not viable: requires 1 argument, but 2 were provided}}
-  void foo(unsigned n = 10); // expected-note {{candidate function not viable: requires at most 1 argument, but 2 were provided}}
   void foo(int n, const char *s, int t); // expected-note {{candidate function not viable: requires 3 arguments, but 2 were provided}}
   void foo(int n, const char *s, int t, ...); // expected-note {{candidate function not viable: requires at least 3 arguments, but 2 were provided}}
   void foo(int n, const char *s, int t, int u = 0); // expected-note {{candidate function not viable: requires at least 3 arguments, but 2 were provided}}
 
+  // PR 11857
+  void foo(int n); // expected-note {{candidate function not viable: requires argument 'n', but 2 were provided}}
+  void foo(unsigned n = 10); // expected-note {{candidate function not viable: requires at most argument 'n', but 2 were provided}}
+  void bar(int n, int u = 0); // expected-note {{candidate function not viable: requires at least argument 'n', but none were provided}}
+  void baz(int n = 0, int u = 0); // expected-note {{candidate function not viable: requires at most 2 arguments, but 3 were provided}}
+
   void test() {
     foo(4, "hello"); //expected-error {{no matching function for call to 'foo'}}
+    bar(); //expected-error {{no matching function for call to 'bar'}}
+    baz(3, 4, 5); // expected-error {{no matching function for call to 'baz'}}
   }
 }
 

Modified: cfe/trunk/test/SemaCXX/overload-member-call.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/overload-member-call.cpp?rev=156607&r1=156606&r2=156607&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/overload-member-call.cpp (original)
+++ cfe/trunk/test/SemaCXX/overload-member-call.cpp Fri May 11 00:16:41 2012
@@ -72,8 +72,6 @@
   class A {
     template <class T> void foo(T t, unsigned N); // expected-note {{candidate function [with T = int] not viable: no known conversion from 'const char [6]' to 'unsigned int' for 2nd argument}}
     void foo(int n, char N); // expected-note {{candidate function not viable: no known conversion from 'const char [6]' to 'char' for 2nd argument}} 
-    void foo(int n); // expected-note {{candidate function not viable: requires 1 argument, but 2 were provided}}
-    void foo(unsigned n = 10); // expected-note {{candidate function not viable: requires at most 1 argument, but 2 were provided}}
     void foo(int n, const char *s, int t); // expected-note {{candidate function not viable: requires 3 arguments, but 2 were provided}}
     void foo(int n, const char *s, int t, ...); // expected-note {{candidate function not viable: requires at least 3 arguments, but 2 were provided}}
     void foo(int n, const char *s, int t, int u = 0); // expected-note {{candidate function not viable: requires at least 3 arguments, but 2 were provided}}
@@ -83,6 +81,14 @@
 
     void baz(A &d); // expected-note {{candidate function not viable: 1st argument ('const test1::A') would lose const qualifier}}
     void baz(int i); // expected-note {{candidate function not viable: no known conversion from 'const test1::A' to 'int' for 1st argument}} 
+
+    // PR 11857
+    void foo(int n); // expected-note {{candidate function not viable: requires argument 'n', but 2 were provided}}
+    void foo(unsigned n = 10); // expected-note {{candidate function not viable: requires at most argument 'n', but 2 were provided}}
+    void rab(double n, int u = 0); // expected-note {{candidate function not viable: requires at least argument 'n', but none were provided}}
+    void rab(int n, int u = 0); // expected-note {{candidate function not viable: requires at least argument 'n', but none were provided}}
+    void zab(double n = 0.0, int u = 0); // expected-note {{candidate function not viable: requires at most 2 arguments, but 3 were provided}}
+    void zab(int n = 0, int u = 0); // expected-note {{candidate function not viable: requires at most 2 arguments, but 3 were provided}}
   };
 
   void test() {
@@ -93,6 +99,9 @@
     b.bar(0); //expected-error {{no matching member function for call to 'bar'}}
 
     a.baz(b); //expected-error {{no matching member function for call to 'baz'}}
+
+    a.rab(); //expected-error {{no matching member function for call to 'rab'}}
+    a.zab(3, 4, 5); //expected-error {{no matching member function for call to 'zab'}}
   }
 }
 





More information about the cfe-commits mailing list