public inbox for libstdc++@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jonathan Wakely <jwakely.gcc@gmail.com>
To: tika <tikabass@yahoo.fr>
Cc: "libstdc++" <libstdc++@gcc.gnu.org>
Subject: Re: Questions about std::string::operator=(char)
Date: Sat, 27 Mar 2021 10:37:06 +0000	[thread overview]
Message-ID: <CAH6eHdTr71jKCB6YekuNYO=iNqNTCE8vGtnfpZEX4MvQhBLd0Q@mail.gmail.com> (raw)
In-Reply-To: <CAH6eHdSgs3ioWmeUj6Wk_+-NzTL-r+kKGmQhX4cFaFWpm8n=Lw@mail.gmail.com>

On Sat, 27 Mar 2021 at 10:35, Jonathan Wakely wrote:
>
> On Sat, 27 Mar 2021 at 02:26, tika via Libstdc++ <libstdc++@gcc.gnu.org> wrote:
> >
> >
> > Synopsys:?? assigning a char to a std::string makes a string 1 char long,
> > but what happens if that char is zero??? And showing how easily can this
> > UB pass undetected through unit testing...
>
> This is not UB.
>
> >
> > The story:?? I created a stupid bug, that my unit testing did not
> > catch....?? And ended up spending more more time debugging the test than
> > fixing my bug.
> >
> > The bug itself is kind of boring...?? Using the return value of int
> > snd_get_name(int, char*) C function from the alsa library, and putting
> > an int into a string. That's what I think could be a rather common mistake.

See the proposal
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2020/p2037r1.html

The C++ committee rejected the proposal, so it won't be part of the
C++ standard, but it might help you understand the behaviour you see
(and why GCC is correct).

  reply	other threads:[~2021-03-27 10:37 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <7eeb24bf-58cc-5316-807e-64434ecf4b83.ref@yahoo.fr>
2021-03-27  2:25 ` tika
2021-03-27 10:35   ` Jonathan Wakely
2021-03-27 10:37     ` Jonathan Wakely [this message]
2021-03-27 14:58     ` tika
2021-03-27 15:32       ` Jonathan Wakely

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAH6eHdTr71jKCB6YekuNYO=iNqNTCE8vGtnfpZEX4MvQhBLd0Q@mail.gmail.com' \
    --to=jwakely.gcc@gmail.com \
    --cc=libstdc++@gcc.gnu.org \
    --cc=tikabass@yahoo.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).