From c1efb3faefa7d42f974fe384dfd45e5127f8afa6 Mon Sep 17 00:00:00 2001
From: Douglas Gregor
Date: Fri, 12 Jun 2009 22:31:52 +0000
Subject: [PATCH] It looks like we've finished off matching of class template
partial specializations; add comments and update the C++ status page
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@73263 91177308-0d34-0410-b5e6-96231b3b80d8
---
lib/Sema/SemaTemplateDeduction.cpp | 10 ++++++++--
lib/Sema/SemaTemplateInstantiate.cpp | 28 +++++++++++++++++++++++-----
www/cxx_status.html | 2 +-
3 files changed, 32 insertions(+), 8 deletions(-)
diff --git a/lib/Sema/SemaTemplateDeduction.cpp b/lib/Sema/SemaTemplateDeduction.cpp
index 252f2d1d0d..48e38ddf14 100644
--- a/lib/Sema/SemaTemplateDeduction.cpp
+++ b/lib/Sema/SemaTemplateDeduction.cpp
@@ -618,12 +618,18 @@ DeduceTemplateArguments(ASTContext &Context,
return Sema::TDK_Success;
}
-
+/// \brief Perform template argument deduction to determine whether
+/// the given template arguments match the given class template
+/// partial specialization per C++ [temp.class.spec.match].
Sema::TemplateDeductionResult
Sema::DeduceTemplateArguments(ClassTemplatePartialSpecializationDecl *Partial,
const TemplateArgumentList &TemplateArgs,
TemplateDeductionInfo &Info) {
- // Deduce the template arguments for the partial specialization
+ // C++ [temp.class.spec.match]p2:
+ // A partial specialization matches a given actual template
+ // argument list if the template arguments of the partial
+ // specialization can be deduced from the actual template argument
+ // list (14.8.2).
llvm::SmallVector Deduced;
Deduced.resize(Partial->getTemplateParameters()->size());
if (TemplateDeductionResult Result
diff --git a/lib/Sema/SemaTemplateInstantiate.cpp b/lib/Sema/SemaTemplateInstantiate.cpp
index 936df1e97d..6814b36ada 100644
--- a/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/lib/Sema/SemaTemplateInstantiate.cpp
@@ -854,11 +854,14 @@ Sema::InstantiateClassTemplateSpecialization(
const TemplateArgumentList *TemplateArgs
= &ClassTemplateSpec->getTemplateArgs();
- // C++ [temp.class.spec]p7:
- // Partial specialization declarations themselves are not found by
- // name lookup. Rather, when the primary template name is used,
- // any previously declared partial specializations of the primary
- // template are also considered.
+ // C++ [temp.class.spec.match]p1:
+ // When a class template is used in a context that requires an
+ // instantiation of the class, it is necessary to determine
+ // whether the instantiation is to be generated using the primary
+ // template or one of the partial specializations. This is done by
+ // matching the template arguments of the class template
+ // specialization with the template argument lists of the partial
+ // specializations.
typedef std::pair MatchResult;
llvm::SmallVector Matched;
@@ -881,13 +884,28 @@ Sema::InstantiateClassTemplateSpecialization(
}
if (Matched.size() == 1) {
+ // -- If exactly one matching specialization is found, the
+ // instantiation is generated from that specialization.
Pattern = Matched[0].first;
TemplateArgs = Matched[0].second;
} else if (Matched.size() > 1) {
+ // -- If more than one matching specialization is found, the
+ // partial order rules (14.5.4.2) are used to determine
+ // whether one of the specializations is more specialized
+ // than the others. If none of the specializations is more
+ // specialized than all of the other matching
+ // specializations, then the use of the class template is
+ // ambiguous and the program is ill-formed.
// FIXME: Implement partial ordering of class template partial
// specializations.
Diag(ClassTemplateSpec->getLocation(),
diag::unsup_template_partial_spec_ordering);
+ } else {
+ // -- If no matches are found, the instantiation is generated
+ // from the primary template.
+
+ // Since we initialized the pattern and template arguments from
+ // the primary template, there is nothing more we need to do here.
}
// Note that this is an instantiation.
diff --git a/www/cxx_status.html b/www/cxx_status.html
index 06f541b534..f1c3fb952d 100644
--- a/www/cxx_status.html
+++ b/www/cxx_status.html
@@ -1895,7 +1895,7 @@ welcome!
14.5.4.1 [temp.class.spec.match] |
N/A |
N/A |
- |
+ |
N/A |
|
--
2.40.0