Skip to content

Commit 9f1167f

Browse files
authored
Fixed documentation about __constant initialization (#667)
1 parent f75c00b commit 9f1167f

1 file changed

Lines changed: 8 additions & 9 deletions

File tree

cxx4opencl/address_spaces.txt

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -368,15 +368,16 @@ kernel void foo() {
368368
}
369369
------------
370370

371-
User defined constructors are not allowed to construct objects in `__constant`
372-
address space. Such objects can be initialized using literals and
373-
initialization lists if they do not require any user defined conversions.
371+
User defined constructors in `__constant` address space must be `constexpr`.
372+
Such objects can be initialized using literals and initialization lists if they
373+
do not require any user defined conversions.
374374

375375
Objects in `__constant` address space can be initialized using:
376376

377377
* Literal expressions;
378378
* Uniform initialization syntax `{}`;
379379
* Using implicit constructors.
380+
* Using constexpr constructors.
380381

381382
[source,cpp]
382383
------------
@@ -386,14 +387,12 @@ struct C1 {
386387

387388
struct C2 {
388389
int m;
389-
C2(int init) __constant {};
390+
constexpr C2(int init) __constant : m(init) {};
390391
};
391392

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-
}
393+
__constant C1 cobj1 = {1};
394+
__constant C1 cobj2 = C1();
395+
__constant C2 cobj3(1);
397396
------------
398397

399398
==== Nested pointers

0 commit comments

Comments
 (0)