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

    <tr>
        <th>Summary</th>
        <td>
            [clang] pack indexing fails when index not laundered through class template
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang
      </td>
    </tr>

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

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

<pre>
    See https://godbolt.org/z/19EKoc86z or [pack_indexing.zip](https://github.com/user-attachments/files/17739083/pack_indexing.zip).

The code contains this definition of `__m_at_c`:
```CPP
#ifdef LAUNDER
template <unsigned long _Idx, unsigned long _Cnt>
struct ___m_at {
        static_assert(_Idx < _Cnt);
        static constexpr unsigned long value = _Idx + _Cnt * 0;
};

template <unsigned long _Np, class... _Ts>
using __m_at_c = _Ts...[___m_at<_Np, sizeof...(_Ts)>::value];
#else
template <unsigned long _Np, class... _Ts>
using __m_at_c = _Ts...[_Np];
#endif
```

When `LAUNDER` is defined, the pack indexing subscript is laundered through the class template `___m_at` and compilation succeeds. When it is not defined, the subscript is used directly, and Clang produces the following diagnostic:

```
pack_indexing3.cpp:12:25: error: invalid index 1 for pack '_Ts' of size 1
   12 | using __m_at_c = _Ts...[_Np];
      | ^
```

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy0VE1v4zYQ_TX0ZRCBH5ZkHXRw_AEULYJFm6JHgyZHEluaFEjKm82vLyg5m4130aKHGoZkyDNv3nt6HBmj6R1iS8pHUu5XckqDD-1VRnmRq7PXX9rfEGFIaYxEbAk_En7svT57mwofesKPr4QfWXP42atN9Qo-ACkfR6n-Ohmn8cW4vng1Iyn3hG_uYEwapnOh_IXw4xQxPMiUpBou6FIk_NgZi_nO6lo0dCMIP36Py5uC0D2h2-X6PCAor_PFJWlchDSYCBo740wy3oHvgFT0dLqcZDopUtHMZ0Go6PLdffp0e8KF6TR28Mv296f94dflacLLaGVCIGI3udk_Dda7Hk4_6RfCd3D3dOcSEYelOaYwqQSnhQCQ-vGNfhOTTEadZIwYEuGbjJZnLAC8IeK-NquMCV_GcDfyKu2U-e1hAeGPMwgQvgX6jlPvv8H8F2lPY1amrIyxKAo4PcevmqZocsXN0mXsc64i5eNNKBG7G0I0r-i7_CffZJCs65DfgdjOrHNSvpLiAm3E_43b03g_zWnT3aXhW3_-GNDl-LzloaLwli7UmUMaEHJI4S2kEKdzVMGMKVdaOTmNATWkIfipH-aGmTi868vxXFyrKEinQfnLaKyc8xsnpRB1LGAmY2Zc59M9iw9zp4gatAmokv2SKzLqzkrXwxi8nhTGuanz1vrPmbY2snc-JqPez8ePfPlwIkWhxpGILeNEbHlJxBYwBB_yD-Ou0hq9GAMMOh8Wpwiv5xzU-WjmdABboAGAcSD1Dv7DS4T5k5tIefgh45VuhW5EI1fYslqwUjBe89XQCtY0lLOuUULKNdWbWlZIKePnsmaUq5VpOeVrxpjgtFwLXmiNddPhZl1WtNL1mawpXqSxhbXXS16PKxPjhC1jFaPlysoz2jivWs5Vdp9wnrduaHPDw3nqI1lTa2KK7xDJJDvv56Wj3N8FrJPGRvg8h2H2Nofh-6B9DNlqCrb9h3Wcp99uD2Pwf6JKhB9nNfNKXgRdW_53AAAA__8Vr-2d">