From patchwork Thu Aug 1 16:36:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 1140627 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-506012-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="IN/SNePQ"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=oracle.com header.i=@oracle.com header.b="u4hv44I/"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 45zwsW5Zxxz9sBF for ; Fri, 2 Aug 2019 02:36:15 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to:cc :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=a4mEzGJWBYIRvI5WamNuikCbEbyFT+iT3VrjjKd092Gblz/a32 vHVIN5XtYgPox/OU1nw8vRjQTjUrTIbg8gezbq1t6e4Ia3oofy/e8lIG5MXEx9+R e+N4oSm9lnFqUbfs/GJoZSNV0ra4eJtPCeOZWhiizMNXUZL/Gef8EzSh4= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to:cc :from:subject:message-id:date:mime-version:content-type; s= default; bh=j/FPqRgRDYVEqfO5Aaas2Xn/eJ0=; b=IN/SNePQsk50yzFfiuU8 KVlU2aey76+Mllc0B5LzZRdSLFRMVRceHoHndbmwvugG6bRPCBKibD9bcASfbSxh bFaLAilGq6QtVvJqG/O1eHNu3dvNhH7saHPNcE6aerRTgKo/++Z9eHLZ8xJztDHK UJAYgHRVN6N6CQXn3IVL2OY= Received: (qmail 13043 invoked by alias); 1 Aug 2019 16:36:08 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 13035 invoked by uid 89); 1 Aug 2019 16:36:08 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-6.4 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, SPAM_BODY, SPF_HELO_PASS autolearn=ham version=3.3.1 spammy=HX-Spam-Relays-External:192.168.1.4, H*RU:192.168.1.4, HX-Languages-Length:1697 X-HELO: aserp2120.oracle.com Received: from aserp2120.oracle.com (HELO aserp2120.oracle.com) (141.146.126.78) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 01 Aug 2019 16:36:07 +0000 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x71GO24q126684; Thu, 1 Aug 2019 16:36:05 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=to : cc : from : subject : message-id : date : mime-version : content-type; s=corp-2018-07-02; bh=b/q+5Hru3oyW9LWmoUfOC2TP0K4g2cRWiwqufvezRD4=; b=u4hv44I/gOdzSBEVl375Se9K/AI+PybsxagklKNuqnIRCBY/DAh2oAeb7D/8fhDD4plB RP4/X1kTHofk0TgwFRtcg5J/nq6Ripst+mEcwgNtZdfULbzVsUfJTRHhZZ69kHAjNaiw si2NF/aRuzx9JVpRb/ENQlVEP6MwwvUJjuKkTTplkkxhmSUvAYN651l5NNRHVuI8E4oM RIB9fHIKc6S9sYAMWnq0sCPsJb99NzkjheelCo9WN5DR9GWbyJ5xyjbrL1Y89Oy+/dEC xd3yd4fIidThjrM8AoMuqwDGn2hoFmvAzxoHEoclgb0eeJ99rClNKuL172cxZfbabYXv yA== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by aserp2120.oracle.com with ESMTP id 2u0ejpw0f8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 01 Aug 2019 16:36:04 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x71GN91V025606; Thu, 1 Aug 2019 16:36:04 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by aserp3020.oracle.com with ESMTP id 2u2jp6cgsm-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 01 Aug 2019 16:36:04 +0000 Received: from abhmp0008.oracle.com (abhmp0008.oracle.com [141.146.116.14]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x71Ga3Z7004834; Thu, 1 Aug 2019 16:36:03 GMT Received: from [192.168.1.4] (/95.247.231.7) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 01 Aug 2019 09:36:03 -0700 To: "gcc-patches@gcc.gnu.org" Cc: Jason Merrill From: Paolo Carlini Subject: [C++ Patch] Do not warn about [[nodiscard]] applied to a constructor Message-ID: Date: Thu, 1 Aug 2019 18:36:00 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 X-IsSubscribed: yes Hi, in Cologne, during the presentation of P1771R0, Per Sommerlad pointed out that apparently GCC was already almost doing the right thing - it accepts [[nodiscard]] on a constructor and then a warning is emitted in the relevant potentially dangerous situations - but it does first emit a warning when it encounters the [[nodiscard]] itself. Avoiding the latter seems easy to me - the below passes testing. Something else? Thanks, Paolo. /////////////////// /cp 2019-08-01 Paolo Carlini * tree.c (handle_nodiscard_attribute): Do not warn about nodiscard applied to a constructor. /testsuite 2019-08-01 Paolo Carlini * g++.dg/cpp1z/nodiscard6.C: New. Index: cp/tree.c =================================================================== --- cp/tree.c (revision 273951) +++ cp/tree.c (working copy) @@ -4361,7 +4361,8 @@ handle_nodiscard_attribute (tree *node, tree name, { if (TREE_CODE (*node) == FUNCTION_DECL) { - if (VOID_TYPE_P (TREE_TYPE (TREE_TYPE (*node)))) + if (VOID_TYPE_P (TREE_TYPE (TREE_TYPE (*node))) + && !DECL_CONSTRUCTOR_P (*node)) warning_at (DECL_SOURCE_LOCATION (*node), OPT_Wattributes, "%qE attribute applied to %qD with void " "return type", name, *node); Index: testsuite/g++.dg/cpp1z/nodiscard6.C =================================================================== --- testsuite/g++.dg/cpp1z/nodiscard6.C (nonexistent) +++ testsuite/g++.dg/cpp1z/nodiscard6.C (working copy) @@ -0,0 +1,11 @@ +// { dg-do compile { target c++11 } } + +struct A +{ + [[nodiscard]] A(); +}; + +void foo() +{ + A(); // { dg-warning "ignoring return value" } +}