[libcxx-commits] [PATCH] D76636: [RFC] Added type trait to remove address space qualifier from type

Anastasia Stulova via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Mon Mar 23 12:00:59 PDT 2020

Anastasia created this revision.
Anastasia added reviewers: mclow.lists, ldionne, EricWF.
Herald added a subscriber: dexonsmith.

As I am not developing `libcxx`, I am not familiar with the process. However, I was wondering if it makes sense to add the following feature.

Clang provides experimental support for address spaces in C++ mode that are represented as type qualifiers (following ISO/IEC JTC1 SC22 WG14 N1169 Section 5.1.2). It would be convenient to have a utility to remove address space from the type just like other qualifiers e.g. `remove_cv`.

It is not part of any official spec and therefore I am adding double underscore prefix to the name. Also the feature is guarded on the compilation with Clang since address spaces in C++ is currently just a Clang extension.

The need for this feature has been discussed in:

Any feedback is valuable!



Index: libcxx/test/libcxx/type_traits/address_space.pass.cpp
--- /dev/null
+++ libcxx/test/libcxx/type_traits/address_space.pass.cpp
@@ -0,0 +1,22 @@
+// 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
+#include <type_traits>
+#ifdef __clang__
+typedef int __attribute__((address_space(2))) intAS2;
+void foo(){
+  std::__remove_address_space<intAS2> i;
+  (void)i;
+int main(int, char**) {
+  return 0;
Index: libcxx/include/type_traits
--- libcxx/include/type_traits
+++ libcxx/include/type_traits
@@ -65,6 +65,11 @@
     template <class T> struct add_volatile;
     template <class T> struct add_cv;
+#ifdef __clang__
+    // Remove address space from type.
+    template <class T> struct __remove_address_space;
     // Reference transformations:
     template <class T> struct remove_reference;
     template <class T> struct add_lvalue_reference;
@@ -700,6 +705,14 @@
 template <class _Tp> using remove_cv_t = typename remove_cv<_Tp>::type;
+#ifdef __clang__
+// __remove_address_space
+template<class... T> struct __remove_address_space;
+template <class _Tp> struct __remove_address_space<_Tp> { typedef _Tp type; };
+template <class _Tp, int I> struct __remove_address_space<_Tp __attribute__((address_space(I)))> { typedef _Tp __attribute__((address_space(I))) type; };
 // is_void
 template <class _Tp> struct __libcpp_is_void       : public false_type {};

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D76636.252097.patch
Type: text/x-patch
Size: 1888 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20200323/cf53600a/attachment.bin>

More information about the libcxx-commits mailing list