Skip to content

[clang] pack indexing fails when index not laundered through class template #116105

@vasama

Description

@vasama

See https://godbolt.org/z/19EKoc86z or pack_indexing.zip.

The code contains this definition of __m_at_c:

#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];
      |                         ^

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:frontendLanguage frontend issues, e.g. anything involving "Sema"

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions