public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/111091] New: Split view with double quoted string
@ 2023-08-21 16:30 deco33000 at yandex dot com
2023-08-21 16:31 ` [Bug c++/111091] " deco33000 at yandex dot com
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: deco33000 at yandex dot com @ 2023-08-21 16:30 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111091
Bug ID: 111091
Summary: Split view with double quoted string
Product: gcc
Version: 13.2.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: deco33000 at yandex dot com
Target Milestone: ---
Hi,
I have just been caught by an overlook using range split, but it may happen to
others.
The issue is the Try1 bypasses the delimiter (maybe because of a char
conversion?)
The other versions work fine though..
As usual, to ease your life: https://godbolt.org/z/7nMK46bjq
--------------------------------------------
#include <iostream>
#include <ranges>
#include <string>
#include <string_view>
using namespace std; // for simplicity
int main() {
string a{"Part A / Part B"};
{
cout << "Try 1 : with double quote (wrong behavior? delim is
bypassed)\n";
auto v = ::ranges::views::split(a, "/");
for (auto &&word : v) {
cout << string_view(word) << ' ';
}
cout << "\n\n";
}
{
cout << "Try 1bis : explicitly convert to string: OK\n";
auto v = ::ranges::views::split(a, string("/"));
for (auto &&word : v) {
cout << string_view(word) << ' ';
}
cout << "\n\n";
}
{
cout << "Try 2 : with single quote: OK\n";
auto v = ::ranges::views::split(a, '/');
for (auto &&word : v) {
cout << string_view(word) << ' ';
}
cout << "\n\n";
}
{
cout << "Try 3 : with string delimiter: OK\n";
string delim{"/"};
auto v = ::ranges::views::split(a, delim);
for (auto &&word : v) {
cout << string_view(word) << ' ';
}
cout << "\n\n";
}
{
cout << "Try 4 : with string delimiter: OK\n";
string delim{'/'};
auto v = ::ranges::views::split(a, delim);
for (auto &&word : v) {
cout << string_view(word) << ' ';
}
cout << "\n\n";
}
return 0;
}
Do you think we could make Try1 to work properly ?
Thanks
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/111091] Split view with double quoted string
2023-08-21 16:30 [Bug c++/111091] New: Split view with double quoted string deco33000 at yandex dot com
@ 2023-08-21 16:31 ` deco33000 at yandex dot com
2023-08-21 16:34 ` [Bug libstdc++/111091] " pinskia at gcc dot gnu.org
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: deco33000 at yandex dot com @ 2023-08-21 16:31 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111091
--- Comment #1 from KL <deco33000 at yandex dot com> ---
The godbolt has the clang compiler set but it was just to compare the output
(which has the same output given the same libstdc++).
Sorry for this.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug libstdc++/111091] Split view with double quoted string
2023-08-21 16:30 [Bug c++/111091] New: Split view with double quoted string deco33000 at yandex dot com
2023-08-21 16:31 ` [Bug c++/111091] " deco33000 at yandex dot com
@ 2023-08-21 16:34 ` pinskia at gcc dot gnu.org
2023-08-22 17:48 ` ppalka at gcc dot gnu.org
2023-08-22 18:09 ` deco33000 at yandex dot com
3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-08-21 16:34 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111091
--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Both libstdc++ and libc++ have the same behavior for Try1 ...
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug libstdc++/111091] Split view with double quoted string
2023-08-21 16:30 [Bug c++/111091] New: Split view with double quoted string deco33000 at yandex dot com
2023-08-21 16:31 ` [Bug c++/111091] " deco33000 at yandex dot com
2023-08-21 16:34 ` [Bug libstdc++/111091] " pinskia at gcc dot gnu.org
@ 2023-08-22 17:48 ` ppalka at gcc dot gnu.org
2023-08-22 18:09 ` deco33000 at yandex dot com
3 siblings, 0 replies; 5+ messages in thread
From: ppalka at gcc dot gnu.org @ 2023-08-22 17:48 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111091
Patrick Palka <ppalka at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |ppalka at gcc dot gnu.org
Status|UNCONFIRMED |RESOLVED
Resolution|--- |INVALID
--- Comment #3 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Thanks for the report. Although the behavior may seem surprising I believe
it's working as specified. The string literal "/" when treated as a range
includes the null terminator, so we're actually splitting at occurrences of '/'
followed by '\0', of which there are none in the input string. The
corresponding std::string or std::string_view doesn't include the null
terminator and so does the expected thing.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug libstdc++/111091] Split view with double quoted string
2023-08-21 16:30 [Bug c++/111091] New: Split view with double quoted string deco33000 at yandex dot com
` (2 preceding siblings ...)
2023-08-22 17:48 ` ppalka at gcc dot gnu.org
@ 2023-08-22 18:09 ` deco33000 at yandex dot com
3 siblings, 0 replies; 5+ messages in thread
From: deco33000 at yandex dot com @ 2023-08-22 18:09 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111091
--- Comment #4 from KL <deco33000 at yandex dot com> ---
I get it.
Must be more careful :)
Thanks
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2023-08-22 18:09 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-21 16:30 [Bug c++/111091] New: Split view with double quoted string deco33000 at yandex dot com
2023-08-21 16:31 ` [Bug c++/111091] " deco33000 at yandex dot com
2023-08-21 16:34 ` [Bug libstdc++/111091] " pinskia at gcc dot gnu.org
2023-08-22 17:48 ` ppalka at gcc dot gnu.org
2023-08-22 18:09 ` deco33000 at yandex dot com
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).