From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 54259 invoked by alias); 22 Feb 2017 23:44:39 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 54144 invoked by uid 89); 22 Feb 2017 23:44:32 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.1 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,RCVD_IN_SORBS_SPAM,SPF_PASS autolearn=ham version=3.3.2 spammy=H*f:sk:066019c, H*f:sk:cXjL_YP, H*f:cU8Lnq5eGqJzo, H*f:sk:0a4c97a X-HELO: mail-qk0-f172.google.com Received: from mail-qk0-f172.google.com (HELO mail-qk0-f172.google.com) (209.85.220.172) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 22 Feb 2017 23:44:30 +0000 Received: by mail-qk0-f172.google.com with SMTP id u188so18121479qkc.2 for ; Wed, 22 Feb 2017 15:44:30 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:cc:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=Zo8xczVkal4W3aMpZW4ENK+XmXBij5dvfBNG6wVG7hI=; b=q5L75Zlio4vdeJnii5VS2KxxnCq2+6sMJcrnfLrdKcES5TsFkfArl4DDYXs0hm6xzB iS+fR6KYJAtJxDzjE84yKEJLfP7U/7V1ZkvF9oF+H+3c6/FK+4EUeXM/bcmB4NCKFw0M TBiXg7U7+PHNNekKKJAgl7sXA/zYxtRem+NgILcnF0+geL1Ud/BdpvHInJ7pzkd829vx 2/1Q/+qQ37n+xiEoPtw6MMqVIPW1fxNi5x4XvIPwPMXdYMoDk+P3Q6fEGm3bLvuE0qnP k6tfRW5bN95xob8fVunTqmh5lwpqvq3yM5evsp2l4FfhdqhhAybaFtUass6k6JfOevDc hebw== X-Gm-Message-State: AMke39lrA2wMhdSZPNuqlkYTDWFugNVbqEr+24ie1+kCn8tBStZF0i+3oPRDzvwbLiRWuw== X-Received: by 10.55.71.210 with SMTP id u201mr11545699qka.90.1487807069049; Wed, 22 Feb 2017 15:44:29 -0800 (PST) Received: from [192.168.0.3] (75-166-126-106.hlrn.qwest.net. [75.166.126.106]) by smtp.gmail.com with ESMTPSA id x64sm1645492qke.60.2017.02.22.15.44.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 22 Feb 2017 15:44:28 -0800 (PST) Subject: Re: [PATCH] restore -Wunused-variable on a typedef'd variable in a function template (PR 79548) To: Jason Merrill References: <28dd4f25-b208-52af-af1e-7bc5e36db557@gmail.com> <2c85e43f-d1dc-a74e-4d5b-c00fca8588d3@redhat.com> <066019c5-c85e-8d26-102e-aeba34988416@gmail.com> <0a4c97ac-fe30-2e3e-6694-9a3f9dbdf90c@gmail.com> Cc: Gcc Patch List From: Martin Sebor Message-ID: <00eb2a46-a8e8-7744-a093-7eaad8c42e36@gmail.com> Date: Wed, 22 Feb 2017 23:52:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.6.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-IsSubscribed: yes X-SW-Source: 2017-02/txt/msg01416.txt.bz2 On 02/22/2017 11:02 AM, Jason Merrill wrote: > On Tue, Feb 21, 2017 at 4:27 PM, Martin Sebor wrote: >>> Ah, I see, your patch changes attribute unused handling for local >>> variables from tracking TREE_USED to lookup_attribute. I'm not >>> opposed to this change, but I'd like to understand why the TREE_USED >>> handling wasn't working. >> >> >> In the test case in the bug: >> >> template >> void g () >> { >> T t; // warning, ok >> >> typedef T U; >> U u; // no warning, bug >> } >> >> template void g(); >> >> both TREE_USED(T) and TREE_USED(t) are zero in initialize_local_var >> so the function doesn't set already_used or TREE_USED(t) and we get >> a warning as expected. >> >> But because TREE_USED(U) is set to 1 in maybe_record_typedef_use >> (to implement -Wunused-local-typedefs), initialize_local_var then >> sets already_used to 1 and later also TREE_USED(u) to 1, suppressing >> the warning. > > Hmm, I would expect maybe_record_typedef_use to set TREE_USED on the > TYPE_DECL, not on the *_TYPE which initialize_local_var checks. That's what it does: void maybe_record_typedef_use (tree t) { if (!is_typedef_decl (t)) return; TREE_USED (t) = true; } Here, t is a TYPE_DECL of the typedef U. It has the effect of TREE_USED (TREE_TYPE (decl)) being set in initialize_local_var. The TREE_USED bit on the type (i.e., on TREE_TYPE(decl) where decl is the u in the test case above) is set when the function template is instantiated, in set_underlying_type called from tsubst_decl. Martin