From patchwork Mon Feb 12 23:32:54 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Sebor X-Patchwork-Id: 872521 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-473120-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="LE9pTlp3"; 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 3zgMRW72kKz9s7f for ; Tue, 13 Feb 2018 10:33:09 +1100 (AEDT) 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=CaAlvu3bPcMSLRHfpP3FMOntYm0UPE8rycCkOh4nMLd5XKhAcr LpEBcXRLY23L9We9WJiJdgbDlLueKm+1YNzArzeDnvmtXmwjnGV8zxBdXw/4PPU2 FO7xRbtB2lbKplt0aP/2mWa0WcC/iMcrRO8sagTrqyDs1J9DkkRfvwUaA= 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=pOMcZqqp8kih5WqBdPkd3Rfe33g=; b=LE9pTlp3IK8vUl8z7Vgd 9OaAN1NjQc4VpORaZ1PjKp/2hZoSuhVr/DbqpxnZVU7EYwXRv4JeWyzlTJhyUEcn m0vSXhXdeeM28ufJQjBiI04YjNT4384z987ifXNqGklt0tNPq3T8C8g3vzSP6tZR v4O35B0hQxYdkhBiBld3IdE= Received: (qmail 50566 invoked by alias); 12 Feb 2018 23:33:03 -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 49012 invoked by uid 89); 12 Feb 2018 23:33:02 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.4 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=1, 63 X-HELO: mail-ot0-f175.google.com Received: from mail-ot0-f175.google.com (HELO mail-ot0-f175.google.com) (74.125.82.175) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 12 Feb 2018 23:33:00 +0000 Received: by mail-ot0-f175.google.com with SMTP id a2so15634999otf.2 for ; Mon, 12 Feb 2018 15:33:00 -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=mLkFTFvoyTLhEF1Ln0/aW7hoqfpf2V1BWHj7klbTZGs=; b=U0UqmFKIAqY9iL+JR5Ce5VFWPf72gnx3SuPfKg7lrEpvZh1l8JLYBaTZy/CmEcM7nl g1kPT+dmrhiOZ4CgdQImwLvX6giMz0ruLwstOOQ95XQm1gvbaJlzPWP+aZsm5YaROnNG gnGd6ukTmZli1ZaQ1xfWWLjTwxwRoqSt7KbfVPDseYqu/NcSKN6hHNF+NZ0aUMtXAvwS IbrxoJzZlBBG8l/Macbhx4L2cvVb8wjYl8uAVjMZMLT4H9sKLFK1YoD2XvhTQLTRbQWN iWS7ltL/RUlMUoEhx+qDwDR8BDWVN0TxGSpTiVo7wexq3hiLuyoGPhdYAxFa2drYdI+V wJcg== X-Gm-Message-State: APf1xPBSdwjaUc2zyGfL22Vts4ba96GiYb5QOXDIjZrIyVV57icEpWgO xVC8NyQZG7nFbHc8/1wwebvZdQ== X-Google-Smtp-Source: AH8x224oysH0dZ9zNGjPPWEw/wPZe0Xb1yg8wA8DgRhZPIT0NbGSUenSIGpp6OWulAfQWXoq25UujQ== X-Received: by 10.157.52.98 with SMTP id v89mr9531136otb.169.1518478378230; Mon, 12 Feb 2018 15:32:58 -0800 (PST) Received: from localhost.localdomain (75-171-228-29.hlrn.qwest.net. [75.171.228.29]) by smtp.gmail.com with ESMTPSA id h186sm1168925oif.30.2018.02.12.15.32.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 12 Feb 2018 15:32:56 -0800 (PST) To: Jason Merrill , Gcc Patch List From: Martin Sebor Subject: [PATCH] diagnose specializations of deprecated templates (PR c++/84318) Message-ID: Date: Mon, 12 Feb 2018 16:32:54 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 MIME-Version: 1.0 X-IsSubscribed: yes While testing my fix for 83871 (handling attributes on explicit specializations) I noticed another old regression: while GCC 4.4 would diagnose declarations of explicit soecializations of all primary templates declared deprecated, GCC 4.5 and later only diagnose declarations of explicit soecializations of class templates but not those of function or variable templates. The root cause of this regression is different than 83871 so I prefer to fix each separately. The attached patch does that. Because there is an opportunity to share code between the two fixes I expect to integrate one into the other (whichever is approved/committed last). Martin PR c++/84318 - attribute deprecated on function templates different than class templates gcc/cp/ChangeLog: PR c++/84318 * pt.c (check_explicit_specialization): Warn for explicit specializations of deprecated primary templates. gcc/testsuite/ChangeLog: PR c++/84318 * g++.dg/ext/attr-deprecated-2.C: New test. diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index b58c60f..aa5f0dd 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -3104,6 +3104,20 @@ check_explicit_specialization (tree declarator, else if (VAR_P (decl)) DECL_COMDAT (decl) = false; + if (TREE_CODE (gen_tmpl) != TYPE_DECL) + { + tree tmpl = gen_tmpl; + if (DECL_FUNCTION_TEMPLATE_P (tmpl) + || TREE_CODE (tmpl) == TEMPLATE_DECL) + tmpl = DECL_TEMPLATE_RESULT (tmpl); + + /* Diagnose declarations of specializations of + a deprecated primary template. */ + if (TREE_DEPRECATED (tmpl) + || lookup_attribute ("deprecated", DECL_ATTRIBUTES (tmpl))) + warn_deprecated_use (tmpl, NULL_TREE); + } + /* If this is a full specialization, register it so that we can find it again. Partial specializations will be registered in process_partial_specialization. */ diff --git a/gcc/testsuite/g++.dg/ext/attr-deprecated-2.C b/gcc/testsuite/g++.dg/ext/attr-deprecated-2.C new file mode 100644 index 0000000..f639a73 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/attr-deprecated-2.C @@ -0,0 +1,63 @@ +// PR c++/84318 - attribute deprecated on function templates different +// than class templates +// { dg-do compile } +// { dg-options "-Wall" } + +#define DEPRECATED __attribute__ ((deprecated)) + +template +struct DEPRECATED +ClassPartial { }; // { dg-message "declared here" } + +// Verify that a partial specialization is diagnosed. +template +struct ClassPartial { }; // { dg-warning ".template * struct ClassPartial. is deprecated" } + + +template +struct +ClassPartialDeprecated { }; + +template +struct DEPRECATED +ClassPartialDeprecated { }; + +ClassPartialDeprecated cpdi; +ClassPartialDeprecated cpdci; // { dg-warning "is deprecated" "bug 84347" { xfail *-*-* } } + + +template +struct DEPRECATED +ClassExplicit { }; // { dg-message "declared here" } + +template <> +struct +ClassExplicit { }; // { dg-warning ".template * struct ClassExplicit. is deprecated" } + + +template +void DEPRECATED +FuncExplicit (); // { dg-message "declared here" } + +template <> +void +FuncExplicit(); // { dg-warning ".void FuncExplicit\\\(\\\). is deprecated" } + + +template +int DEPRECATED +VarPartial; // { dg-message "declared here" } + +template +int +VarPartial; // { dg-warning ".VarPartial. is deprecated" } + +template +int DEPRECATED +VarExplicit; // { dg-message "declared here" } + +template <> +int +VarExplicit; // { dg-warning ".VarExplicit. is deprecated" } + +// { dg-prune-output "variable templates only available" }