From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 58F2E3858C66 for ; Thu, 11 Jan 2024 20:46:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 58F2E3858C66 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 58F2E3858C66 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1705006020; cv=none; b=hAmTafBW1/XSdUPYKOyUe7qkqHOLdAK7+Pk5DnEFYlzffHztn6+Aes/3bmRcPa+Igdbe/9Hdh5f+EU2ET86cKCPv+wpF7Ihi/D2LNzTNjmQg1fcD4O5/z4ZStYiUR49BC5WcVREmbpjxCv2VGUznEhA0IBj5wIaFxsCEXbVWmdo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1705006020; c=relaxed/simple; bh=547eyIy2Rqwkc9/DQtd5LjkIGfCrKD9+253ypaTaIO0=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=ZCFp914VCiJL+QzGoDrPW9Vvb+6qrk8O02TEezeWQFmMWfnRx0wKShpcJIDMNcC9bnjcoM0d/hNsKJeb8O1fC04PAJYk7EsX92UKFCDHwQBHSrm23SgMYYbqGW5rBI+l/ZPwHiOm1kXzzxZXjdtEqJxv8dL4V6Kjp1JjHdNXKq4= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1705006018; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=PxecPSxhwuiO2vET9mkvpQ0rKco8eEnEg3rkuGWPsWM=; b=QFvT/cbkZU6KdKnXaLX2zFJaefKLGEDNubque4kqqnoggBdrsUJVey2KvaKejknmE4CI8G YoN+Aav9xzh1KpqopVe4i9FcAggvUz9JyUf8z9wD6p+Nd+vSu8AeX1tP/bF+V9NO1bOvQ6 mAOcpad5OY0KtCXYlHX4kmxYdjsRuUI= Received: from mail-yb1-f199.google.com (mail-yb1-f199.google.com [209.85.219.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-216-jgiIArCwM6afu8Fu0wy2bg-1; Thu, 11 Jan 2024 15:46:55 -0500 X-MC-Unique: jgiIArCwM6afu8Fu0wy2bg-1 Received: by mail-yb1-f199.google.com with SMTP id 3f1490d57ef6-dbf228b9961so4394197276.3 for ; Thu, 11 Jan 2024 12:46:55 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705006015; x=1705610815; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=PxecPSxhwuiO2vET9mkvpQ0rKco8eEnEg3rkuGWPsWM=; b=jpYzm9pBeiNi5/u746U0cYIA7K7DNBw05lWGZK463fLnzvaeSz5pxnuYMzc1G/ZRar DHmlm3B9L6azwIDPwPGy8ijG3okugmVlW8bBwynMrp7o3DNWdj0r1Ff4vDZ+Qv4jzda1 xDNkAO5tqhuGbo2IKEbiPvEtxWjXCguFR22Z/OiWngWE9a2VehOoCvfJfVMm5Elev0TC 5sjD50oW3mocQPEqcSPHUha5ANRnPcewjXz3ua95QHgllaAlUO1G3q8FdLLO+HC5O4Qn FTX2fweSaK+EiA1gyRIB0taRabA+cncqlGzDHm1tgwHr4jHvrdUCQFle6CDNaPAV5msp ytRQ== X-Gm-Message-State: AOJu0YzmCKfPwmqf3cfMRSy5WMHuGMiZQVllGCi0c71A7DXadwtMdzrT PnNOq8KQvYLq7T8wgECwFibSn5ad5NyfXSZoHUVpVA6UE9SsFUpixRiIZF+Ib05/sYNfZJrsJ/c XNm2g656SwY8s4VmvzvjaZQBEjx8EVboB6R/oW8ex35uulefZuA== X-Received: by 2002:a05:6902:2309:b0:dbf:cdc:7de6 with SMTP id do9-20020a056902230900b00dbf0cdc7de6mr268853ybb.28.1705006015002; Thu, 11 Jan 2024 12:46:55 -0800 (PST) X-Google-Smtp-Source: AGHT+IHPF48ZdDNj6TPol7BbHjNDZKjpiUCjdBKi/k2HU4Iso5qyazwN6Um8Y6yzaLY42Q/P64DiOznkHFy1Q/OAo2I= X-Received: by 2002:a05:6902:2309:b0:dbf:cdc:7de6 with SMTP id do9-20020a056902230900b00dbf0cdc7de6mr268846ybb.28.1705006014745; Thu, 11 Jan 2024 12:46:54 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Jonathan Wakely Date: Thu, 11 Jan 2024 20:46:38 +0000 Message-ID: Subject: Re: std::basic_string::resize_and_overwrite & oversize passed to lambda To: Ryszard Kabatek Cc: libstdc++@gcc.gnu.org X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-7.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,KAM_SHORT,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: 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 > #include > > 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) > >