Skip to content

Commit 22daf99

Browse files
[SYCL] Update detail::string_view impl (#19878)
* Fix potential `nullptr` dereference when casting default-constructed object to `std::string_view`. * Make that conversion operator implicit (because why shouldn't it be?) * Not that it's implicit, there is no need in comparison operators with `std::string_view`, because that conversion will be considered implicitly. I also have no idea why there was `__INTEL_PREVIEW_BREAKING_CHANGES` guard before.
1 parent 799718a commit 22daf99

File tree

1 file changed

+3
-39
lines changed

1 file changed

+3
-39
lines changed

sycl/include/sycl/detail/string_view.hpp

Lines changed: 3 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -68,51 +68,15 @@ class string_view {
6868

6969
constexpr const char *data() const noexcept { return str ? str : ""; }
7070

71-
constexpr explicit operator std::string_view() const noexcept {
71+
constexpr operator std::string_view() const noexcept {
72+
if (str == nullptr)
73+
return std::string_view{};
7274
#ifdef __INTEL_PREVIEW_BREAKING_CHANGES
7375
return std::string_view(str, len);
7476
#else
7577
return std::string_view(str);
7678
#endif
7779
}
78-
79-
#ifdef __INTEL_PREVIEW_BREAKING_CHANGES
80-
friend constexpr bool operator==(string_view lhs,
81-
std::string_view rhs) noexcept {
82-
return rhs == std::string_view(lhs);
83-
}
84-
friend constexpr bool operator==(std::string_view lhs,
85-
string_view rhs) noexcept {
86-
return lhs == std::string_view(rhs);
87-
}
88-
89-
friend constexpr bool operator!=(string_view lhs,
90-
std::string_view rhs) noexcept {
91-
return rhs != std::string_view(lhs);
92-
}
93-
friend constexpr bool operator!=(std::string_view lhs,
94-
string_view rhs) noexcept {
95-
return lhs != std::string_view(rhs);
96-
}
97-
#else
98-
friend constexpr bool operator==(string_view lhs,
99-
std::string_view rhs) noexcept {
100-
return rhs == lhs.data();
101-
}
102-
friend constexpr bool operator==(std::string_view lhs,
103-
string_view rhs) noexcept {
104-
return lhs == rhs.data();
105-
}
106-
107-
friend constexpr bool operator!=(string_view lhs,
108-
std::string_view rhs) noexcept {
109-
return rhs != lhs.data();
110-
}
111-
friend constexpr bool operator!=(std::string_view lhs,
112-
string_view rhs) noexcept {
113-
return lhs != rhs.data();
114-
}
115-
#endif
11680
};
11781

11882
} // namespace detail

0 commit comments

Comments
 (0)