From patchwork Wed May 31 12:04:31 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 769078 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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 3wd8Kw5jZxz9s74 for ; Wed, 31 May 2017 22:04:52 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="yT1Kyyo7"; dkim-atps=neutral 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=PMKphAFbSz3ADW324EWuDnaZeErU/1JYXqwq4Oz6uyB7brrZLO U8m2DStveGns8i65OdrLnjmIrIRKNax2YcJrtUrktkmC1//lJmEKgwlWiNczHG8x xs+maBkC/+fim6jjQ+UdG5eRyJho/oE3O4ECm4DGwYp9IOdz4om/mPNFo= 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=mhhw9hn9B4RE4kk0ko0dgfStgzI=; b=yT1Kyyo7Yz0psO4aGtb3 Pew98W4WvHP8743g+P4l8kuqaqTpVXRhsUzvQpCLEKua5PAwAinpLgAJwjztLRqd FxIsBvCBdDt+umsf2x/8Uv/OEeS9r1+tV28uv2+dUsR7CYONoY+gNxn/klSgCmzQ YlZBjJtE8Ocknt98RJxkVOA= Received: (qmail 56277 invoked by alias); 31 May 2017 12:04:36 -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 56257 invoked by uid 89); 31 May 2017 12:04:36 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.1 required=5.0 tests=BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RP_MATCHES_RCVD, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: userp1040.oracle.com Received: from userp1040.oracle.com (HELO userp1040.oracle.com) (156.151.31.81) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 31 May 2017 12:04:34 +0000 Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by userp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id v4VC4Z6f026748 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 31 May 2017 12:04:35 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id v4VC4YFm009081 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 31 May 2017 12:04:35 GMT Received: from abhmp0003.oracle.com (abhmp0003.oracle.com [141.146.116.9]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id v4VC4YKF023990; Wed, 31 May 2017 12:04:34 GMT Received: from [192.168.1.4] (/79.13.225.104) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 31 May 2017 05:04:34 -0700 To: "gcc-patches@gcc.gnu.org" Cc: Jason Merrill From: Paolo Carlini Subject: [C++ Patch] PR 80896 ("[[nodiscard]] is ignored for functions returning references") Message-ID: <875f093a-0b8f-7ddc-cd46-cece5a24cb2f@oracle.com> Date: Wed, 31 May 2017 14:04:31 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.1.0 MIME-Version: 1.0 X-IsSubscribed: yes Hi, this one appears to be a rather simple case of missing diagnostic: in convert_to_void we aren't calling maybe_warn_nodiscard when we strip an INDIRECT_REF wrapping a CALL_EXPR thus we don't issue the diagnostic that we normally provide for plain CALL_EXPRs (eg, for a func returning a plain int). Tested x86_64-linux. Thanks, Paolo. ////////////////// /cp 2017-05-31 Paolo Carlini PR c++/80896 * cvt.c (convert_to_void): Possibly call maybe_warn_nodiscard for case INDIRECT_REF too in the main switch. /testsuite 2017-05-31 Paolo Carlini PR c++/80896 * g++.dg/cpp1z/nodiscard5.C: New. Index: testsuite/g++.dg/cpp1z/nodiscard5.C =================================================================== --- testsuite/g++.dg/cpp1z/nodiscard5.C (revision 0) +++ testsuite/g++.dg/cpp1z/nodiscard5.C (working copy) @@ -0,0 +1,7 @@ +// PR c++/80896 +// { dg-do compile { target c++11 } } + +int x = 42; +[[nodiscard]] int& func() { return x; } + +int main() { func(); } // { dg-warning "ignoring return value" } Index: cp/cvt.c =================================================================== --- cp/cvt.c (revision 248728) +++ cp/cvt.c (working copy) @@ -1296,6 +1296,8 @@ convert_to_void (tree expr, impl_conv_void implici && !is_reference) warning_at (loc, OPT_Wunused_value, "value computed is not used"); expr = TREE_OPERAND (expr, 0); + if (TREE_CODE (expr) == CALL_EXPR) + maybe_warn_nodiscard (expr, implicit); } break;