From patchwork Tue May 29 08:31:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 921893 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-478631-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="C4+tAPat"; 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 40w7CX3CSbz9s0q for ; Tue, 29 May 2018 19:07:20 +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:date :from:to:cc:subject:message-id:reply-to:mime-version :content-type; q=dns; s=default; b=Ed+0EeMhPnFTCwFftpXNsYJtq0lhw tdjittPn5IuyYMR7JSC0fUbC4xeFg3PKsf0vbJE0fDwhrgme/3ww+jQ2vuaPRMBw 9vCzpzqVz39eEELU+twSksio7OlMr+AqIYRxhyp+EF/1dPCiBrtSP6k52fvH8ODL D0FL6dY7mYO5Kw= 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:date :from:to:cc:subject:message-id:reply-to:mime-version :content-type; s=default; bh=7RGL4dj9PxQAgElpt28YquZ8JNE=; b=C4+ tAPatQzNQvd0sojU8rA/wSvpY+2aKol7G8vGAD2tnTH/eLP7VW3YRzjGlg6tCyb/ wnUAk3PwTNC4foZ//fifxBh9Yt5Q0GXz55BdKSz7EktekvOICtzh8tU/AYTfDa63 EB5YlHJyruqm2X7cO7kcXnYZzYsOtfjZB3qQiq14= Received: (qmail 59213 invoked by alias); 29 May 2018 08:59:33 -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 14456 invoked by uid 89); 29 May 2018 08:31:27 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=0.0 required=5.0 tests=none autolearn=unavailable version=3.3.2 spammy= X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 29 May 2018 08:31:17 +0000 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B922D30832EB for ; Tue, 29 May 2018 08:31:16 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-117-37.ams2.redhat.com [10.36.117.37]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4290C5D70C; Tue, 29 May 2018 08:31:16 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.15.2/8.15.2) with ESMTP id w4T8VERv006693; Tue, 29 May 2018 10:31:14 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id w4T8VDx5006692; Tue, 29 May 2018 10:31:13 +0200 Date: Tue, 29 May 2018 10:31:13 +0200 From: Jakub Jelinek To: Jason Merrill Cc: gcc-patches@gcc.gnu.org Subject: [C++ PATCH] Avoid bogus -Wunused-but-set* with structured binding (PR c++/85952) Message-ID: <20180529083113.GZ14160@tucnak> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.9.2 (2017-12-15) X-IsSubscribed: yes Hi! Initializing the decomposition temporary from an expression with array type is a special aggregate initialization path in which we wouldn't mark the expression as read for the purposes of -Wunused-but-set*. Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2018-05-29 Jakub Jelinek PR c++/85952 * init.c (build_aggr_init): For structured binding initialized from array call mark_rvalue_use on the initializer. * g++.dg/warn/Wunused-var-33.C: New test. Jakub --- gcc/cp/init.c.jj 2018-05-25 14:34:41.000000000 +0200 +++ gcc/cp/init.c 2018-05-28 19:04:10.504063972 +0200 @@ -1678,6 +1678,7 @@ build_aggr_init (tree exp, tree init, in if (VAR_P (exp) && DECL_DECOMPOSITION_P (exp)) { from_array = 1; + init = mark_rvalue_use (init); if (init && DECL_P (init) && !(flags & LOOKUP_ONLYCONVERTING)) { --- gcc/testsuite/g++.dg/warn/Wunused-var-33.C.jj 2018-05-28 19:32:00.236440573 +0200 +++ gcc/testsuite/g++.dg/warn/Wunused-var-33.C 2018-05-28 19:31:11.816372827 +0200 @@ -0,0 +1,29 @@ +// PR c++/85952 +// { dg-do compile { target c++11 } } +// { dg-options "-Wunused-but-set-variable" } + +int +foo () +{ + int a[2] = {1, 2}; // { dg-bogus "set but not used" } */ + auto [x, y] = a; // { dg-warning "structured bindings only available with" "" { target c++14_down } } + return x + y; +} + +struct S { int d, e; }; + +int +bar () +{ + S a = {1, 2}; + auto [x, y] = a; // { dg-warning "structured bindings only available with" "" { target c++14_down } } + return x + y; +} + +int +baz () +{ + S a = {1, 2}; + auto & [x, y] = a; // { dg-warning "structured bindings only available with" "" { target c++14_down } } + return x + y; +}