[cfe-commits] r110318 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/Sema.h lib/Sema/SemaOverload.cpp lib/Sema/SemaTemplateDeduction.cpp test/SemaTemplate/deduction.cpp

John McCall rjmccall at apple.com
Thu Aug 5 02:05:08 PDT 2010


Author: rjmccall
Date: Thu Aug  5 04:05:08 2010
New Revision: 110318

URL: http://llvm.org/viewvc/llvm-project?rev=110318&view=rev
Log:
TDK_InconsistentQuals is really totally different from TDK_Inconsistent.
Rename it to TDK_Underqualified to avoid this sort of confusion and give it
its own diagnostic.


Modified:
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/trunk/lib/Sema/Sema.h
    cfe/trunk/lib/Sema/SemaOverload.cpp
    cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp
    cfe/trunk/test/SemaTemplate/deduction.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=110318&r1=110317&r2=110318&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Thu Aug  5 04:05:08 2010
@@ -1151,6 +1151,9 @@
 def note_ovl_candidate_instantiation_depth : Note<
     "candidate template ignored: substitution exceeded maximum template "
     "instantiation depth">;
+def note_ovl_candidate_underqualified : Note<
+    "candidate template ignored: can't deduce a type for %0 which would "
+    "make %2 equal %1">;
 def note_ovl_candidate_substitution_failure : Note<
     "candidate template ignored: substitution failure %0">;
     

Modified: cfe/trunk/lib/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.h?rev=110318&r1=110317&r2=110318&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/Sema.h (original)
+++ cfe/trunk/lib/Sema/Sema.h Thu Aug  5 04:05:08 2010
@@ -3320,7 +3320,7 @@
     /// cv-qualifiers on a template parameter type that would
     /// otherwise be deduced, e.g., we tried to deduce T in "const T"
     /// but were given a non-const "X".
-    TDK_InconsistentQuals,
+    TDK_Underqualified,
     /// \brief Substitution of the deduced template argument values
     /// resulted in an error.
     TDK_SubstitutionFailure,

Modified: cfe/trunk/lib/Sema/SemaOverload.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOverload.cpp?rev=110318&r1=110317&r2=110318&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaOverload.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOverload.cpp Thu Aug  5 04:05:08 2010
@@ -315,7 +315,7 @@
     break;
       
   case Sema::TDK_Inconsistent:
-  case Sema::TDK_InconsistentQuals: {
+  case Sema::TDK_Underqualified: {
     // FIXME: Should allocate from normal heap so that we can free this later.
     DFIParamWithArguments *Saved = new (Context) DFIParamWithArguments;
     Saved->Param = Info.Param;
@@ -348,7 +348,7 @@
     break;
       
   case Sema::TDK_Inconsistent:
-  case Sema::TDK_InconsistentQuals:
+  case Sema::TDK_Underqualified:
     // FIXME: Destroy the data?
     Data = 0;
     break;
@@ -380,7 +380,7 @@
     return TemplateParameter::getFromOpaqueValue(Data);    
 
   case Sema::TDK_Inconsistent:
-  case Sema::TDK_InconsistentQuals:
+  case Sema::TDK_Underqualified:
     return static_cast<DFIParamWithArguments*>(Data)->Param;
       
   // Unhandled
@@ -402,7 +402,7 @@
     case Sema::TDK_Incomplete:
     case Sema::TDK_InvalidExplicitArguments:
     case Sema::TDK_Inconsistent:
-    case Sema::TDK_InconsistentQuals:
+    case Sema::TDK_Underqualified:
       return 0;
 
     case Sema::TDK_SubstitutionFailure:
@@ -429,7 +429,7 @@
     return 0;
 
   case Sema::TDK_Inconsistent:
-  case Sema::TDK_InconsistentQuals:
+  case Sema::TDK_Underqualified:
     return &static_cast<DFIParamWithArguments*>(Data)->FirstArg;      
 
   // Unhandled
@@ -454,7 +454,7 @@
     return 0;
 
   case Sema::TDK_Inconsistent:
-  case Sema::TDK_InconsistentQuals:
+  case Sema::TDK_Underqualified:
     return &static_cast<DFIParamWithArguments*>(Data)->SecondArg;
 
   // Unhandled
@@ -5592,8 +5592,31 @@
     return;
   }
 
-  case Sema::TDK_Inconsistent:
-  case Sema::TDK_InconsistentQuals: {
+  case Sema::TDK_Underqualified: {
+    assert(ParamD && "no parameter found for bad qualifiers deduction result");
+    TemplateTypeParmDecl *TParam = cast<TemplateTypeParmDecl>(ParamD);
+
+    QualType Param = Cand->DeductionFailure.getFirstArg()->getAsType();
+
+    // Param will have been canonicalized, but it should just be a
+    // qualified version of ParamD, so move the qualifiers to that.
+    QualifierCollector Qs(S.Context);
+    Qs.strip(Param);
+    QualType NonCanonParam = Qs.apply(TParam->getTypeForDecl());
+    assert(S.Context.hasSameType(Param, NonCanonParam));
+
+    // Arg has also been canonicalized, but there's nothing we can do
+    // about that.  It also doesn't matter as much, because it won't
+    // have any template parameters in it (because deduction isn't
+    // done on dependent types).
+    QualType Arg = Cand->DeductionFailure.getSecondArg()->getAsType();
+
+    S.Diag(Fn->getLocation(), diag::note_ovl_candidate_underqualified)
+      << ParamD->getDeclName() << Arg << NonCanonParam;
+    return;
+  }
+
+  case Sema::TDK_Inconsistent: {
     assert(ParamD && "no parameter found for inconsistent deduction result");    
     int which = 0;
     if (isa<TemplateTypeParmDecl>(ParamD))

Modified: cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp?rev=110318&r1=110317&r2=110318&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp Thu Aug  5 04:05:08 2010
@@ -428,9 +428,9 @@
     // type.
     if (Param.isMoreQualifiedThan(Arg) && !(TDF & TDF_IgnoreQualifiers)) {
       Info.Param = cast<TemplateTypeParmDecl>(TemplateParams->getParam(Index));
-      Info.FirstArg = Deduced[Index];
+      Info.FirstArg = TemplateArgument(Param);
       Info.SecondArg = TemplateArgument(Arg);
-      return Sema::TDK_InconsistentQuals;
+      return Sema::TDK_Underqualified;
     }
 
     assert(TemplateTypeParm->getDepth() == 0 && "Can't deduce with depth > 0");

Modified: cfe/trunk/test/SemaTemplate/deduction.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/deduction.cpp?rev=110318&r1=110317&r2=110318&view=diff
==============================================================================
--- cfe/trunk/test/SemaTemplate/deduction.cpp (original)
+++ cfe/trunk/test/SemaTemplate/deduction.cpp Thu Aug  5 04:05:08 2010
@@ -105,3 +105,11 @@
   template <typename T_> void g (T_&); // expected-note{{T_ = int}}
   void h (void) { g(f()); } // expected-error{{no matching function for call}}
 }
+
+namespace test0 {
+  template <class T> void make(const T *(*fn)()); // expected-note {{candidate template ignored: can't deduce a type for 'T' which would make 'T const' equal 'char'}}
+  char *char_maker();
+  void test() {
+    make(char_maker); // expected-error {{no matching function for call to 'make'}}
+  }
+}





More information about the cfe-commits mailing list