[cfe-commits] r103341 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaOverload.cpp test/CXX/temp/temp.fct.spec/temp.deduct/temp.deduct.type/p17.cpp

Douglas Gregor dgregor at apple.com
Sat May 8 11:13:29 PDT 2010


Author: dgregor
Date: Sat May  8 13:13:28 2010
New Revision: 103341

URL: http://llvm.org/viewvc/llvm-project?rev=103341&view=rev
Log:
When template argument deduction fails because the call had too
many/too few arguments, use the same diagnostic we use for arity
mismatches in non-templates (but note that it's a function template).


Modified:
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/trunk/lib/Sema/SemaOverload.cpp
    cfe/trunk/test/CXX/temp/temp.fct.spec/temp.deduct/temp.deduct.type/p17.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=103341&r1=103340&r2=103341&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Sat May  8 13:13:28 2010
@@ -1069,9 +1069,9 @@
     "%select{function|function|constructor|function|function|constructor|"
     "constructor (the implicit default constructor)|"
     "constructor (the implicit copy constructor)|"
-    "function (the implicit copy assignment operator)}0 not viable: requires"
-    "%select{ at least| at most|}2 %3 argument%s3, but %4 %plural{1:was|:were}4 "
-    "provided">;
+    "function (the implicit copy assignment operator)}0 %select{|template }1"
+    "not viable: requires%select{ at least| at most|}2 %3 argument%s3, but %4 "
+    "%plural{1:was|:were}4 provided">;
 
 def note_ovl_candidate_deleted : Note<
   "candidate %select{function|function|constructor|"

Modified: cfe/trunk/lib/Sema/SemaOverload.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOverload.cpp?rev=103341&r1=103340&r2=103341&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaOverload.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOverload.cpp Sat May  8 13:13:28 2010
@@ -5056,16 +5056,21 @@
   unsigned MinParams = Fn->getMinRequiredArguments();
   
   // at least / at most / exactly
+  // FIXME: variadic templates "at most" should account for parameter packs
   unsigned mode, modeCount;
   if (NumFormalArgs < MinParams) {
-    assert(Cand->FailureKind == ovl_fail_too_few_arguments);
+    assert((Cand->FailureKind == ovl_fail_too_few_arguments) ||
+           (Cand->FailureKind == ovl_fail_bad_deduction &&
+            Cand->DeductionFailure.Result == Sema::TDK_TooFewArguments));
     if (MinParams != FnTy->getNumArgs() || FnTy->isVariadic())
       mode = 0; // "at least"
     else
       mode = 2; // "exactly"
     modeCount = MinParams;
   } else {
-    assert(Cand->FailureKind == ovl_fail_too_many_arguments);
+    assert((Cand->FailureKind == ovl_fail_too_many_arguments) ||
+           (Cand->FailureKind == ovl_fail_bad_deduction &&
+            Cand->DeductionFailure.Result == Sema::TDK_TooManyArguments));
     if (MinParams != FnTy->getNumArgs())
       mode = 1; // "at most"
     else
@@ -5077,7 +5082,8 @@
   OverloadCandidateKind FnKind = ClassifyOverloadCandidate(S, Fn, Description);
 
   S.Diag(Fn->getLocation(), diag::note_ovl_candidate_arity)
-    << (unsigned) FnKind << Description << mode << modeCount << NumFormalArgs;
+    << (unsigned) FnKind << (Fn->getDescribedFunctionTemplate() != 0) << mode 
+    << modeCount << NumFormalArgs;
 }
 
 /// Diagnose a failed template-argument deduction.
@@ -5120,14 +5126,17 @@
       << *Cand->DeductionFailure.getSecondArg();
     return;
   }
+
+  case Sema::TDK_TooManyArguments:
+  case Sema::TDK_TooFewArguments:
+    DiagnoseArityMismatch(S, Cand, NumArgs);
+    return;
       
   // TODO: diagnose these individually, then kill off
   // note_ovl_candidate_bad_deduction, which is uselessly vague.
   case Sema::TDK_InstantiationDepth:
   case Sema::TDK_SubstitutionFailure:
   case Sema::TDK_NonDeducedMismatch:
-  case Sema::TDK_TooManyArguments:
-  case Sema::TDK_TooFewArguments:
   case Sema::TDK_InvalidExplicitArguments:
   case Sema::TDK_FailedOverloadResolution:
     S.Diag(Fn->getLocation(), diag::note_ovl_candidate_bad_deduction);

Modified: cfe/trunk/test/CXX/temp/temp.fct.spec/temp.deduct/temp.deduct.type/p17.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/temp/temp.fct.spec/temp.deduct/temp.deduct.type/p17.cpp?rev=103341&r1=103340&r2=103341&view=diff
==============================================================================
--- cfe/trunk/test/CXX/temp/temp.fct.spec/temp.deduct/temp.deduct.type/p17.cpp (original)
+++ cfe/trunk/test/CXX/temp/temp.fct.spec/temp.deduct/temp.deduct.type/p17.cpp Sat May  8 13:13:28 2010
@@ -15,7 +15,7 @@
   g(b); // OK: cv-qualifiers are ignored on template parameter types
 }
 
-template<short s> void h(int (&)[s]); // expected-note{{failed template argument deduction}}
+template<short s> void h(int (&)[s]); // expected-note{{candidate function template not viable: requires 1 argument, but 2 were provided}}
 void k3() {
   int array[5];
   h(array);





More information about the cfe-commits mailing list