]> granicus.if.org Git - clang/commitdiff
PR13243: When deducing a non-type template parameter which is specified as an
authorRichard Smith <richard-llvm@metafoo.co.uk>
Sun, 8 Jul 2012 04:37:51 +0000 (04:37 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Sun, 8 Jul 2012 04:37:51 +0000 (04:37 +0000)
expression, skip over any SubstNonTypeTemplateParmExprs which alias templates
may have inserted before checking for a DeclRefExpr referring to a non-type
template parameter declaration.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@159909 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaTemplateDeduction.cpp
test/SemaTemplate/alias-templates.cpp

index 310d9b36cba22b99f61febc41c826500cc078a36..b8ec59ee1d6931a8d76365b8869c3ff21bd820f0 100644 (file)
@@ -137,8 +137,17 @@ DeduceTemplateArguments(Sema &S,
 /// 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());
index 75615ee29517e78b00ccc634056904a3107cf43a..a074bc4e1e6b90cc968f2a44e0b6e5c16081ef51 100644 (file)
@@ -100,3 +100,12 @@ namespace PR11848 {
   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>);
+}