[Bug libstdc++/88738] treat shared_ptr and unique_ptr more like plain old pointers

drepper.fsp+rhbz at gmail dot com gcc-bugzilla@gcc.gnu.org
Sat Jan 12 10:39:00 GMT 2019


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88738

--- Comment #3 from Ulrich Drepper <drepper.fsp+rhbz at gmail dot com> ---
Created attachment 45416
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=45416&action=edit
Add nodiscard support

As Martin suggested, we could indeed use existing attributes in library code to
warn about some of the problems.  The code from comment #0 is real, this
happened in a project of mine where I mistyped an assignment.  The warning
would have pointed to the problem.

How about the following patch for a start?  This compiles cleanly on x86-64.  I
haven't run the test suite to see whether it breaks some regression tests.

Also, this approach should be extended beyond shared_ptr and unique_ptr,
probably to at least every single bool operatorXX(...) const.  Or even every
single const member function which then of course raises the question whether
the compiler should learn about this…


More information about the Gcc-bugs mailing list