public inbox for libstdc++@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jonathan Wakely <jwakely@redhat.com>
To: Ryszard Kabatek <rumcajs@gmx.net>
Cc: libstdc++@gcc.gnu.org
Subject: Re: std::basic_string::resize_and_overwrite & oversize passed to lambda
Date: Thu, 11 Jan 2024 20:46:38 +0000	[thread overview]
Message-ID: <CACb0b4==S7+Z-aVGW83ngoqU2X9jbvmUuGNkMpWJRbx_cWCp+g@mail.gmail.com> (raw)
In-Reply-To: <df5e3be6-d807-4475-9ae8-5c49c731bfe2@gmx.net>

On Thu, 11 Jan 2024 at 20:40, Ryszard Kabatek wrote:
>
> Hi!
>
> I'm not sure if this was the intention, but in some cases the expected
> size passed to resize_and_overwrite does not propagate to the lambda
> being called. The value passed to lambda can be greater then the initial
> value.

I fixed this in August with
https://gcc.gnu.org/g:4a2b262597e4a6bc5732d4564673c1e19381dcfa
and backported it to gcc-13 in November as
https://gcc.gnu.org/g:f749564ca5e3d16ee16bf490e329f00041563c2d


>
>
> The code below produces the output:
>
> 16 != 30
> 17 != 30
> 18 != 30
> 19 != 30
> 20 != 30
> 21 != 30
> 22 != 30
> 23 != 30
> 24 != 30
> 25 != 30
> 26 != 30
> 27 != 30
> 28 != 30
> 29 != 30
>
>
> #include<iostream>
> #include<string>
>
> int main()
> {
>    for (std::size_t i = 0; i < 142; ++i)
>    {
>        auto op = [](char*, std::size_t len)
>        {
>           return len;
>        };
>
>        std::string str;
>        str.resize_and_overwrite(i, op);
>
>        if (i != str.size())
>           std::cout << i << " != " << str.size() << std::endl;
>    }
>
>    return 0;
> }
>
>
> Using built-in specs.
> COLLECT_GCC=g++-13
> COLLECT_LTO_WRAPPER=/usr/lib64/gcc/x86_64-suse-linux/13/lto-wrapper
> OFFLOAD_TARGET_NAMES=nvptx-none
> OFFLOAD_TARGET_DEFAULT=1
> Target: x86_64-suse-linux
> Configured with: ../configure CFLAGS=' -fmessage-length=0
> -grecord-gcc-switches -O2 -funwind-tables -fasynchronous-unwind-tables
> -fstack-clash-protection -g' CXXFLAGS=' -fmessage-length=0
> -grecord-gcc-switches -O2 -funwind-tables -fasynchronous-unwind-tables
> -fstack-clash-protection -g' XCFLAGS=' -fmessage-length=0
> -grecord-gcc-switches -O2 -funwind-tables -fasynchronous-unwind-tables
> -fstack-clash-protection -g' TCFLAGS=' -fmessage-length=0
> -grecord-gcc-switches -O2 -funwind-tables -fasynchronous-unwind-tables
> -fstack-clash-protection -g' GDCFLAGS=' -fmessage-length=0
> -grecord-gcc-switches -O2 -funwind-tables -fasynchronous-unwind-tables
> -fstack-clash-protection -g' --prefix=/usr --infodir=/usr/share/info
> --mandir=/usr/share/man --libdir=/usr/lib64 --libexecdir=/usr/lib64
> --enable-languages=c,c++,objc,fortran,obj-c++,ada,go,d,m2
> --enable-offload-targets=nvptx-none, --enable-offload-defaulted
> --without-cuda-driver --enable-checking=release --disable-werror
> --with-gxx-include-dir=/usr/include/c++/13
> --with-libstdcxx-zoneinfo=/usr/share/zoneinfo --enable-ssp
> --disable-libssp --disable-libvtv --enable-cet=auto --disable-libcc1
> --disable-plugin --with-bugurl=https://bugs.opensuse.org/
> --with-pkgversion='SUSE Linux' --with-slibdir=/lib64 --with-system-zlib
> --enable-libstdcxx-allocator=new --disable-libstdcxx-pch
> --enable-libphobos --enable-version-specific-runtime-libs
> --with-gcc-major-version-only --enable-linker-build-id
> --enable-linux-futex --enable-gnu-indirect-function --program-suffix=-13
> --without-system-libunwind --enable-multilib --with-arch-32=x86-64
> --with-tune=generic --enable-link-serialization
> --build=x86_64-suse-linux --host=x86_64-suse-linux
> Thread model: posix
> Supported LTO compression algorithms: zlib
> gcc version 13.2.1 20230912 [revision
> b96e66fd4ef3e36983969fb8cdd1956f551a074b] (SUSE Linux)
>
>


      reply	other threads:[~2024-01-11 20:46 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-11 20:40 Ryszard Kabatek
2024-01-11 20:46 ` Jonathan Wakely [this message]

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='CACb0b4==S7+Z-aVGW83ngoqU2X9jbvmUuGNkMpWJRbx_cWCp+g@mail.gmail.com' \
    --to=jwakely@redhat.com \
    --cc=libstdc++@gcc.gnu.org \
    --cc=rumcajs@gmx.net \
    /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).