From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 6F5AE3858D33 for ; Mon, 23 Jan 2023 21:28:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6F5AE3858D33 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1674509337; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=fBPS9mgh0RZXBs3dXFdrS3H8RLiIiCjTY258LGopOgg=; b=Tuqm2gRzzA1ThB676/N8wAjZnXXTu6oOJLceLFLPoRZ8ki2s3/MTb4JZndfirZeLcqy2Ho cGDHYnDzREI5iUJiqEFQlyglYOMdML10O93CEc9OttBC6DEomtuCn9XH/TnSbnZpQQRDan R+NXFseHZg7DGncLnk0qkh6PIn0E6Q4= Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-45-t8XkqErrPs-cp9rvYxwzbw-1; Mon, 23 Jan 2023 16:28:55 -0500 X-MC-Unique: t8XkqErrPs-cp9rvYxwzbw-1 Received: by mail-qv1-f72.google.com with SMTP id c10-20020a05621401ea00b004c72d0e92bcso6546074qvu.12 for ; Mon, 23 Jan 2023 13:28:55 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=user-agent:in-reply-to:content-disposition:mime-version:references :message-id:subject:cc:to:from:date:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=fBPS9mgh0RZXBs3dXFdrS3H8RLiIiCjTY258LGopOgg=; b=fn03000qS3y1V4aK0+7N+LsjbhgiWVPXzYfnuub8gT6wV0d1opTvHT2Have8OqGozT 6pWwQoOPK0i6dQTRHIJwDBAEdizul0WGZRKFQYmjklEJWtWBgkU1e4uRNXI63zTY7EDb 80AhTWPIz4CgspI7CsAB1RlphS0jp3bnVl76DV0lWp8yW2y/lli9jAsaCJvNucHmZ/J5 xUxYxYb53cqMgJUIfl8FeVjAKgMLULnLZrxC8XzxbLk9GaRMvacPD3auYsNK+WsAIsCO PO7VVOEFtuGJdn0AHkM4gv2k6kmQ3l+NZ4Gsna95eOq0LL+iCAKF8C2B6oQXEc36dFJC JZWw== X-Gm-Message-State: AFqh2kruytOGvqtNNN71DvBo01bbbyIuj+357huaMcgQ6b+3bf938J9S Gw7JUmnd73sdd6sxVmNghaDlfrJkj+7iA+pVzPiVj+D+hQe96nOuGja+VlbkANemo7Z5kDKlY/O 6xk3BWf+0/tQYil8GHw== X-Received: by 2002:ac8:7450:0:b0:3b6:320f:7580 with SMTP id h16-20020ac87450000000b003b6320f7580mr42034618qtr.17.1674509334213; Mon, 23 Jan 2023 13:28:54 -0800 (PST) X-Google-Smtp-Source: AMrXdXvBD+7QrvaUfP2KYp8yLs4Mcj/U1bkmzM9VgA8SU9x7TcqQoHN4m+z3u0krSJ8srKOkmsB9lQ== X-Received: by 2002:ac8:7450:0:b0:3b6:320f:7580 with SMTP id h16-20020ac87450000000b003b6320f7580mr42034596qtr.17.1674509333968; Mon, 23 Jan 2023 13:28:53 -0800 (PST) Received: from redhat.com (2603-7000-9500-34a5-0000-0000-0000-1db4.res6.spectrum.com. [2603:7000:9500:34a5::1db4]) by smtp.gmail.com with ESMTPSA id y21-20020a376415000000b006e07228ed53sm237391qkb.18.2023.01.23.13.28.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Jan 2023 13:28:53 -0800 (PST) Date: Mon, 23 Jan 2023 16:28:51 -0500 From: Marek Polacek To: Jason Merrill Cc: GCC Patches Subject: Re: [PATCH] c++: Quash bogus -Wunused-value with new [PR107797] Message-ID: References: <20230120020339.1025075-1-polacek@redhat.com> MIME-Version: 1.0 In-Reply-To: User-Agent: Mutt/2.2.9 (2022-11-12) X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-12.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Fri, Jan 20, 2023 at 02:37:19PM -0500, Jason Merrill wrote: > On 1/19/23 21:03, Marek Polacek wrote: > > We shouldn't emit "right operand of comma operator has no effect" > > when that comma operator was created by the compiler for "new int{}". > > convert_to_void/COMPOUND_EXPR already checks warning_suppressed_p so > > we can just suppress -Wunused-value. > > > > Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk? > > > > PR c++/107797 > > > > gcc/cp/ChangeLog: > > > > * cvt.cc (ocp_convert): copy_warning when creating a new > > COMPOUND_EXPR. > > * init.cc (build_new_1): Suppress -Wunused-value on > > compiler-generated COMPOUND_EXPRs. > > > > gcc/testsuite/ChangeLog: > > > > * g++.dg/warn/Wunused-value-1.C: New test. > > --- > > gcc/cp/cvt.cc | 6 ++++-- > > gcc/cp/init.cc | 2 ++ > > gcc/testsuite/g++.dg/warn/Wunused-value-1.C | 12 ++++++++++++ > > 3 files changed, 18 insertions(+), 2 deletions(-) > > create mode 100644 gcc/testsuite/g++.dg/warn/Wunused-value-1.C > > > > diff --git a/gcc/cp/init.cc b/gcc/cp/init.cc > > index f816c474cef..52e96fbe590 100644 > > --- a/gcc/cp/init.cc > > +++ b/gcc/cp/init.cc > > @@ -3800,6 +3800,8 @@ build_new_1 (vec **placement, tree type, tree nelts, > > if (cookie_expr) > > rval = build2 (COMPOUND_EXPR, TREE_TYPE (rval), cookie_expr, rval); > > + suppress_warning (rval, OPT_Wunused_value); > > This makes sense, but IIUC since rval is built with no location, this just > sets nowarning_flag? Correct (I didn't realize this when writing the patch). There's another suppress_warning on a location-less expr just a few lines above. > > if (rval == data_addr && TREE_CODE (alloc_expr) == TARGET_EXPR) > > /* If we don't have an initializer or a cookie, strip the TARGET_EXPR > > and return the call (which doesn't need to be adjusted). */ > > diff --git a/gcc/cp/cvt.cc b/gcc/cp/cvt.cc > > index 0cbfd8060cb..17827d06a4a 100644 > > --- a/gcc/cp/cvt.cc > > +++ b/gcc/cp/cvt.cc > > @@ -711,8 +711,10 @@ ocp_convert (tree type, tree expr, int convtype, int flags, > > return error_mark_node; > > if (e == TREE_OPERAND (expr, 1)) > > return expr; > > - return build2_loc (EXPR_LOCATION (expr), COMPOUND_EXPR, TREE_TYPE (e), > > - TREE_OPERAND (expr, 0), e); > > + e = build2_loc (EXPR_LOCATION (expr), COMPOUND_EXPR, TREE_TYPE (e), > > + TREE_OPERAND (expr, 0), e); > > + copy_warning (e, expr); > > And so I don't know what effect this would have; copy_warning doesn't seem > to propagate nowarning_flag, which seems like a bug. It actually does propagate nowarning_flag: in copy_warning we have 219 /* The no-warning bit might be set even if the map has not been consulted, or 220 otherwise if there's no entry in the map. */ 221 set_no_warning_bit (to, supp); so 'e' ends up with TREE_NO_WARNING set. I would not think we want to build 'rval' in build_new_1 with a location or use TREE_NO_WARNING directly instead of suppress_warning so I'm leaving the patch as-is, but please let me know if you disagree. Marek