[Bug libstdc++/109941] [feat req] Add an option to mark STL types as nodiscard

2023-05-23 Thread de34 at live dot cn via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109941

Jiang An  changed:

   What|Removed |Added

 CC||de34 at live dot cn

--- Comment #1 from Jiang An  ---
FYI MSVC STL currently applies [[nodiscard]] to std::lock_guard and
std::scoped_lock.

[Bug libstdc++/109941] [feat req] Add an option to mark STL types as nodiscard

2023-05-23 Thread roi.jacobson1 at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109941

--- Comment #2 from Roy Jacobson  ---
Right, libc++ do that as well since 2019 -
https://reviews.llvm.org/D65900?id=213975.

Although with the RAII classes I think you need to [[nodiscard]] the
constructor which I think (?) is a compiler extension. And you're also much
less likely to have false positives with that so you can actually do that
unconditionally :)

[Bug libstdc++/109941] [feat req] Add an option to mark STL types as nodiscard

2023-05-23 Thread redi at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109941

Jonathan Wakely  changed:

   What|Removed |Added

 Depends on||85973

--- Comment #3 from Jonathan Wakely  ---
That doesn't currently work with GCC, so there's not much point doing it.


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85973
[Bug 85973] [[nodiscard]] on class shall emit a warning for unused anonymous
variable

[Bug libstdc++/109941] [feat req] Add an option to mark STL types as nodiscard

2023-05-23 Thread redi at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109941

Jonathan Wakely  changed:

   What|Removed |Added

   Severity|normal  |enhancement

[Bug libstdc++/109941] [feat req] Add an option to mark STL types as nodiscard

2023-05-23 Thread roi.jacobson1 at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109941

--- Comment #4 from Roy Jacobson  ---
The linked bug is about nodiscard applied to the class together with ignoring
temporary objects. But GCC will when the type is the return value or when the
nodiscard is applied to the constructor:

class [[nodiscard]] err {};
err f();

void g() {
f(); // Warning emitted
}

struct RAII {
[[nodiscard]] RAII(int x);
};

void h() {
RAII(0); // Warning emitted
}