From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 33433 invoked by alias); 10 Jan 2020 20:28:29 -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 33422 invoked by uid 89); 10 Jan 2020 20:28:29 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-7.9 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 spammy=parserc, UD:parser.c, sk:cp_pars, parser.c X-HELO: us-smtp-delivery-1.mimecast.com Received: from us-smtp-2.mimecast.com (HELO us-smtp-delivery-1.mimecast.com) (205.139.110.61) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 10 Jan 2020 20:28:28 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1578688106; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=GOf1oSy5ps/uxaF50eMt6LxZkupzk13gYoxPpKQuycE=; b=X4e0d2AXW2oa3ZP6ikvCQh417apUiV1XM2qZHjv1X8561Obz90MXEkYrT6RBFks9l5JnF6 EJlRNXTbNOwcF1MuLcCQDcD0jMRj4NUI1FU8my4P9oqoyMJcLIeK/c06TQzAMropRLB8ZH gGfmvYF46JnpZEEP2HXjHKEZJMVr+FM= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-386-pBfnbYH3O0GcvjmNmIkMqg-1; Fri, 10 Jan 2020 15:28:25 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5DC1C800D41 for ; Fri, 10 Jan 2020 20:28:24 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-116-112.ams2.redhat.com [10.36.116.112]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E90D078E8E; Fri, 10 Jan 2020 20:28:23 +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 00AKSL1V029022; Fri, 10 Jan 2020 21:28:22 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id 00AKSKQn029021; Fri, 10 Jan 2020 21:28:20 +0100 Date: Fri, 10 Jan 2020 20:44:00 -0000 From: Jakub Jelinek To: Jason Merrill Cc: gcc-patches@gcc.gnu.org Subject: [C++ PATCH] Fix deprecated attribute handling on templates (PR c++/93228) Message-ID: <20200110202820.GZ10088@tucnak> Reply-To: Jakub Jelinek MIME-Version: 1.0 User-Agent: Mutt/1.11.3 (2019-02-01) X-Mimecast-Spam-Score: 0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Content-Disposition: inline X-IsSubscribed: yes X-SW-Source: 2020-01/txt/msg00636.txt.bz2 Hi! As the following testcase shows, when deprecated attribute is on a template, we'd never print the message if any, because the attribute is not present on the TEMPLATE_DECL with which warn_deprecated_use is called, but on its DECL_TEMPLATE_RESULT or its type. Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2020-01-10 Jakub Jelinek PR c++/93228 * parser.c (cp_parser_template_name): Look up deprecated attribute in DECL_TEMPLATE_RESULT or its type's attributes. * g++.dg/cpp1y/attr-deprecated-3.C: New test. --- gcc/cp/parser.c.jj 2020-01-10 17:52:48.084062620 +0100 +++ gcc/cp/parser.c 2020-01-10 19:15:29.019861630 +0100 @@ -16882,7 +16882,17 @@ cp_parser_template_name (cp_parser* pars { if (TREE_DEPRECATED (decl) && deprecated_state !=3D DEPRECATED_SUPPRESS) - warn_deprecated_use (decl, NULL_TREE); + { + tree d =3D DECL_TEMPLATE_RESULT (decl); + tree attr; + if (TREE_CODE (d) =3D=3D TYPE_DECL) + attr =3D lookup_attribute ("deprecated", + TYPE_ATTRIBUTES (TREE_TYPE (d))); + else + attr =3D lookup_attribute ("deprecated", + DECL_ATTRIBUTES (d)); + warn_deprecated_use (decl, attr); + } } else { --- gcc/testsuite/g++.dg/cpp1y/attr-deprecated-3.C.jj 2020-01-10 19:20:44.1= 65196267 +0100 +++ gcc/testsuite/g++.dg/cpp1y/attr-deprecated-3.C 2020-01-10 19:20:48.6991= 29148 +0100 @@ -0,0 +1,13 @@ +// PR c++/93228 +// { dg-do compile { target c++14 } } + +template +struct [[deprecated("foo")]] bar {}; // { dg-message "declared here" } +struct [[deprecated("baz")]] qux {}; // { dg-message "declared here" } + +void +quux () +{ + bar b; // { dg-warning "is deprecated: foo" } + qux c; // { dg-warning "is deprecated: baz" } +} Jakub