-
Notifications
You must be signed in to change notification settings - Fork 769
[SYCL] Make half default constructor constexpr #8067
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -137,7 +137,8 @@ namespace host_half_impl { | |||
// The main host half class | ||||
class __SYCL_EXPORT half { | ||||
public: | ||||
half() = default; | ||||
constexpr half() = default; | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note for reviewers: this is a non-trivial constructor! Reason for that is because trivially constructible classes can't have non-static members with default initializers. From cppreference:
We have non-static member Without default initializer for
Apparently, trivial default constexpr constructors are only available in C++23: P1331R2. Not making the default constructor trivial brings several issues (of different impact):
|
||||
|
||||
constexpr half(const half &) = default; | ||||
constexpr half(half &&) = default; | ||||
|
||||
|
@@ -206,7 +207,7 @@ class __SYCL_EXPORT half { | |||
friend class sycl::ext::intel::esimd::detail::WrapperElementTypeProxy; | ||||
|
||||
private: | ||||
uint16_t Buf; | ||||
uint16_t Buf = {}; | ||||
}; | ||||
|
||||
} // namespace host_half_impl | ||||
|
@@ -272,7 +273,7 @@ class half { | |||
class [[__sycl_detail__::__uses_aspects__(aspect::fp16)]] half { | ||||
#endif | ||||
public: | ||||
half() = default; | ||||
constexpr half() = default; | ||||
constexpr half(const half &) = default; | ||||
constexpr half(half &&) = default; | ||||
|
||||
|
@@ -548,7 +549,7 @@ class [[__sycl_detail__::__uses_aspects__(aspect::fp16)]] half { | |||
friend class sycl::ext::intel::esimd::detail::WrapperElementTypeProxy; | ||||
|
||||
private: | ||||
StorageT Data; | ||||
StorageT Data = {}; | ||||
}; | ||||
} // namespace half_impl | ||||
|
||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// RUN: %clangxx -fsycl -fsyntax-only %s | ||
|
||
#include <sycl/sycl.hpp> | ||
|
||
int main() { | ||
constexpr sycl::half h; | ||
|
||
return 0; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note for reviewers: I honestly don't know why would we need a trivial constructor here, but if necessary, we can return that check back and add a special case for
half
like we used to have, see 909a824