From patchwork Sat Feb 18 01:07:52 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Sebor X-Patchwork-Id: 729395 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 3vQBbZ2qMDz9s8D for ; Sat, 18 Feb 2017 12:08:12 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="XXuUvgAv"; 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 :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=PcdtuDtq+prDgAz4SsT9vruzwh/3HGwXkZSof2a2p+49nTReI6 OnvEyJbv2bG/LyZoWcMRlDPnluQ6FAY/pRgEThhHwD4EZfnXXMsvAgehIrmT4gPL LFLficKwbnVy4Byy5MIqNJRiGF/jIVzpgknQM26W0Ec6PYI7xz62VPY2I= 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 :from:subject:message-id:date:mime-version:content-type; s= default; bh=l64o2u6yek+VAE8H+74b5xkOG3M=; b=XXuUvgAvMAHqLM6bExSm mGlwKkCzMuif8XqzW/MqKPwb+Af/SiJ+9HzINWy6ztf8OUUprFDs9odQe6FLAngn 7MzsbRDugHrcWDaLxmv4o1BT9884JXvJSGMafuQUYj2vV23ySDBtvE0/TJaJ/cH5 hoYouYk69RsvQPrtEiBnNUE= Received: (qmail 78879 invoked by alias); 18 Feb 2017 01:07:58 -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 78868 invoked by uid 89); 18 Feb 2017 01:07:57 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.6 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_LOW, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mail-qt0-f182.google.com Received: from mail-qt0-f182.google.com (HELO mail-qt0-f182.google.com) (209.85.216.182) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 18 Feb 2017 01:07:56 +0000 Received: by mail-qt0-f182.google.com with SMTP id b16so4556490qte.0 for ; Fri, 17 Feb 2017 17:07:56 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:from:subject:message-id:date:user-agent :mime-version; bh=7owflDM2XzosSJc7tQJeAPuT43T/qv5DdtSpYMAPlvs=; b=W0umBihbT6PUm4zWzV76Lux9ZYdsM8v1mxippL5DrfMEfb6vyPT/ARWAcBuxWOW8v3 8L6T5dw0XObC9cKTaBI/6QUMg36wIsmGVDpja0qWg6jKsjGkjw0Zbg9Wpqe4sDHeRA3J Zm8dycfh8+3gLN/kRJyHx9gAvHbYBGeZ+4S0gtC7B0sNaKdrvjyANYgJEiiIRuivensm 9WMGwCpmcpe64ohwDZN7Wzw3rIJ0xyoHI8omknusJuHqiR3zB7ceu5bHcrSm6Xf4qEqy PyXsZywsBGkbRErVxooCU5j+2VbCgzsFVeFeKvo6LPuYeu3ojlAAnh6fZlu5vlL3YAH8 YjzQ== X-Gm-Message-State: AMke39lpZDleoeUUxDgn6OACq62/ipizG02WV/VOOnIAzixx4j2S3w4A1svdW1i4bj4g6g== X-Received: by 10.237.50.229 with SMTP id z92mr9884298qtd.182.1487380074479; Fri, 17 Feb 2017 17:07:54 -0800 (PST) Received: from [192.168.0.3] (97-118-113-37.hlrn.qwest.net. [97.118.113.37]) by smtp.gmail.com with ESMTPSA id i1sm7593418qte.32.2017.02.17.17.07.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 17 Feb 2017 17:07:53 -0800 (PST) To: Gcc Patch List , Jason Merrill From: Martin Sebor Subject: [PATCH] restore -Wunused-variable on a typedef'd variable in a function template (PR 79548) Message-ID: <28dd4f25-b208-52af-af1e-7bc5e36db557@gmail.com> Date: Fri, 17 Feb 2017 18:07:52 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.6.0 MIME-Version: 1.0 X-IsSubscribed: yes The attached patch fixes bug 79548 - [5/6/7 Regression] missing -Wunused-variable on a typedef'd variable in a function template, most likely broken by the introduction of -Wunused-local-typedefs. While testing the patch I came across a couple of other bugs: 79585 - spurious -Wunused-variable on a pointer with attribute unused in function template and 79586 - missing -Wdeprecated depending on position of attribute The test I added for 79548 fails two assertions due to the first of these two so I xfailed them. The second doesn't have an impact on it. Neither of these is a regression so I didn't try to fix them. Martin PR c++/79548 - [5/6/7 Regression] missing -Wunused-variable on a typedef'd variable in a function template gcc/cp/ChangeLog: PR c++/79548 * decl.c (poplevel): Avoid diagnosing entities declared with attribute unused. (initialize_local_var): Do not consider the type of a variable when determining whether or not it's used. gcc/testsuite/ChangeLog: PR c++/79548 * g++.dg/warn/Wunused-var-26.C: New test. diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 70c44fb..e315ad0 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -664,7 +664,8 @@ poplevel (int keep, int reverse, int functionbody) && (!CLASS_TYPE_P (type) || !TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type) || lookup_attribute ("warn_unused", - TYPE_ATTRIBUTES (TREE_TYPE (decl))))) + TYPE_ATTRIBUTES (TREE_TYPE (decl)))) + && !lookup_attribute ("unused", TYPE_ATTRIBUTES (TREE_TYPE (decl)))) { if (! TREE_USED (decl)) warning_at (DECL_SOURCE_LOCATION (decl), @@ -6546,7 +6547,6 @@ initialize_local_var (tree decl, tree init) { tree type = TREE_TYPE (decl); tree cleanup; - int already_used; gcc_assert (VAR_P (decl) || TREE_CODE (decl) == RESULT_DECL); @@ -6564,7 +6564,7 @@ initialize_local_var (tree decl, tree init) return; /* Compute and store the initial value. */ - already_used = TREE_USED (decl) || TREE_USED (type); + bool already_used = TREE_USED (decl); if (TREE_USED (type)) DECL_READ_P (decl) = 1; diff --git a/gcc/testsuite/g++.dg/warn/Wunused-var-26.C b/gcc/testsuite/g++.dg/warn/Wunused-var-26.C new file mode 100644 index 0000000..562f25b --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wunused-var-26.C @@ -0,0 +1,127 @@ +// PR c++/79548 - missing -Wunused-variable on a typedef'd variable +// in a function template +// { dg-do compile } +// { dg-options "-Wunused" } + + +#define UNUSED __attribute__ ((unused)) + +template +void f_int () +{ + T t; // { dg-warning "unused variable" } + + typedef T U; + U u; // { dg-warning "unused variable" } +} + +template void f_int(); + + +template +void f_intptr () +{ + T *t = 0; // { dg-warning "unused variable" } + + typedef T U; + U *u = 0; // { dg-warning "unused variable" } +} + +template void f_intptr(); + + +template +void f_var_unused () +{ + // The variable is marked unused. + T t UNUSED; + + typedef T U; + U u UNUSED; +} + +template void f_var_unused(); + + +template +void f_var_type_unused () +{ + // The variable's type is marked unused. + T* UNUSED t = new T; // { dg-bogus "unused variable" "bug 79585" { xfail *-*-* } } + + typedef T U; + U* UNUSED u = new U; // { dg-bogus "unused variable" "bug 79585" { xfail *-*-* } } + + typedef T UNUSED U; + U v = U (); // { dg-bogus "unused variable" "bug 79585" { xfail *-*-* } } +} + +template void f_var_type_unused(); + + +struct A { int i; }; + +template +void f_A () +{ + T t; // { dg-warning "unused variable" } + + typedef T U; + U u; // { dg-warning "unused variable" } +} + +template void f_A(); + + +template +void f_A_unused () +{ + T t UNUSED; + + typedef T U; + U u UNUSED; +} + +template void f_A_unused(); + + +struct B { B (); }; + +template +void f_B () +{ + T t; + + typedef T U; + U u; +} + +template void f_B(); + + +struct C { ~C (); }; + +template +void f_C () +{ + T t; + + typedef T U; + U u; +} + +template void f_C(); + + +struct D { B b; }; + +template +void f_D () +{ + T t; + + typedef T U; + U u; +} + +template void f_D();