[cfe-commits] r81779 - in /cfe/trunk: lib/Sema/SemaTemplateDeduction.cpp test/CXX/temp/temp.fct.spec/temp.deduct/temp.deduct.partial/p11.cpp

Douglas Gregor dgregor at apple.com
Mon Sep 14 13:00:47 PDT 2009


Author: dgregor
Date: Mon Sep 14 15:00:47 2009
New Revision: 81779

URL: http://llvm.org/viewvc/llvm-project?rev=81779&view=rev
Log:
Tighten up checking of non-dependent arguments as part of template
argument deduction. This fixes the new test case (since partial
ordering does not have a "verify the results of deduction" step), and
will allow failed template argument deductions to return more quickly
for, e.g., matching class template partial specializations.


Added:
    cfe/trunk/test/CXX/temp/temp.fct.spec/temp.deduct/temp.deduct.partial/p11.cpp
Modified:
    cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp

Modified: cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp?rev=81779&r1=81778&r2=81779&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp Mon Sep 14 15:00:47 2009
@@ -39,7 +39,11 @@
     /// \brief Within template argument deduction from a function call,
     /// we are matching in a case where we can perform template argument
     /// deduction from a template-id of a derived class of the argument type.
-    TDF_DerivedClass = 0x04
+    TDF_DerivedClass = 0x04,
+    /// \brief Allow non-dependent types to differ, e.g., when performing
+    /// template argument deduction from a function call where conversions
+    /// may apply.
+    TDF_SkipNonDependent = 0x08
   };
 }
 
@@ -378,8 +382,14 @@
   }
 
   // If the parameter type is not dependent, there is nothing to deduce.
-  if (!Param->isDependentType())
+  if (!Param->isDependentType()) {
+    if (!(TDF & TDF_SkipNonDependent) && Param != Arg) {
+      
+      return Sema::TDK_NonDeducedMismatch;
+    }
+    
     return Sema::TDK_Success;
+  }
 
   // C++ [temp.deduct.type]p9:
   //   A template type argument T, a template template argument TT or a
@@ -1368,7 +1378,7 @@
     //   In general, the deduction process attempts to find template argument
     //   values that will make the deduced A identical to A (after the type A
     //   is transformed as described above). [...]
-    unsigned TDF = 0;
+    unsigned TDF = TDF_SkipNonDependent;
 
     //     - If the original P is a reference type, the deduced A (i.e., the
     //       type referred to by the reference) can be more cv-qualified than

Added: cfe/trunk/test/CXX/temp/temp.fct.spec/temp.deduct/temp.deduct.partial/p11.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/temp/temp.fct.spec/temp.deduct/temp.deduct.partial/p11.cpp?rev=81779&view=auto

==============================================================================
--- cfe/trunk/test/CXX/temp/temp.fct.spec/temp.deduct/temp.deduct.partial/p11.cpp (added)
+++ cfe/trunk/test/CXX/temp/temp.fct.spec/temp.deduct/temp.deduct.partial/p11.cpp Mon Sep 14 15:00:47 2009
@@ -0,0 +1,10 @@
+// RUN: clang-cc -fsyntax-only %s
+
+template <class T> T* f(int);	// #1 
+template <class T, class U> T& f(U); // #2 
+
+void g() {
+  int *ip = f<int>(1);	// calls #1
+}
+
+// FIXME: test occurrences of template parameters in non-deduced contexts.





More information about the cfe-commits mailing list