title: Partial template specialization for variadic types and variadic argument packs expanded into outer type result in ambiguity
body: <p>I'm trying to compile the following program with g++-4.7 (20120228-1):</p>
  
  <pre><code>#include &lt;cstdlib&gt;
  #include &lt;tuple&gt;
  
  template&lt;typename X&gt; struct Y {};
  
  template&lt;typename T, size_t Level, size_t TermLevel&gt; struct A;
  
  // (B) dummy for T=tuple&lt;int, Ts...&gt; just to show it works for simple expansions
  template&lt;typename ... Ts, size_t Level, size_t TermLevel&gt;
  struct A&lt;std::tuple&lt;int, Ts...&gt;, Level, TermLevel&gt;
  {
      A&lt;std::tuple&lt;int, Ts...&gt;, Level+1, TermLevel&gt; value;
  };
  
  template&lt;typename ... Ts, size_t Level&gt;
  struct A&lt;std::tuple&lt;int, Ts...&gt;, Level, Level&gt; {};
  
  
  // (C) ambiguous partial specialization
  template&lt;typename ... Ts, size_t Level, size_t TermLevel&gt;
  struct A&lt;std::tuple&lt;Y&lt;Ts&gt;...&gt;, Level, TermLevel&gt;
  {
      A&lt;std::tuple&lt;Y&lt;Ts&gt;...&gt;, Level+1, TermLevel&gt; value;
  };
  
  template&lt;typename ... Ts, size_t Level&gt;
  struct A&lt;std::tuple&lt;Y&lt;Ts&gt;...&gt;, Level, Level&gt; {};
  
  
  int main(int argc, const char *argv[])
  {
      A&lt;std::tuple&lt;int, float, int&gt;, 0, 5&gt; tint;
      A&lt;std::tuple&lt;Y&lt;int&gt;, Y&lt;float&gt;&gt;, 0, 1&gt; tn;
      return 0;
  }
  </code></pre>
  
  <p>which results in an ambiguity as follows:</p>
  
  <pre><code>g++-4.7 -g -O0 -std=c++0x    specialization_orig.cc   -o specialization_orig
  specialization_orig.cc: In instantiation of 'struct A&lt;std::tuple&lt;Y&lt;int&gt;, Y&lt;float&gt; &gt;, 0ul, 1ul&gt;':
  specialization_orig.cc:33:43:   required from here
  specialization_orig.cc:23:49: error: ambiguous class template instantiation for 'struct A&lt;std::tuple&lt;Y&lt;int&gt;, Y&lt;float&gt; &gt;, 1ul, 1ul&gt;'
  specialization_orig.cc:21:8: error: candidates are: struct A&lt;std::tuple&lt;Y&lt;Ts&gt;...&gt;, Level, TermLevel&gt;
  specialization_orig.cc:27:8: error:                 struct A&lt;std::tuple&lt;Y&lt;Ts&gt;...&gt;, Level, Level&gt;
  specialization_orig.cc:23:49: error: 'A&lt;std::tuple&lt;Y&lt;Ts&gt;...&gt;, Level, TermLevel&gt;::value' has incomplete type
  specialization_orig.cc:6:61: error: declaration of 'struct A&lt;std::tuple&lt;Y&lt;int&gt;, Y&lt;float&gt; &gt;, 1ul, 1ul&gt;'
  </code></pre>
  
  <p>this is kind of weird since variadic argument expansion works for the simple expansion of the argument pack, but fails as soon as the variadic argument packs is expanded to be nested within some other template type.</p>
  
  <p>Is this simply compiler madness or am i doing anything terribly wrong?</p>