Skip to content

Commit 603ec1e

Browse files
[C++ for OpenCL] Added examples (#512)
Added examples for the initialization of objects in different address spaces. Co-authored-by: Sven van Haastregt <sven.vanhaastregt@arm.com>
1 parent c58a3fd commit 603ec1e

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

cxx4opencl/address_spaces.txt

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,20 @@ is required for classes with data members that are references because their valu
354354
can not be overwritten trivially. Destructors of local address space objects
355355
are not invoked automatically. They can be called manually.
356356

357+
[source,cpp]
358+
------------
359+
class C {
360+
int m;
361+
};
362+
363+
kernel void foo() {
364+
__local C locobj{}; // error: local address space objects can't be initialized
365+
__local C locobj; // uninitialised object
366+
locobj = {}; // calling copy assignment operator is allowed
367+
locobj.~C(); // local address space object destructors are not invoked automatically.
368+
}
369+
------------
370+
357371
User defined constructors are not allowed to construct objects in `__constant`
358372
address space. Such objects can be initialized using literals and
359373
initialization lists if they do not require any user defined conversions.
@@ -364,6 +378,24 @@ Objects in `__constant` address space can be initialized using:
364378
* Uniform initialization syntax `{}`;
365379
* Using implicit constructors.
366380

381+
[source,cpp]
382+
------------
383+
struct C1 {
384+
int m;
385+
};
386+
387+
struct C2 {
388+
int m;
389+
C2(int init) __constant {};
390+
};
391+
392+
kernel void k() {
393+
__constant C1 cobj1 = {1};
394+
__constant C1 cobj2 = C1();
395+
__constant C2 cobj3 = {1}; // error: user defined constructor can't be used
396+
}
397+
------------
398+
367399
==== Nested pointers
368400

369401
{cpp} for OpenCL does not allow implicit address space conversions in nested

0 commit comments

Comments
 (0)