public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
* [Bug c++/106753] New: Give -Wunused-value warning for user-defined literal expressions with discarded result @ 2022-08-26 10:52 redi at gcc dot gnu.org 2022-08-26 12:15 ` [Bug c++/106753] " mpolacek at gcc dot gnu.org ` (2 more replies) 0 siblings, 3 replies; 4+ messages in thread From: redi at gcc dot gnu.org @ 2022-08-26 10:52 UTC (permalink / raw) To: gcc-bugs 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]]. ^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c++/106753] Give -Wunused-value warning for user-defined literal expressions with discarded result 2022-08-26 10:52 [Bug c++/106753] New: Give -Wunused-value warning for user-defined literal expressions with discarded result redi at gcc dot gnu.org @ 2022-08-26 12:15 ` 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 2 siblings, 0 replies; 4+ messages in thread From: mpolacek at gcc dot gnu.org @ 2022-08-26 12:15 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106753 Marek Polacek <mpolacek at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |mpolacek at gcc dot gnu.org Last reconfirmed| |2022-08-26 Ever confirmed|0 |1 Status|UNCONFIRMED |NEW ^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c++/106753] Give -Wunused-value warning for user-defined literal expressions with discarded result 2022-08-26 10:52 [Bug c++/106753] New: Give -Wunused-value warning for user-defined literal expressions with discarded result redi at gcc dot gnu.org 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 2 siblings, 0 replies; 4+ messages in thread From: pinskia at gcc dot gnu.org @ 2022-08-26 17:55 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106753 Andrew Pinski <pinskia at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Severity|normal |enhancement --- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> --- >but that seems disgusting. You know if it works, someone will do it, especially with C++ code. ^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c++/106753] Give -Wunused-value warning for user-defined literal expressions with discarded result 2022-08-26 10:52 [Bug c++/106753] New: Give -Wunused-value warning for user-defined literal expressions with discarded result redi at gcc dot gnu.org 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 2 siblings, 0 replies; 4+ messages in thread From: redi at gcc dot gnu.org @ 2022-08-26 18:01 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106753 --- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> --- But it seems reasonable that they should write: (void) 123_disgusting; to silence a warning if they're really creating a literal just for its side effects. ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-08-26 18:01 UTC | newest] Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2022-08-26 10:52 [Bug c++/106753] New: Give -Wunused-value warning for user-defined literal expressions with discarded result redi at gcc dot gnu.org 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
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).