[cfe-commits] r74356 - /cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp

Douglas Gregor dgregor at apple.com
Fri Jun 26 16:27:24 PDT 2009


Author: dgregor
Date: Fri Jun 26 18:27:24 2009
New Revision: 74356

URL: http://llvm.org/viewvc/llvm-project?rev=74356&view=rev
Log:
Set the rest of the flags we need to perform template argument
deduction using a base class of the argument type. No actual
functionality change; this is just a hook.

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=74356&r1=74355&r2=74356&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp Fri Jun 26 18:27:24 2009
@@ -37,8 +37,7 @@
     TDF_IgnoreQualifiers = 0x02,
     /// \brief Within template argument deduction from a function call,
     /// we are matching in a case where we can perform template argument
-    /// deduction from a derived class of the argument type.
-    /// FIXME: this is completely unsupported right now.
+    /// deduction from a template-id of a derived class of the argument type.
     TDF_DerivedClass = 0x04
   };
 }
@@ -299,11 +298,11 @@
       if (!PointerArg)
         return Sema::TDK_NonDeducedMismatch;
       
+      unsigned SubTDF = TDF & (TDF_IgnoreQualifiers | TDF_DerivedClass);
       return DeduceTemplateArguments(Context, TemplateParams,
                                    cast<PointerType>(Param)->getPointeeType(),
                                      PointerArg->getPointeeType(),
-                                     Info, Deduced, 
-                                     TDF & TDF_IgnoreQualifiers);
+                                     Info, Deduced, SubTDF);
     }
       
     //     T &
@@ -499,6 +498,11 @@
       if (!RecordArg)
         return Sema::TDK_NonDeducedMismatch;
 
+      // FIXME: Check TDF_DerivedClass here. When this flag is set, we need
+      // to troll through the base classes of the argument and try matching
+      // all of them. Failure to match does not mean that there is a problem,
+      // of course.
+
       ClassTemplateSpecializationDecl *SpecArg 
         = dyn_cast<ClassTemplateSpecializationDecl>(RecordArg->getDecl());
       if (!SpecArg)
@@ -849,6 +853,15 @@
   return TDK_Success;
 }
 
+/// \brief Determine whether the given type T is a simple-template-id type.
+static bool isSimpleTemplateIdType(QualType T) {
+  if (const TemplateSpecializationType *Spec 
+        = T->getAsTemplateSpecializationType())
+    return Spec->getTemplateName().getAsTemplateDecl() != 0;
+  
+  return false;
+}
+                   
 /// \brief Perform template argument deduction from a function call
 /// (C++ [temp.deduct.call]).
 ///
@@ -965,7 +978,17 @@
     //       conversion (4.4).
     if (ArgType->isPointerType() || ArgType->isMemberPointerType())
       TDF |= TDF_IgnoreQualifiers;
-    // FIXME: derived -> base checks
+    //     - If P is a class and P has the form simple-template-id, then the 
+    //       transformed A can be a derived class of the deduced A. Likewise,
+    //       if P is a pointer to a class of the form simple-template-id, the
+    //       transformed A can be a pointer to a derived class pointed to by
+    //       the deduced A.
+    if (isSimpleTemplateIdType(ParamType) ||
+        (isa<PointerType>(ParamType) && 
+         isSimpleTemplateIdType(
+                              ParamType->getAsPointerType()->getPointeeType())))
+      TDF |= TDF_DerivedClass;
+    
     if (TemplateDeductionResult Result
         = ::DeduceTemplateArguments(Context, TemplateParams,
                                     ParamType, ArgType, Info, Deduced,





More information about the cfe-commits mailing list