public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/109737] New: [13/14] Hitting unreachable code when using std::string::assign with iterators
@ 2023-05-04 15:39 enrico.seiler+gccbugs at outlook dot com
  2023-05-04 15:43 ` [Bug libstdc++/109737] " pinskia at gcc dot gnu.org
  0 siblings, 1 reply; 2+ messages in thread
From: enrico.seiler+gccbugs at outlook dot com @ 2023-05-04 15:39 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109737

            Bug ID: 109737
           Summary: [13/14] Hitting unreachable code when using
                    std::string::assign with iterators
           Product: gcc
           Version: 13.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: enrico.seiler+gccbugs at outlook dot com
  Target Milestone: ---

The following emits "runtime error: execution reached an unreachable program
poin" when compiling with `-g -fsanitize=undefined -std=c++20`:

```

#include <cassert>
#include <sstream>
#include <string>

void fits_in_local_buffer()
{
    std::stringstream source{"123457890123456"};
    std::string str;
    str.assign(std::istreambuf_iterator<char>{source},
std::istreambuf_iterator<char>{});
    assert(str == "123457890123456");
}

void does_not_fit_in_local_buffer()
{
    std::stringstream source{"1234578901234567"};
    std::string str;
    str.assign(std::istreambuf_iterator<char>{source},
std::istreambuf_iterator<char>{});
    assert(str == "1234578901234567");
}

int main()
{
    fits_in_local_buffer(); // OK
    does_not_fit_in_local_buffer(); // Not OK
    return 0;
}

```

Compiler Explorer: https://godbolt.org/z/6obr7afon

* Must be at least compiled with CPP20
* Using std::string's constructor with the iterators works.
* Unreachable was introduced with PR109299
https://github.com/gcc-mirror/gcc/commit/bf78b43873b0b7e8f9a430df38749b8b61f9c9b8
* The std::istreambuf_iterator is used as an example, but the same happens when
using, for example, a std::views::iota and using its iterators

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [Bug libstdc++/109737] [13/14] Hitting unreachable code when using std::string::assign with iterators
  2023-05-04 15:39 [Bug libstdc++/109737] New: [13/14] Hitting unreachable code when using std::string::assign with iterators enrico.seiler+gccbugs at outlook dot com
@ 2023-05-04 15:43 ` pinskia at gcc dot gnu.org
  0 siblings, 0 replies; 2+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-05-04 15:43 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109737

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |DUPLICATE

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Already fixed. Dup of bug 109703.

*** This bug has been marked as a duplicate of bug 109703 ***

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-05-04 15:43 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-04 15:39 [Bug libstdc++/109737] New: [13/14] Hitting unreachable code when using std::string::assign with iterators enrico.seiler+gccbugs at outlook dot com
2023-05-04 15:43 ` [Bug libstdc++/109737] " pinskia at gcc dot gnu.org

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).