[cfe-commits] r159909 - in /cfe/trunk: lib/Sema/SemaTemplateDeduction.cpp test/SemaTemplate/alias-templates.cpp

Richard Smith richard-llvm at metafoo.co.uk
Sat Jul 7 21:37:51 PDT 2012


Author: rsmith
Date: Sat Jul  7 23:37:51 2012
New Revision: 159909

URL: http://llvm.org/viewvc/llvm-project?rev=159909&view=rev
Log:
PR13243: When deducing a non-type template parameter which is specified as an
expression, skip over any SubstNonTypeTemplateParmExprs which alias templates
may have inserted before checking for a DeclRefExpr referring to a non-type
template parameter declaration.

Modified:
    cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp
    cfe/trunk/test/SemaTemplate/alias-templates.cpp

Modified: cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp?rev=159909&r1=159908&r2=159909&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp Sat Jul  7 23:37:51 2012
@@ -137,8 +137,17 @@
 /// of a non-type template parameter, return the declaration of that
 /// non-type template parameter.
 static NonTypeTemplateParmDecl *getDeducedParameterFromExpr(Expr *E) {
-  if (ImplicitCastExpr *IC = dyn_cast<ImplicitCastExpr>(E))
-    E = IC->getSubExpr();
+  // If we are within an alias template, the expression may have undergone
+  // any number of parameter substitutions already.
+  while (1) {
+    if (ImplicitCastExpr *IC = dyn_cast<ImplicitCastExpr>(E))
+      E = IC->getSubExpr();
+    else if (SubstNonTypeTemplateParmExpr *Subst =
+               dyn_cast<SubstNonTypeTemplateParmExpr>(E))
+      E = Subst->getReplacement();
+    else
+      break;
+  }
 
   if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(E))
     return dyn_cast<NonTypeTemplateParmDecl>(DRE->getDecl());

Modified: cfe/trunk/test/SemaTemplate/alias-templates.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/alias-templates.cpp?rev=159909&r1=159908&r2=159909&view=diff
==============================================================================
--- cfe/trunk/test/SemaTemplate/alias-templates.cpp (original)
+++ cfe/trunk/test/SemaTemplate/alias-templates.cpp Sat Jul  7 23:37:51 2012
@@ -100,3 +100,12 @@
   Hidden1<Hide> h1;  // expected-note{{in instantiation of template class 'PR11848::Hidden1<PR11848::Hide>' requested here}}
   Hidden2<Hide, double, char> h2(1, 2);
 }
+
+namespace PR13243 {
+  template<typename A> struct X {};
+  template<int I> struct C {};
+  template<int I> using Ci = C<I>;
+
+  template<typename A, int I> void f(X<A>, Ci<I>) {}
+  template void f(X<int>, C<0>);
+}





More information about the cfe-commits mailing list