public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/109941] New: [feat req] Add an option to mark STL types as nodiscard
@ 2023-05-23 12:15 roi.jacobson1 at gmail dot com
  2023-05-23 12:36 ` [Bug libstdc++/109941] " de34 at live dot cn
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: roi.jacobson1 at gmail dot com @ 2023-05-23 12:15 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 109941
           Summary: [feat req] Add an option to mark STL types as
                    nodiscard
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: roi.jacobson1 at gmail dot com
  Target Milestone: ---

I would find it useful if there was a macro or some other option to mark types
like std::error_code, std::errc, and std::expected as [[nodiscard]] so
developers will be forced to handle the errors.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug libstdc++/109941] [feat req] Add an option to mark STL types as nodiscard
  2023-05-23 12:15 [Bug libstdc++/109941] New: [feat req] Add an option to mark STL types as nodiscard roi.jacobson1 at gmail dot com
@ 2023-05-23 12:36 ` de34 at live dot cn
  2023-05-23 12:39 ` roi.jacobson1 at gmail dot com
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: de34 at live dot cn @ 2023-05-23 12:36 UTC (permalink / raw)
  To: gcc-bugs

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

Jiang An <de34 at live dot cn> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |de34 at live dot cn

--- Comment #1 from Jiang An <de34 at live dot cn> ---
FYI MSVC STL currently applies [[nodiscard]] to std::lock_guard and
std::scoped_lock.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug libstdc++/109941] [feat req] Add an option to mark STL types as nodiscard
  2023-05-23 12:15 [Bug libstdc++/109941] New: [feat req] Add an option to mark STL types as nodiscard roi.jacobson1 at gmail dot com
  2023-05-23 12:36 ` [Bug libstdc++/109941] " de34 at live dot cn
@ 2023-05-23 12:39 ` roi.jacobson1 at gmail dot com
  2023-05-23 13:24 ` redi at gcc dot gnu.org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: roi.jacobson1 at gmail dot com @ 2023-05-23 12:39 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Roy Jacobson <roi.jacobson1 at gmail dot com> ---
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 :)

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug libstdc++/109941] [feat req] Add an option to mark STL types as nodiscard
  2023-05-23 12:15 [Bug libstdc++/109941] New: [feat req] Add an option to mark STL types as nodiscard roi.jacobson1 at gmail dot com
  2023-05-23 12:36 ` [Bug libstdc++/109941] " de34 at live dot cn
  2023-05-23 12:39 ` roi.jacobson1 at gmail dot com
@ 2023-05-23 13:24 ` redi at gcc dot gnu.org
  2023-05-23 13:24 ` redi at gcc dot gnu.org
  2023-05-23 13:31 ` roi.jacobson1 at gmail dot com
  4 siblings, 0 replies; 6+ messages in thread
From: redi at gcc dot gnu.org @ 2023-05-23 13:24 UTC (permalink / raw)
  To: gcc-bugs

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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Depends on|                            |85973

--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug libstdc++/109941] [feat req] Add an option to mark STL types as nodiscard
  2023-05-23 12:15 [Bug libstdc++/109941] New: [feat req] Add an option to mark STL types as nodiscard roi.jacobson1 at gmail dot com
                   ` (2 preceding siblings ...)
  2023-05-23 13:24 ` redi at gcc dot gnu.org
@ 2023-05-23 13:24 ` redi at gcc dot gnu.org
  2023-05-23 13:31 ` roi.jacobson1 at gmail dot com
  4 siblings, 0 replies; 6+ messages in thread
From: redi at gcc dot gnu.org @ 2023-05-23 13:24 UTC (permalink / raw)
  To: gcc-bugs

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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |enhancement

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug libstdc++/109941] [feat req] Add an option to mark STL types as nodiscard
  2023-05-23 12:15 [Bug libstdc++/109941] New: [feat req] Add an option to mark STL types as nodiscard roi.jacobson1 at gmail dot com
                   ` (3 preceding siblings ...)
  2023-05-23 13:24 ` redi at gcc dot gnu.org
@ 2023-05-23 13:31 ` roi.jacobson1 at gmail dot com
  4 siblings, 0 replies; 6+ messages in thread
From: roi.jacobson1 at gmail dot com @ 2023-05-23 13:31 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Roy Jacobson <roi.jacobson1 at gmail dot com> ---
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
}

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2023-05-23 13:31 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-23 12:15 [Bug libstdc++/109941] New: [feat req] Add an option to mark STL types as nodiscard roi.jacobson1 at gmail dot com
2023-05-23 12:36 ` [Bug libstdc++/109941] " de34 at live dot cn
2023-05-23 12:39 ` roi.jacobson1 at gmail dot com
2023-05-23 13:24 ` redi at gcc dot gnu.org
2023-05-23 13:24 ` redi at gcc dot gnu.org
2023-05-23 13:31 ` roi.jacobson1 at gmail dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).