-
Couldn't load subscription status.
- Fork 793
[SYCL] Fix for sycl::detail::string and tests #20076
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
Merged
steffenlarsen
merged 3 commits into
intel:sycl
from
cperkinsintel:cperkins-fix-sycl-string-empty
Sep 18, 2025
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| // RUN: %clangxx -fsycl %s -o %t.out | ||
| // RUN: %t.out | ||
| #include <sycl/sycl.hpp> | ||
|
|
||
| int main() { | ||
| // Default constructor | ||
| sycl::detail::string empty_s; | ||
| assert(empty_s.empty() && "Default constructed string should be empty"); | ||
| assert(strcmp(empty_s.c_str(), "") == 0 && | ||
| "Default constructed string should be empty string"); | ||
|
|
||
| // std::string_view constructor | ||
| std::string_view sv = "Hello, World!"; | ||
| sycl::detail::string s1(sv); | ||
| assert(strcmp(s1.c_str(), "Hello, World!") == 0 && | ||
| "String from string_view constructor should match view content"); | ||
|
|
||
| // Copy constructor | ||
| sycl::detail::string s2(s1); | ||
| assert(strcmp(s2.c_str(), "Hello, World!") == 0 && | ||
| "Copied string should match original"); | ||
| // Check for deep copy | ||
| s1 = "Changed"; | ||
| assert(strcmp(s2.c_str(), "Hello, World!") == 0 && | ||
| "Copied string should be a deep copy"); | ||
|
|
||
| // Move constructor | ||
| sycl::detail::string s3(std::move(s1)); | ||
| assert(strcmp(s3.c_str(), "Changed") == 0 && | ||
| "Moved string should have original content"); | ||
|
|
||
| // string_view assignment | ||
| sycl::detail::string s4; | ||
| s4 = "New String"; | ||
| assert(strcmp(s4.c_str(), "New String") == 0 && | ||
| "String_view assignment should update content"); | ||
|
|
||
| // Copy assignment | ||
| sycl::detail::string s5; | ||
| s5 = s2; | ||
| assert(strcmp(s5.c_str(), "Hello, World!") == 0 && | ||
| "Copy assignment should work correctly"); | ||
|
|
||
| // Move assignment | ||
| sycl::detail::string s6; | ||
| s6 = std::move(s3); | ||
| assert(strcmp(s6.c_str(), "Changed") == 0 && | ||
| "Move assignment should work correctly"); | ||
|
|
||
| // Test c_str() and data() | ||
| assert(strcmp(s6.data(), "Changed") == 0 && | ||
| "data() should return same as c_str()"); | ||
|
|
||
| // Test empty(). Thrice. | ||
| sycl::detail::string s_not_empty("not empty"); | ||
| sycl::detail::string s_empty; | ||
| assert(!s_not_empty.empty() && "String with content should not be empty"); | ||
| assert(sycl::detail::string("").empty() && "Empty string should be empty"); | ||
| assert(s_empty.empty() && "Default constructed string should be empty"); | ||
|
|
||
| // Test swap. | ||
| sycl::detail::string swap_s1("first"); | ||
| sycl::detail::string swap_s2("second"); | ||
| swap(swap_s1, swap_s2); | ||
| assert(strcmp(swap_s1.c_str(), "second") == 0 && | ||
| "swap should exchange content"); | ||
| assert(strcmp(swap_s2.c_str(), "first") == 0 && | ||
| "swap should exchange content"); | ||
|
|
||
| // Comparison operators | ||
| sycl::detail::string compare_s("match"); | ||
| assert((compare_s == "match") && "string == string_view should work"); | ||
| assert(("match" == compare_s) && "string_view == string should work"); | ||
| assert(!(compare_s == "no match") && "string == string_view should fail"); | ||
|
|
||
| return 0; | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.