[cfe-commits] r88722 - in /cfe/trunk: lib/Sema/SemaTemplateDeduction.cpp test/SemaTemplate/instantiate-member-pointers.cpp
Douglas Gregor
dgregor at apple.com
Fri Nov 13 15:45:44 PST 2009
Author: dgregor
Date: Fri Nov 13 17:45:44 2009
New Revision: 88722
URL: http://llvm.org/viewvc/llvm-project?rev=88722&view=rev
Log:
Template argument deduction of a non-type template parameter from a
template argument.
Modified:
cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp
cfe/trunk/test/SemaTemplate/instantiate-member-pointers.cpp
Modified: cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp?rev=88722&r1=88721&r2=88722&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp Fri Nov 13 17:45:44 2009
@@ -126,7 +126,6 @@
/// from the given type- or value-dependent expression.
///
/// \returns true if deduction succeeded, false otherwise.
-
static Sema::TemplateDeductionResult
DeduceNonTypeTemplateArgument(ASTContext &Context,
NonTypeTemplateParmDecl *NTTP,
@@ -166,6 +165,43 @@
return Sema::TDK_Success;
}
+/// \brief Deduce the value of the given non-type template parameter
+/// from the given declaration.
+///
+/// \returns true if deduction succeeded, false otherwise.
+static Sema::TemplateDeductionResult
+DeduceNonTypeTemplateArgument(ASTContext &Context,
+ NonTypeTemplateParmDecl *NTTP,
+ Decl *D,
+ Sema::TemplateDeductionInfo &Info,
+ llvm::SmallVectorImpl<TemplateArgument> &Deduced) {
+ assert(NTTP->getDepth() == 0 &&
+ "Cannot deduce non-type template argument with depth > 0");
+
+ if (Deduced[NTTP->getIndex()].isNull()) {
+ Deduced[NTTP->getIndex()] = TemplateArgument(D->getCanonicalDecl());
+ return Sema::TDK_Success;
+ }
+
+ if (Deduced[NTTP->getIndex()].getKind() == TemplateArgument::Expression) {
+ // Okay, we deduced a declaration in one case and a dependent expression
+ // in another case.
+ return Sema::TDK_Success;
+ }
+
+ if (Deduced[NTTP->getIndex()].getKind() == TemplateArgument::Declaration) {
+ // Compare the declarations for equality
+ if (Deduced[NTTP->getIndex()].getAsDecl()->getCanonicalDecl() ==
+ D->getCanonicalDecl())
+ return Sema::TDK_Success;
+
+ // FIXME: Fill in argument mismatch information
+ return Sema::TDK_NonDeducedMismatch;
+ }
+
+ return Sema::TDK_Success;
+}
+
static Sema::TemplateDeductionResult
DeduceTemplateArguments(ASTContext &Context,
TemplateParameterList *TemplateParams,
@@ -847,7 +883,10 @@
if (Arg.getKind() == TemplateArgument::Expression)
return DeduceNonTypeTemplateArgument(Context, NTTP, Arg.getAsExpr(),
Info, Deduced);
-
+ if (Arg.getKind() == TemplateArgument::Declaration)
+ return DeduceNonTypeTemplateArgument(Context, NTTP, Arg.getAsDecl(),
+ Info, Deduced);
+
assert(false && "Type/value mismatch");
Info.FirstArg = Param;
Info.SecondArg = Arg;
Modified: cfe/trunk/test/SemaTemplate/instantiate-member-pointers.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/instantiate-member-pointers.cpp?rev=88722&r1=88721&r2=88722&view=diff
==============================================================================
--- cfe/trunk/test/SemaTemplate/instantiate-member-pointers.cpp (original)
+++ cfe/trunk/test/SemaTemplate/instantiate-member-pointers.cpp Fri Nov 13 17:45:44 2009
@@ -46,3 +46,10 @@
int &get_X4(X4<&Y::x> x4, Y& y) {
return x4.getMember(y);
}
+
+template<IntMember Member>
+void accept_X4(X4<Member>);
+
+void test_accept_X4(X4<&Y::x> x4) {
+ accept_X4(x4);
+}
More information about the cfe-commits
mailing list