From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ed1-x530.google.com (mail-ed1-x530.google.com [IPv6:2a00:1450:4864:20::530]) by sourceware.org (Postfix) with ESMTPS id 9B7C03858C50 for ; Thu, 9 Feb 2023 14:56:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9B7C03858C50 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ed1-x530.google.com with SMTP id d40so1084218eda.8 for ; Thu, 09 Feb 2023 06:56:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=+TG1dEu7CdFG0fRSfPeIobu4+qOiRU69CTi8xFQZDWU=; b=A7MbFgXjb4mBQkmT4y6IzqlKJf8i/j7iqPfKRkahIjqFknWADElPtRhIu9PlPpHij4 XfE/3lxaZMbUWhPQHI+M2VAgTBKnF70a4SfARGhWxxe+rHtVtTkAzS9X08erPdPs5phL H5DSEaUbQQwQfs3Tw87rEMI0gqY9lku6BTdqdvgM2QE3881euVxEC4bPiOQQbRqLAhKk slf89pN84p0MqLtcLrMAhP0hEBrpTzNkYzLlfl7mrcNsxk28LIOosGkebezVvwVUoSg1 2wKDIkQGuPAaQ4SrA+RJHAnpmp/xUBA0CXzgtPRCpohfiXdB2TvLEBT/6ki7zbBwzzyU WKUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=+TG1dEu7CdFG0fRSfPeIobu4+qOiRU69CTi8xFQZDWU=; b=OxohYnXgYpQ+fNoSm27/69FXJ0WxLsVKvRvxpF/9lIFTINYhvxEyPnTskqWJiS9gbJ AIEQJqyOdHJ49prkT4mtPC6CgJaiOU5LHBENZc57j9cTcScad70H97TniKLY/2wMIAr0 rr/ucnr7/cyy+jqKrrTkyMe0fwRLmIgcFEZj4i7cXVOQ73/5UCVwoP2vrYMz1iFaX7Xi 6bjKzw10O+7Mjjbtc8vlbMFIzgoMBPNUVu7Fqp5i1S/ZNAmd1aI18SQXoqU6V0OMBwS2 44tE7U8hWnr4JbWxY53DI+b83bmsDRpGGi413/tRkemXuAqilG4T6sjpR6aTHNK8dT+E GkXw== X-Gm-Message-State: AO0yUKWIfGbwdvCs57XrO3lEogTLTom8+Ox1oehitA37/AgVYhgcGkhb 28g2+CdsCoEmaky+4MBFPo8GMUmJJRU0+bjpqTE= X-Google-Smtp-Source: AK7set+I/TXWGGk7Cq/Fpzpv83fUylL+eBKsYGeDUfnY5XCVlIRHWr9P4B1sXV0w8sMN2tMWMpj64g9ddjRqan+BBlU= X-Received: by 2002:a50:ccdb:0:b0:4ab:1ed0:c2e5 with SMTP id b27-20020a50ccdb000000b004ab1ed0c2e5mr407329edj.6.1675954583356; Thu, 09 Feb 2023 06:56:23 -0800 (PST) MIME-Version: 1.0 References: <7e6e3bbf-0dac-0632-0e8f-372bd32a6923@jguk.org> In-Reply-To: <7e6e3bbf-0dac-0632-0e8f-372bd32a6923@jguk.org> From: Jonathan Wakely Date: Thu, 9 Feb 2023 14:56:12 +0000 Message-ID: Subject: Re: std::string add nullptr attribute To: Jonny Grant Cc: gcc-help Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-0.5 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.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Thu, 9 Feb 2023 at 13:28, Jonny Grant wrote: > > Hello > Could GCC's STL implementation add nullptr attribute to prevent code like this compiling? > > g++ -Wall -o string string.cpp > > std::string c(nullptr); > > > At least GCC STL does reject it at runtime: > > terminate called after throwing an instance of 'std::logic_error' > what(): basic_string: construction from null is not valid > Aborted (core dumped) > > > 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. I assume you mean the nonnull attribute. That was added in 2020 and then reverted because it broke some things: commit 2635f9e5086318f4560997d9741fdda496b9c801 Author: Ville Voutilainen Date: Mon Jun 29 23:59:34 2020 Revert "Add a __nonnnull__ attribute to std::string's _CharT* constructor" This reverts commit b26fd416fb0a734d3f3e56629b6dff2e3c25dd40. commit b26fd416fb0a734d3f3e56629b6dff2e3c25dd40 Author: Ville Voutilainen Date: Sun Jun 28 22:47:05 2020 Add a __nonnnull__ attribute to std::string's _CharT* constructor Add a __nonnnull__ attribute to std::string's _CharT* constructor * include/bits/basic_string.h (string(_CharT*, const _Alloc&)): Add a __nonnull__ attribute. * testsuite/21_strings/basic_string/cons/char/nonnull.cc: New. * testsuite/21_strings/basic_string/cons/wchar_t/nonnull.cc: Likewise. I don't know if anybody analyzed why it broke tests, to see if it could be made to work.