From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 7D2593858404; Fri, 26 Aug 2022 10:52:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7D2593858404 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1661511171; bh=j1prrW4pr354zGvIgO4ml6geRi+UPekY0EV02cbPBns=; h=From:To:Subject:Date:From; b=jeGyXz5xmv5kp86YLuvWhCGcYzXjItPGotVApANLlPEDHOo5oEP64wcqH5mFLOQ9A Z7MYRqCQqKisG7mkcieYNbQUBBStXodXCqsNzpnj6piQIRLM592f3Ldq2XUJgROHtu rD5HmhvawI8Zle0A3PQ07xisp6GvucT/b/WmXtD0= From: "redi at gcc dot 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 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 13.0 X-Bugzilla-Keywords: diagnostic X-Bugzilla-Severity: normal X-Bugzilla-Who: redi at gcc dot gnu.org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status keywords bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D106753 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 #include #include void test() { using namespace std::literals; 2i; // { dg-warning "Wunused-value" } 2s; // { dg-warning "Wunused-value" } ""s; // { dg-warning "Wunused-value" } #if __cplusplus >=3D 201703L ""sv; // { dg-warning "Wunused-value" "" { target c++17 } } #endif } I could add [[nodiscard]] to all these UDLs, but that wouldn't help users w= ho 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 th= at'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]].=