Skip to content

Commit 1525c7b

Browse files
authored
[C++ for OpenCL] Added __remove_address_space feature (#647)
Add documentation of __remove_address_space functionality in C++ for OpenCL 2021.
1 parent fac94e4 commit 1525c7b

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

cxx4opencl/address_spaces.txt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,3 +551,31 @@ defdefptr = addrspace_cast<int * *>(cnstdefptr); // illegal.
551551
defdefptr = reinterpret_cast<int * *>(locdefptr); // legal.
552552
defdefptr = reinterpret_cast<int * *>(cnstdefptr); // legal.
553553
------------
554+
555+
[[remove-addrspace]]
556+
==== Address space removal
557+
558+
`+template<class T> struct __remove_address_space;+`
559+
560+
{cpp} for OpenCL 2021 supports utility `+__remove_address_space+` which allows to
561+
derive types that have address space qualifiers removed. Its effect is analogous
562+
to `+__remove_const+` and other similar traits in {cpp}17 `[meta.trans]`. The
563+
utility only removes an address space qualifier from a given type, therefore, other
564+
type qualifiers such as `+const+` or `+volatile+` remain unchanged.
565+
566+
[source,cpp]
567+
----------
568+
template<typename T>
569+
void foo(T *par) {
570+
T var1; // error: function scope variable cannot be declared in global
571+
// address space
572+
__private T var2; // error: conflicting address space qualifiers are provided
573+
// between types '__private T' and '__global int'
574+
__private __remove_address_space<T>::type var3; // type of var3 is __private int
575+
}
576+
577+
void bar() {
578+
__global int* ptr;
579+
foo(ptr);
580+
}
581+
----------

0 commit comments

Comments
 (0)