From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by sourceware.org (Postfix) with ESMTPS id 279B8385801A for ; Sat, 27 Mar 2021 15:33:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 279B8385801A Received: by mail-wm1-x333.google.com with SMTP id j4-20020a05600c4104b029010c62bc1e20so4472175wmi.3 for ; Sat, 27 Mar 2021 08:33:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=IJu/Z8hTFFO0blviyzGH9EDKr993biJLkRTxvQwqVwg=; b=ste7ES8oRb7dTuShqtyb2KFnY3QWWxEtxlXFi57Qtg0F/IrFGc0G7k4YGTahLTgxW5 z6yvvQk5jjqLfa0o7rMwZeVPag8ETo772r57MtwJ+wxlhFBwFNRf2Fi2iOPkKlxQNJ1O U61UxV8wZPUbc+fLT6bPcl5eP+q5Ql6G4g0MqDCep6Y5pkpT2Ngsy+fwsrFVvdwp5Erp S/qH4cHsWDCRKfSCo5Co9Jf5b13iNY9k/2kBc4FYT0FQqVCTuS/TTLPsGyNRUuqfI42E aJBzCkHILA55m4K3wBETv9pLGMpjTDaRJLcQl7Zn00e3PUXYjmSAQOH7DHGEzhCkP6PP 4Hqw== X-Gm-Message-State: AOAM533Fo3t9rAfSRQtabv/AJPjVz6u5dp0zBEz/x0cjbnn1xpQq8khB CSjF3nS4gywQqoQEpTRiOtfZNRuIrLTWcO8TNu8= X-Google-Smtp-Source: ABdhPJy5hxTiBMXcRICSVJmlmSLcsnM0rdNqtLdVIRFFYvx1zKUqSaXZGqC2FF2GgqhXPTv5np1EaboZqN+igfEW+Pk= X-Received: by 2002:a1c:b007:: with SMTP id z7mr17576172wme.14.1616859184575; Sat, 27 Mar 2021 08:33:04 -0700 (PDT) MIME-Version: 1.0 References: <7eeb24bf-58cc-5316-807e-64434ecf4b83.ref@yahoo.fr> <7eeb24bf-58cc-5316-807e-64434ecf4b83@yahoo.fr> In-Reply-To: From: Jonathan Wakely Date: Sat, 27 Mar 2021 15:32:53 +0000 Message-ID: Subject: Re: Questions about std::string::operator=(char) To: tika Cc: "libstdc++" Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libstdc++@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libstdc++ mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 27 Mar 2021 15:33:07 -0000 On Sat, 27 Mar 2021 at 14:58, tika wrote: > > I understand. I do not think there is a bug in the STL, only a grey area. > > My primary concern is the detection of the bug in my (the user) code in > unit testing. That's the bug I mean in the 'bug detected!' comment. > > A warning by the compiler would be nice and sufficient to avoid most > cases of this mistake, which unit testing can detect like this: > > std::string s; > s = some_function_returning_int_0(); > EXPECT_EQ(s, s.c_str()); > > Which makes it seem UB is involved. And the fact that the MS STL > handles the case differently, with a warning, which is nice, and > providing a different result (making s zero length) does force the case > into UB territory, doesn't it? No, that's not how UB works. If MS does that then they have a bug. But I've looked at their code, and I don't see how they can do what you see, because the code looks like it creates a string of length 1: https://github.com/microsoft/STL/blob/6aed1a69d64367bad60a4c9714d7658fe6c70f4d/stl/inc/xstring#L3095-L3101