From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from xry111.site (xry111.site [89.208.246.23]) by sourceware.org (Postfix) with ESMTPS id 2A2793858C50 for ; Thu, 9 Feb 2023 16:30:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2A2793858C50 Authentication-Results: sourceware.org; dmarc=pass (p=reject dis=none) header.from=xry111.site Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=xry111.site DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=xry111.site; s=default; t=1675960234; bh=WYSJyv6QCGjKgOFyn1yhtYJpb20ThPBekH8Z+FrCgzc=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=BiCVnqCzm8vOvYtLa0bARa4TVy17dDTXD9Vfy3e2Ei1Bev8VF23TeoHmeBMBYl4tM gMjQGDs6oyh/OeeFAxo5ga/d2PQ/yA3MSOdcyB1Eh0w57X5uirNIFvuRvTrUin9T0X lutld0gv04CzxNli+a/p5hlf6VBLhvmnaHhGLDvY= Received: from localhost.localdomain (xry111.site [IPv6:2001:470:683e::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature ECDSA (P-384) server-digest SHA384) (Client did not present a certificate) (Authenticated sender: xry111@xry111.site) by xry111.site (Postfix) with ESMTPSA id D3D3665DC8; Thu, 9 Feb 2023 11:30:33 -0500 (EST) Message-ID: <6e30ed8e6c6f08407a5b8259e73fd18a492376b5.camel@xry111.site> Subject: Re: std::string add nullptr attribute From: Xi Ruoyao To: Jonathan Wakely , Jonny Grant Cc: gcc-help Date: Fri, 10 Feb 2023 00:30:32 +0800 In-Reply-To: References: <7e6e3bbf-0dac-0632-0e8f-372bd32a6923@jguk.org> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.46.3 MIME-Version: 1.0 X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,LIKELY_SPAM_FROM,SPF_HELO_PASS,SPF_PASS,TXREP autolearn=no 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, 2023-02-09 at 14:56 +0000, Jonathan Wakely via Gcc-help wrote: > > Note, my code isn't like this, it is just an example to suggest > > adding the nullptr attribute, as its clearly already rejected at > > runtime. >=20 > I assume you mean the nonnull attribute. That was added in 2020 and > then reverted because it broke some things: I remember I'd once made the same mistake when I suggested to add nonnull for ostream::operator<<(const string &) and I was lectured: nonnull is not only a diagnostic attribute, it also allows the compiler to assume the parameter is never null and rendering std::string(nullptr) an undefined behavior. Then the example may just silently continue to run, instead of throwing an exception. It would be an ironic example: an attempt to improve diagnostic finally made diagnostic more difficult. --=20 Xi Ruoyao School of Aerospace Science and Technology, Xidian University