From patchwork Wed Apr 6 15:33:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 1614017 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=v7KNMlQ4; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KYT7z4LD0z9sBJ for ; Thu, 7 Apr 2022 01:34:07 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 88E583839825 for ; Wed, 6 Apr 2022 15:34:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 88E583839825 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1649259245; bh=Nc3PTPWHtPMdUic8ipuCvSqOQHHqb5JxmOcYbszmMH8=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=v7KNMlQ4p7EWeTWEXeUxHnMrfHoeEBizpRP28M/gWOBnRjBZwj+WtAy02z/FfSFQ5 zTksJdPWy0M62DS141PS5z5PaFkDnzlH7fLlpQh/S/Q/7Hofe/gMOCQYcuQjnKK9pv ZHozGrheHq9zmBIkuSTV1t7rGHfn4KCANv4iaLOw= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org 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 2046A3857434 for ; Wed, 6 Apr 2022 15:33:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 2046A3857434 Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-515-vqd0CN-SO0eGejKXyMJhUw-1; Wed, 06 Apr 2022 11:33:43 -0400 X-MC-Unique: vqd0CN-SO0eGejKXyMJhUw-1 Received: by mail-qt1-f198.google.com with SMTP id z18-20020ac84552000000b002e201c79cd4so3245996qtn.2 for ; Wed, 06 Apr 2022 08:33:43 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=Nc3PTPWHtPMdUic8ipuCvSqOQHHqb5JxmOcYbszmMH8=; b=rQWtVRBD6/ZCakztilOlzsl0VrcKsiuZiRJt7pAan2d8ros+RUrjg8KkHHkpG5HQbl b0t7mGu556WVkfl+HK9IDTAeE6MhPz8OwVGcrcrjYNdXzlWV7OYOK8jnGuMu949Qrxeo X2YwqicnNUENUDtFPd4xUy/WcWK07KCGYkKt4azI67GYc3OCLuO99CqsQo//Cngrv+JB u1ixVQh/qdTltXnEAmsKV9pfMIHEBT4I0DRsfhSopsP4Kddyw15uWt1Luh5tFGmY+txO sF5OKKRKyrM1P6fmMSwcylbj4W4vYhz2kbCJPbsn52uYC65jjOv1jJ04etVb3U2gbezN zj9Q== X-Gm-Message-State: AOAM531CHG6vv9LK6kuJ5mpyY54Bw3bGLIl8kOjjy6bBaBeDu9tOp4r3 tWJt4HGIUfyXCnsVlyRGHp/UX5WY+CUtxeMCAspTmIkU43oBhQMsrBJ1LKJLym114oFj7Ro7j0l jg4B7LJ5/r2ak7vCDg6zz75ioo6zvo+Z/WqOLK6+hVWLPDZVsaeMc02n0puFqto6giQ== X-Received: by 2002:a05:6214:529b:b0:443:81ef:98c0 with SMTP id kj27-20020a056214529b00b0044381ef98c0mr7564173qvb.117.1649259222399; Wed, 06 Apr 2022 08:33:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwLuq2eFdycCKT/VOGNSflu3TgxgE04zAx4Zd4v1ITBwdwIinMeu+diHG6GPxPtz2jLIPzzIw== X-Received: by 2002:a05:6214:529b:b0:443:81ef:98c0 with SMTP id kj27-20020a056214529b00b0044381ef98c0mr7564142qvb.117.1649259222019; Wed, 06 Apr 2022 08:33:42 -0700 (PDT) Received: from barrymore.redhat.com (130-44-159-43.s15913.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.159.43]) by smtp.gmail.com with ESMTPSA id j18-20020ac85c52000000b002e1b9897ae7sm13390215qtj.10.2022.04.06.08.33.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Apr 2022 08:33:41 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [pushed] c++: -Wunused-value and array init [PR104702] Date: Wed, 6 Apr 2022 11:33:39 -0400 Message-Id: <20220406153339.2364834-1-jason@redhat.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-13.0 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_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jason Merrill via Gcc-patches From: Jason Merrill Reply-To: Jason Merrill Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Here, because of problems with the new warning-control code and expressions that change location, the suppress_warning on the INDIRECT_REF didn't work. Those problems still need to be worked out, but it's simple to avoid needing to use suppress_warning in the first place by using a reference instead. Tested x86_64-pc-linux-gnu, applying to trunk. PR c++/104702 gcc/cp/ChangeLog: * init.cc (build_vec_init): Use a reference for the result. gcc/testsuite/ChangeLog: * g++.dg/warn/Wunused-19.C: New test. --- gcc/cp/init.cc | 5 ++--- gcc/testsuite/g++.dg/warn/Wunused-19.C | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/g++.dg/warn/Wunused-19.C base-commit: eac5c12c1838d51bf05bd6f30f3f5d7bb760e398 diff --git a/gcc/cp/init.cc b/gcc/cp/init.cc index 01e762320f3..c20ed211f1d 100644 --- a/gcc/cp/init.cc +++ b/gcc/cp/init.cc @@ -4908,10 +4908,9 @@ build_vec_init (tree base, tree maxindex, tree init, /* Now make the result have the correct type. */ if (TREE_CODE (atype) == ARRAY_TYPE) { - atype = build_pointer_type (atype); + atype = build_reference_type (atype); stmt_expr = build1 (NOP_EXPR, atype, stmt_expr); - stmt_expr = cp_build_fold_indirect_ref (stmt_expr); - suppress_warning (stmt_expr /* What warning? */); + stmt_expr = convert_from_reference (stmt_expr); } return stmt_expr; diff --git a/gcc/testsuite/g++.dg/warn/Wunused-19.C b/gcc/testsuite/g++.dg/warn/Wunused-19.C new file mode 100644 index 00000000000..2fc70b04c18 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wunused-19.C @@ -0,0 +1,16 @@ +// PR c++/104702 +// { dg-additional-options "-fno-exceptions -Wunused-value" } + +struct FlyString { + FlyString(char const*); + ~FlyString(); +}; + +struct Array { FlyString __data[1]; }; + +void frobnicate(Array&); + +int main() { + Array s_reserved_words = { "" }; // { dg-bogus "value computed is not used" } + frobnicate(s_reserved_words); +}