Re: std::cout breaks after nullptr

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

 



On 2019-03-24 19:40 +0000, Jonny Grant wrote:
> Can I ask, for this nonnull attribute, would it also detect for 
> std::cin, std::err, std::clog as well as std::cout ? Worth adding for 
> std::wcin, std::wcout, std::cerr, std::wclog too.

Adding this attribute to basic_ostream will cover std::cout, std::clog,
std::cerr etc.  For input streams we can't do that because:

char *useless = nullptr;
cin >> useless;  // expect EOF here

is perfectly valid when cin reaches EOF (for e.g. though this code seems
stupid).

> Are there other places where nullptr would not be valid? There are lots 
> of classes, eg <streambuf>

Adding this for basic_ostream also applies to ostringstream because it inherits
basic_ostream.

Unfortunately Marc just told me nonnull is also an optimization attribute.  So
adding it would optimize the null check in operator<< away.  Maybe we need a new
attribute?  Called "warn_if_null"?
-- 
Xi Ruoyao <xry111@xxxxxxxxxxxxxxxx>
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