[clang] [clang]: implement std::meta::is_type (PR #211653)

Hubert Tong via cfe-commits cfe-commits at lists.llvm.org
Fri Nov 27 15:07:33 PST 2026


================
@@ -0,0 +1,37 @@
+/*===---- meta - header for reflection metafunctions -----------------------===
+ *
+ * Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+ * See https://llvm.org/LICENSE.txt for license information.
+ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+ *
+ *===-----------------------------------------------------------------------===
+ */
+
+#ifndef __CLANG_META
+#define __CLANG_META
+
+#if !defined(__clang__)
+#error "this <meta> header is part of Clang and can only be used when compiling with Clang"
+#elif !defined(__cplusplus)
+#error "<meta> is only available in C++ mode"
+#elif !defined(__CLANG_CXX_REFLECTION__)
+#error "<meta> is only available when -freflection is enabled"
+#else
+
+
+namespace std {
+namespace meta {
+
+using info = decltype(^^int);
+
+/// \return \c true if \p __r represents an entity whose underlying entity is a type; \c false otherwise.
+consteval bool is_type(info __r) {
+    return __builtin_meta_is_type(__r);
+}
----------------
hubert-reinterpretcast wrote:

> The biggest question is compatibility between Clang and libstdc++. Hubert took an action item to contact Jonathan Wakely privately to figure out how much work they are willing to do to accommodate for us. One new option that surfaced during the discussion is that Clang can vend `<__meta_impl>` header that provides bodies of metafunctions that call our builtins, to be included in the right namespace in the `<meta>` header that libstdc++ provides.

The response I got was that libstdc++ discussions had operated with an assumption that Clang would provide `<meta>`. Contributions by Clang developers to libstdc++ to modify their `<meta>` header to be compatible with Clang (potentially by including a `__meta_impl` header) are probably acceptable as an alternative. They are, however, not disposed to proactively make such changes themselves.

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


More information about the cfe-commits mailing list