Skip to content

Commit 3d19d6b

Browse files
author
Chen, Brox
committed
update spec and annotated_ptr for void type
1 parent f5399c3 commit 3d19d6b

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

sycl/doc/extensions/experimental/sycl_ext_oneapi_annotated_ptr.asciidoc

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,15 +193,20 @@ struct MyType {
193193
};
194194
195195
struct MyKernel {
196-
annotated_ptr<MyType, properties<PropA>> a; //non-trivially-copyable type
196+
annotated_ptr<MyType, properties<PropA>> a; //non-trivially-copyable type is not allowed
197+
annotated_ptr<void, properties<PropB>> b; //void is legal
197198
...
198199
void operator()() const {
199200
...
201+
*b = ...; //deference is not allowed
200202
}
201203
};
202204
----
203-
It is illegal to apply `annotated_ptr` to a non-trivially-copyable type `T`. In the
204-
above example, encapsulating `annotated_ptr` within `MyType` is illegal.
205+
It is ill-formed to instantiate`annotated_ptr` and `annotated_ref` for a non-trivially-copyable
206+
type `T`. The only exception is that `annotated_ptr` is allowed to be instantiated with `void`.
207+
208+
In the above example, encapsulating `annotated_ptr` within `MyType` is illegal. Encapsulating
209+
`annotated_ptr` with `void` is legal, but it can not be deferenced.
205210

206211
[source,c++]
207212
----

sycl/include/sycl/ext/oneapi/experimental/annotated_ptr/annotated_ptr.hpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ template <typename T, typename... Props>
7878
class annotated_ref<T, detail::properties_t<Props...>> {
7979
using property_list_t = detail::properties_t<Props...>;
8080

81+
static_assert(
82+
std::is_trivially_copyable_v<T>,
83+
"annotated_ref can only be encapsulated with trivially-copyable type!");
84+
8185
private:
8286
T *m_Ptr;
8387
annotated_ref(T *Ptr) : m_Ptr(Ptr) {}
@@ -178,6 +182,11 @@ class __SYCL_SPECIAL_CLASS
178182
__SYCL_TYPE(annotated_ptr) annotated_ptr<T, detail::properties_t<Props...>> {
179183
using property_list_t = detail::properties_t<Props...>;
180184

185+
static_assert(
186+
std::is_same_v<T, void> || std::is_trivially_copyable_v<T>,
187+
"annotated_ptr can only be encapsulated with either trivially-copyable type "
188+
"or void!");
189+
181190
// buffer_location and alignment are allowed for annotated_ref
182191
// Cache controls are allowed for annotated_ptr
183192
using allowed_properties =
@@ -238,11 +247,6 @@ __SYCL_TYPE(annotated_ptr) annotated_ptr<T, detail::properties_t<Props...>> {
238247
annotated_ptr(const annotated_ptr &) = default;
239248
annotated_ptr &operator=(const annotated_ptr &) = default;
240249

241-
static_assert(
242-
std::is_same_v<T, void> || std::is_trivially_copyable_v<T>,
243-
"encapsulating annotated_ptr with non-trivially-copyable type is "
244-
"not supported!");
245-
246250
explicit annotated_ptr(T *Ptr,
247251
const property_list_t & = properties{}) noexcept
248252
: m_Ptr(Ptr) {}

0 commit comments

Comments
 (0)