<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/58679>58679</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [clang] Template argument expressions are not full expressions for the purposes of unexpanded packs
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang:frontend,
            rejects-valid
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
            mizvekov
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          mizvekov
      </td>
    </tr>
</table>

<pre>
    Repro: https://godbolt.org/z/rn8e3GP6c
```
template <class> constexpr int A = 1;

template <int> struct B;
template <> struct B<1> { using b1 = void; };

template <class> using C = char;

template <class... Ds> int D{ B<A<C<Ds>>>{}... };
```

The pattern contains an unexpanded pack, but it's just syntatic.
We incorrectly don't convert the expression, leaving it as a instantiation dependent DeclRef, and then
incorrectly specialize the primary template for B.

This is diagnosed with:
```
<source>:8:31: error: implicit instantiation of undefined template 'B<A<C<Ds>>>'
template <class... Ds> int D{ B<A<C<Ds>>>{}... };
                              ^
<source>:3:23: note: template is declared here
template <int> struct B;
                      ^
<source>:8:44: error: pack expansion does not contain any unexpanded parameter packs
template <class... Ds> int D{ B<A<C<Ds>>>{}... };
```

With recent changes (https://reviews.llvm.org/D136564) regarding sugared substitution of default template arguments, we would start misdiagnosing this snippet as well (continued from above):
```
struct E {
  template <class E1, class = typename B<A<E1>>::b1> E(E1);
};

template <typename... Es> int F{ E(C<Es>{})... };
```

And this is diagnosed with:
```
<source>:14:34: error: no matching conversion for functional-style cast from 'C<Es>' (aka 'char') to 'E'
template <typename... Es> int F{ E(C<Es>{})... };
                                 ^~~~~~~~~
<source>:10:8: note: candidate constructor (the implicit copy constructor) not viable: no known conversion from 'C<Es>' (aka 'char') to 'const E' for 1st argument
struct E {
       ^
<source>:10:8: note: candidate constructor (the implicit move constructor) not viable: no known conversion from 'C<Es>' (aka 'char') to 'E' for 1st argument
struct E {
       ^
<source>:11:54: note: candidate template ignored: substitution failure [with E1 = C<Es>]: implicit instantiation of undefined template 'B<A<C<Ds>>>'
  template <class E1, class = typename B<A<E1>>::b1> E(E1);
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy9Vsty2zgQ_BrqgrKKD1GUDjroYe91K5WqnEEQlBCTAAsApVW-fnsgSjIT25ts1usiTeE5Mz09DZSmOq8-yc6aKFuzg_edw48ofcKzN1VpGj81do_WN7xWL2T2x59zEcW7KF5H83h4QtPLtmu4lyzKtqLhDjs9MmG08_KvzjKlPVtjbMeSKNsMO_ywELNomfO2F55tbjNfzhlP2CbUjooN653Se1YmwcjRqAqrMbB7x9zNz8vabVgqDtz-05rpdMp2YSXFtSPz5MsaL_zbhqHhKTbwgeaPXBljd_n_-SBZx72XVhNwnivtGNes10CQ60pWGBbPUbplZe-Z8lFaOPa1d565M6Z7JaaXnb5I-CWMtVL45swqozHV06ZHaT3zMERJkc4pGtqyRvIjIaA847CJ1c5z7RX2NJpVspMwT5FK0XySNS2BQ7SRvlh8ac51UijeqG8yWOqsark9sxuItbFsMx1HrhzDUym-18Yh0JPyB6Liq2hlW2d6K2RAeL3AmyVEYGmtsfRDwZISCGYch6mBZSVrpWHhntO0eCt3afFB-Wfv_kX546uRZnhT-se08ZK-N8cIPOSGW0R2kFb-fGn9mgsE9mw2Aps4yQJDXSCLkY78u1IYRDmPKWx5K0HysND9nwX2BaRiICkxGVWu9_A0Shdj3bPyqOTJTZvm2A7it0uyeT6fRekSq_fcVlQqrt8HtF1fOq98f2UY-MX7xt9Tw-2-b2HSUdWcJDuZvsEyz1GJrXID52lLT2XgtOo6GerwJJuGHCQkle5hrLamZbw0Rwln3qqPIcVBFa85_gFg9piQP5ffJHv-jCJHZm44PyZXjNFal0FnURILWri8A_2uwF43pfQ83tL5ROmkrSiVofuSROz7U3lcB-n5DclIiMHZmMbasJZ7caBEXIQy0JnEqu61oPTy5sH5cyOZ4NDckAtIxD2ItKBs8WdO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