Re: std::string add nullptr attribute

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux