public inbox for libstdc++@gcc.gnu.org
 help / color / mirror / Atom feed
* std::basic_string::resize_and_overwrite & oversize passed to lambda
@ 2024-01-11 20:40 Ryszard Kabatek
  2024-01-11 20:46 ` Jonathan Wakely
  0 siblings, 1 reply; 2+ messages in thread
From: Ryszard Kabatek @ 2024-01-11 20:40 UTC (permalink / raw)
  To: libstdc++

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.


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)



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

end of thread, other threads:[~2024-01-11 20:46 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-11 20:40 std::basic_string::resize_and_overwrite & oversize passed to lambda Ryszard Kabatek
2024-01-11 20:46 ` Jonathan Wakely

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