From patchwork Mon Nov 17 22:08:43 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 411828 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 3D92F14003E for ; Tue, 18 Nov 2014 09:08:58 +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 :message-id:date:from:mime-version:to:subject:content-type; q= dns; s=default; b=mGJZg/TUFB+Y7hNG+ul8g0JgRnNnNbHywx9ybkvdPNBwu9 zfY4Ym0O/nJf4RBtEZgFlO7QikpGAxEb/EdjuSGlAflRrytUoiu+SY7FVESOn2R2 JMBL+1qLYVZQiQz2UN9Gf40RCW9EvZCGP6+W2dOvzckLhS5H3a63Ffrte8NtU= 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 :message-id:date:from:mime-version:to:subject:content-type; s= default; bh=8A4fihOA2eMNBHaRf3WJwQcAUBI=; b=BBwhXzHRQGamyaNvhAhN 0lyAooSe+PWhWwo12qXjOdr2yKDJSUSYhTvtDJRnXOY3+XgL1s0bstE+umMSj4tO fLfRgt1RIXkmD/vfDcBuLYdEi6ZDEnTP7Lqa+aXkWhrIIUFGDFp/5z5bigs3hAJf mYLBr6QYbkFDFUQtTH+LfW4= Received: (qmail 25415 invoked by alias); 17 Nov 2014 22:08:51 -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 25403 invoked by uid 89); 17 Nov 2014 22:08:50 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.7 required=5.0 tests=AWL, BAYES_00, SPF_HELO_PASS, SPF_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Mon, 17 Nov 2014 22:08:49 +0000 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id sAHM8lAo002674 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Mon, 17 Nov 2014 17:08:47 -0500 Received: from [10.10.116.43] ([10.10.116.43]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id sAHM8kDE001677; Mon, 17 Nov 2014 17:08:47 -0500 Message-ID: <546A71EB.10105@redhat.com> Date: Mon, 17 Nov 2014 17:08:43 -0500 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.2.0 MIME-Version: 1.0 To: gcc-patches List , Jonathan Wakely Subject: C++ PATCH for c++/33911 (-Wdeprecated and templates) We weren't warning properly about deprecated class templates because we were treating the deprecated attribute as a late template attribute, to be applied at instantiation time. But it applies to the template itself, and we should warn about uses of the template as a template template argument as well as about uses of specializations. To avoid regressions in the libstdc++ testsuite I've suppressed -Wdeprecated-declarations within two files that define deprecated interfaces. Tested x86_64-pc-linux-gnu, applying to trunk. commit eda97df89ef9538ae00ffefd76cc0a49aa0e2502 Author: Jason Merrill Date: Tue Nov 11 10:58:54 2014 -0500 PR c++/33911 gcc/cp/ * call.c (build_call_a): Don't warn_deprecated_use here. (build_over_call): Or here. * decl2.c (mark_used): Do it here. (is_late_template_attribute): Attribute deprecated is not deferred. (cplus_decl_attributes): Propagate TREE_DEPRECATED out to the template. * parser.c (cp_parser_template_name): Warn about deprecated template. (cp_parser_template_argument): Likewise. libstdc++-v3/ * include/backward/binders.h: Suppress -Wdeprecated-declarations. * include/ext/array_allocator.h: Likewise. diff --git a/gcc/cp/call.c b/gcc/cp/call.c index 06162aa..c180890 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -387,8 +387,6 @@ build_call_a (tree function, int n, tree *argarray) mark_used (decl); } - if (decl && TREE_DEPRECATED (decl)) - warn_deprecated_use (decl, NULL_TREE); require_complete_eh_spec_types (fntype, decl); TREE_HAS_CONSTRUCTOR (function) = (decl && DECL_CONSTRUCTOR_P (decl)); @@ -7447,11 +7445,6 @@ build_over_call (struct z_candidate *cand, int flags, tsubst_flags_t complain) ba_any, NULL, complain); gcc_assert (binfo && binfo != error_mark_node); - /* Warn about deprecated virtual functions now, since we're about - to throw away the decl. */ - if (TREE_DEPRECATED (fn)) - warn_deprecated_use (fn, NULL_TREE); - argarray[0] = build_base_path (PLUS_EXPR, argarray[0], binfo, 1, complain); if (TREE_SIDE_EFFECTS (argarray[0])) diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c index fb8d0c8..f3b94a9 100644 --- a/gcc/cp/decl2.c +++ b/gcc/cp/decl2.c @@ -1204,9 +1204,9 @@ is_late_template_attribute (tree attr, tree decl) /* Also defer most attributes on dependent types. This is not necessary in all cases, but is the better default. */ else if (dependent_type_p (type) - /* But attributes abi_tag and visibility specifically apply - to templates. */ + /* But some attributes specifically apply to templates. */ && !is_attribute_p ("abi_tag", name) + && !is_attribute_p ("deprecated", name) && !is_attribute_p ("visibility", name)) return true; else @@ -1482,6 +1482,17 @@ cplus_decl_attributes (tree *decl, tree attributes, int flags) if (TREE_CODE (*decl) == TYPE_DECL) SET_IDENTIFIER_TYPE_VALUE (DECL_NAME (*decl), TREE_TYPE (*decl)); + + /* Propagate deprecation out to the template. */ + if (TREE_DEPRECATED (*decl)) + if (tree ti = get_template_info (*decl)) + { + tree tmpl = TI_TEMPLATE (ti); + tree pattern = (TYPE_P (*decl) ? TREE_TYPE (tmpl) + : DECL_TEMPLATE_RESULT (tmpl)); + if (*decl == pattern) + TREE_DEPRECATED (tmpl) = true; + } } /* Walks through the namespace- or function-scope anonymous union @@ -4891,6 +4902,10 @@ mark_used (tree decl, tsubst_flags_t complain) return false; } + if (TREE_DEPRECATED (decl) && (complain & tf_warning) + && deprecated_state != DEPRECATED_SUPPRESS) + warn_deprecated_use (decl, NULL_TREE); + /* We can only check DECL_ODR_USED on variables or functions with DECL_LANG_SPECIFIC set, and these are also the only decls that we might need special handling for. */ diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 3eff5fa..b106f3b 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -13959,7 +13959,11 @@ cp_parser_template_name (cp_parser* parser, /* If DECL is a template, then the name was a template-name. */ if (TREE_CODE (decl) == TEMPLATE_DECL) - ; + { + if (TREE_DEPRECATED (decl) + && deprecated_state != DEPRECATED_SUPPRESS) + warn_deprecated_use (decl, NULL_TREE); + } else { tree fn = NULL_TREE; @@ -14193,7 +14197,11 @@ cp_parser_template_argument (cp_parser* parser) cp_parser_error (parser, "expected template-name"); } if (cp_parser_parse_definitely (parser)) - return argument; + { + if (TREE_DEPRECATED (argument)) + warn_deprecated_use (argument, NULL_TREE); + return argument; + } /* It must be a non-type argument. There permitted cases are given in [temp.arg.nontype]: diff --git a/gcc/testsuite/g++.dg/ext/attr-deprecated-1.C b/gcc/testsuite/g++.dg/ext/attr-deprecated-1.C new file mode 100644 index 0000000..31a7690 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/attr-deprecated-1.C @@ -0,0 +1,15 @@ +// PR c++/33911 + +template struct __attribute__ ((deprecated)) S {}; +S s; // { dg-warning "deprecated" } + +template