[Bug c++/106753] New: Give -Wunused-value warning for user-defined literal expressions with discarded result
redi at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Fri Aug 26 10:52:50 GMT 2022
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]].
More information about the Gcc-bugs
mailing list