[libcxx-commits] [clang] [libcxx] [Clang] Add __common_type builtin (PR #99473)
Aaron Ballman via libcxx-commits
libcxx-commits at lists.llvm.org
Mon Aug 19 07:54:58 PDT 2024
================
@@ -0,0 +1,184 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -verify -std=c++17 %s
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -verify -std=c++20 %s
+
+#if !__has_builtin(__builtin_common_type)
+# error
+#endif
+
+// expected-note@*:* {{template declaration from hidden source: template <template <class ...> class, template <class> class, class, class ...>}}
+
+void test() {
+ __builtin_common_type<> a; // expected-error {{too few template arguments for template '__builtin_common_type'}}
+}
+
+struct empty_type {};
+
+template <class T>
+struct type_identity {
+ using type = T;
+};
+
+template <class...>
+struct common_type;
+
+template <class... Args>
+using common_type_t = typename common_type<Args...>::type;
+
+template <class... Args>
+using common_type_base = __builtin_common_type<common_type_t, type_identity, empty_type, Args...>;
+
+template <class... Args>
+struct common_type : common_type_base<Args...> {};
+
+struct Incomplete;
+
+template<>
+struct common_type<Incomplete, Incomplete>;
+
+static_assert(__is_same(common_type_base<>, empty_type));
----------------
AaronBallman wrote:
A test with an attributed type would be helpful. You can use `clang::annotate_type`, `clang::address_space`, and some calling convention on a function as inspiration.
https://github.com/llvm/llvm-project/pull/99473
More information about the libcxx-commits
mailing list