Re: std::string add nullptr attribute

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

 



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.
> 
> 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.

-- 
Xi Ruoyao <xry111@xxxxxxxxxxx>
School of Aerospace Science and Technology, Xidian University




[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