[clang] [clang] Implement the __builtin_type_order intrinsic for P2830R10 Constexpr Type Ordering (PR #216462)

Matthias Wippich via cfe-commits cfe-commits at lists.llvm.org
Sun Aug 16 06:01:42 PDT 2026


================
@@ -2886,6 +2886,49 @@ class CXXPseudoDestructorExpr : public Expr {
   }
 };
 
+/// Represents a C++26 __builtin_type_order(T, U) expression. Used to implement
+/// std::type_order.
+class BuiltinTypeOrderExpr final : public Expr {
----------------
Tsche wrote:

That too would require special casing for this one of a kind builtin. We currently only support bool and size_t as return types, not int.

Returning size_t 1/2/3 and then in library `__builtin_type_order(U, T) <=> 1` could work (and I do have an implementation for that) but I find that strange. 

Generally speaking I don't feel great about returning magic numbers while also breaking libstdc++ compatibility for the sake of a smaller patch. Especially considering that we already have utilities to look up `std::strong_ordering` since we need it for the 3way comparison anyway. 

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


More information about the cfe-commits mailing list