From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 60450 invoked by alias); 28 Feb 2020 20:24:48 -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 60384 invoked by uid 89); 28 Feb 2020 20:24:47 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-7.4 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 spammy=H*f:sk:65013bf, H*MI:sk:65013bf, H*i:sk:65013bf X-HELO: us-smtp-1.mimecast.com Received: from us-smtp-delivery-1.mimecast.com (HELO us-smtp-1.mimecast.com) (205.139.110.120) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 28 Feb 2020 20:24:46 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582921484; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rgxcFhC8KZ2dLiQtCdIvdi/FazIHe/xMoT+94CHOSBM=; b=ZnBkzHmMl5nvRz+piPfNBt+5mbWU/Y5WDpUGcYK7f3ZBYcjBw7Y86tju9zo3l1awH6sU3E wCgf2GcP4Z/WudcvXTpk26CdPt0c2jpsMp7+5wfOqGND5B/f4UNyE+2hVHM4FwWFHRsffs B9VhJbLbfoWvOX89pXf4lIisA98A3BA= Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-10-tOAgTpB_PtWQeNBNoJoaWA-1; Fri, 28 Feb 2020 15:24:41 -0500 Received: by mail-qk1-f197.google.com with SMTP id a10so3887683qkg.11 for ; Fri, 28 Feb 2020 12:24:41 -0800 (PST) Return-Path: Received: from [192.168.1.148] (209-6-216-142.s141.c3-0.smr-cbr1.sbo-smr.ma.cable.rcncustomer.com. [209.6.216.142]) by smtp.gmail.com with ESMTPSA id r198sm5826555qke.98.2020.02.28.12.24.39 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 28 Feb 2020 12:24:39 -0800 (PST) Subject: Re: [PATCH] avoid -Wredundant-tags on a first declaration in use (PR 93824) To: Martin Sebor , gcc-patches References: <010f6d68-a64e-45a4-744e-c040a4ea94d6@redhat.com> <65013bfc-23c3-47fb-a58d-9ab802d1febb@gmail.com> From: Jason Merrill Message-ID: <2698a399-4176-2b5f-a134-52a0d82c2121@redhat.com> Date: Fri, 28 Feb 2020 20:24:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.3.0 MIME-Version: 1.0 In-Reply-To: <65013bfc-23c3-47fb-a58d-9ab802d1febb@gmail.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: quoted-printable X-IsSubscribed: yes X-SW-Source: 2020-02/txt/msg01662.txt.bz2 On 2/28/20 12:45 PM, Martin Sebor wrote: > On 2/28/20 9:58 AM, Jason Merrill wrote: >> On 2/24/20 6:58 PM, Martin Sebor wrote: >>> -Wredundant-tags doesn't consider type declarations that are also >>> the first uses of the type, such as in 'void f (struct S);' and >>> issues false positives for those.=C2=A0 According to the reported that's >>> making it harder to use the warning to clean up LibreOffice. >>> >>> The attached patch extends -Wredundant-tags to avoid these false >>> positives by relying on the same class_decl_loc_t::class2loc mapping >>> as -Wmismatched-tags.=C2=A0 The patch also somewhat improves the detect= ion >>> of both issues in template declarations (though more work is still >>> needed there). >> >>> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 a new entry for it an= d return unless it's a declaration >>> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 involving a template = that may need to be diagnosed by >>> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 -Wredundant-tags.=C2= =A0 */ >>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 *rdl =3D class_decl_loc_t (class_k= ey, false, def_p); >>> -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return; >>> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (TREE_CODE (decl) !=3D TEMPLATE_DECL) >>> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return; >> >> How can the first appearance of a class template be redundant? >=20 > I'm not sure I correctly understand the question.=C2=A0 The comment says > "involving a template" (i.e., not one of the first declaration of > a template).=C2=A0 The test case that corresponds to this test is: >=20 > =C2=A0 template struct S7 { }; > =C2=A0 struct S7 s7v;=C2=A0 // { dg-warning "\\\[-Wredundant-tags"= } >=20 > where DECL is the TEPLATE_DECL of S7. >=20 > As I mentioned, more work is still needed to handle templates right > because some redundant tags are still not diagnosed.=C2=A0 For example: >=20 > =C2=A0 template struct S7 { }; > =C2=A0 template > =C2=A0 using U =3D struct S7;=C2=A0=C2=A0 // missing warning When we get here for an instance of a template, it doesn't make sense to=20 treat it as a new type. If decl is a template and type_decl is an instance of that template, do=20 we want to (before the lookup) change type_decl to the template or the=20 corresponding generic TYPE_DECL, which should already be in the table? Jason