public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "redi at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/106753] New: Give -Wunused-value warning for user-defined literal expressions with discarded result
Date: Fri, 26 Aug 2022 10:52:50 +0000	[thread overview]
Message-ID: <bug-106753-4@http.gcc.gnu.org/bugzilla/> (raw)

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

            Bug ID: 106753
           Summary: Give -Wunused-value warning for user-defined literal
                    expressions with discarded result
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Keywords: diagnostic
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: redi at gcc dot gnu.org
  Target Milestone: ---

Testcase:

// { dg-do compile { target c++14 } }

#include <string>
#include <complex>
#include <chrono>

void test()
{
  using namespace std::literals;
  2i;  // { dg-warning "Wunused-value" }
  2s;  // { dg-warning "Wunused-value" }
  ""s; // { dg-warning "Wunused-value" }
#if __cplusplus >= 201703L
  ""sv; // { dg-warning "Wunused-value" "" { target c++17 } }
#endif
}


I could add [[nodiscard]] to all these UDLs, but that wouldn't help users who
write their own.

It's theoretically possible that a UDL could modify global variables, and be
called only for its side effects, but that seems disgusting. If we think that's
a real concern, we could only warned for 'constexpr' UDLs, which would avoid
_most_ disgusting global-state-modifying UDLs (but not ones that use
std::is_constant_evaluated() to decide whether to be disgusting).

I think we should just warn for all UDLs though.

Or I could just decorate the ones in libstdc++ with [[nodiscard]].

             reply	other threads:[~2022-08-26 10:52 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-26 10:52 redi at gcc dot gnu.org [this message]
2022-08-26 12:15 ` [Bug c++/106753] " mpolacek at gcc dot gnu.org
2022-08-26 17:55 ` pinskia at gcc dot gnu.org
2022-08-26 18:01 ` redi at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-106753-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).