[clang] [clang-tools-extra] [Clang] Implement `__builtin_sort_pack` (PR #225025)

Corentin Jabot via cfe-commits cfe-commits at lists.llvm.org
Wed Sep 30 06:18:42 PDT 2026


================
@@ -1888,6 +1888,35 @@ using MyTypeList = TypeList<__builtin_dedup_pack<int, double, int, char, double,
 - The resulting pack is currently only supported for expansion in template argument lists and base specifiers.
 - This builtin cannot be assigned to a template template parameter.
 
+### \_\_builtin_sort_pack
+
+```c++
+template <class... Ts>
+using __builtin_sort_pack = ...;
+```
+
+This alias takes a template parameter pack `Ts` and produces a new unexpanded pack containing the same types
+sorted by [`__builtin_type_order`](#builtin-type-order).
+
+The resulting pack can be expanded in contexts like template argument lists or base specifiers.
+
+**Example of Use**:
+
+```c++
+template <typename...> struct TypeList;
+
+// Combined with `__builtin_dedup_pack` to canonicalize a type list.
+template <typename ...ExtraTypes>
+using MyTypeList = TypeList<
+    __builtin_sort_pack<__builtin_dedup_pack<int, double, ExtraTypes...>...>...>;
----------------
cor3ntin wrote:

nah, it removes all duplicates, even if they are not adjacents

https://github.com/llvm/llvm-project/pull/225025


More information about the cfe-commits mailing list