From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 47956 invoked by alias); 13 Feb 2018 19:59:46 -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 47930 invoked by uid 89); 13 Feb 2018 19:59:45 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.3 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mail-io0-f196.google.com Received: from mail-io0-f196.google.com (HELO mail-io0-f196.google.com) (209.85.223.196) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 13 Feb 2018 19:59:43 +0000 Received: by mail-io0-f196.google.com with SMTP id e7so8366514ioj.1 for ; Tue, 13 Feb 2018 11:59:43 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:cc:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=OVdX/84AFK1H705EWMnvpUMnA2/bsNIqEjK1pcFOMxg=; b=frHXWKUO6F4mVjREHFJoBAmE9l22CfC0NirWmYOVDzJcWm8TK3DCigHHUpAIRxC+cw 3qstk6WdKO9R1vIR8rS3U+FIhsFjLfex3WnmZ7PNKV4/HT3ysnmG+TvNxd8S3MOR6BJw C0t63LJk+FCCgnuqmFnMXhLZCpdMxRJF52b+rnKQb8AWlkhDIDcBh8pW0a8KK3kF8AZK BnQdKaZSHjIRCESAi19N2FPB/AHmNBLrEPtrvmZWP6LwKdyHNPxnujJsE3dAMbbcseNT 0+oJFfp5hh63sFJoJg8tBgez9LTNjF2mIaODEBdePSicEH3JOYWk90hpFvmGFgfz4Am3 cF5w== X-Gm-Message-State: APf1xPByJlG5OfhlA92SFAe8UJNmiC1XQabL6RJZA7KmeC/Mgon7hSq3 M50PjN5mhkoEfAUCj+zZc0Lkrg== X-Google-Smtp-Source: AH8x224wYSULCxM8EQyakLpfLzVPPrQs4I8O/E0r0IfZsOKUfj9VZ1vbEBJ3iiC9mU4TCduzbbJNjw== X-Received: by 10.107.160.21 with SMTP id j21mr2839019ioe.186.1518551981348; Tue, 13 Feb 2018 11:59:41 -0800 (PST) Received: from localhost.localdomain (75-171-228-29.hlrn.qwest.net. [75.171.228.29]) by smtp.gmail.com with ESMTPSA id s22sm3907249ite.3.2018.02.13.11.59.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 13 Feb 2018 11:59:40 -0800 (PST) Subject: Re: [PATCH] diagnose specializations of deprecated templates (PR c++/84318) To: Jason Merrill References: <16dde3b6-2848-33b2-7f61-85e0a768ec6e@gmail.com> <8768aadb-7696-0e3f-8725-0f1bbbac3af7@gmail.com> Cc: Gcc Patch List From: Martin Sebor Message-ID: <102d023e-6678-0888-93cd-a958b4dae911@gmail.com> Date: Tue, 13 Feb 2018 19:59:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-IsSubscribed: yes X-SW-Source: 2018-02/txt/msg00772.txt.bz2 On 02/13/2018 12:15 PM, Jason Merrill wrote: > On Tue, Feb 13, 2018 at 1:31 PM, Martin Sebor wrote: >> On 02/13/2018 09:24 AM, Martin Sebor wrote: >>> >>> On 02/13/2018 08:35 AM, Martin Sebor wrote: >>>> >>>> On 02/13/2018 07:40 AM, Jason Merrill wrote: >>>>> >>>>> On Mon, Feb 12, 2018 at 6:32 PM, Martin Sebor wrote: >>>>>> >>>>>> 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 specializations of all >>>>>> primary templates declared deprecated, GCC 4.5 and later only >>>>>> diagnose declarations of explicit specializations of class >>>>>> templates but not those of function or variable templates. >>>>> >>>>> >>>>> Hmm, the discussion on the core reflector seemed to be agreeing that >>>>> we want to be able to define non-deprecated specializations of a >>>>> deprecated primary template. >>>> >>>> >>>> Yes, that's what Richard wanted to do. The only way to do it >>>> within the existing constraints(*) is to define a non-deprecated >>>> primary, and a deprecated partial specialization. This is in line >>>> with that approach and supported by Clang and all other compilers >>>> I tested (including Clang). >>> >>> >>> To clarify, this approach works for class templates (e.g., like >>> std::numeric_limits that was mentioned in the core discussion) >>> and for variable templates. Functions have no partial >>> specilizations so they have to be overloaded to achieve the same >>> effect. >>> >>> Implementations don't treat the deprecated attribute on partial >>> specializations consistently. >>> >>> EDG accepts and honors it on class template partial specializations >>> but rejects it with an error on those of variables. >>> >>> Clang accepts but silently ignores it on class template partial >>> specializations and rejects with an error it on variables. >>> >>> MSVC accepts and honors it on variables but silently ignores it >>> on class template partial specializations. >>> >>> GCC ignores it silently on class partial specializations and >>> with a warning on variables (I opened bug 84347 to track this >>> and to have GCC honor is everywhere). >>> >>> This is clearly a mess, which isn't surprising given how poorly >>> specified this is in the standard. But from the test cases and >>> from the core discussion it seems clear that deprecating >>> a template, including its partial specializations (as opposed >>> to just a single explicit specialization) is desirable and >>> already supported, and that the wording in the standard just >>> needs to be adjusted to reflect that. >>> >>>> >>>> Martin >>>> >>>> [*] Except (as Richard noted) that the standard doesn't seem to >>>> allow a template to be deprecated. I think that's a bug in the >>>> spec because all implementations allow it to some degree. >> >> >> One other note. While thinking about this problem during >> the core discussion, another approach to deprecating a primary >> template without also deprecating all of its specializations >> occurred to me. >> >> 1) First declare the primary template without [[deprecated]]. >> 2) Next declare its non-deprecated specializations (partial >> or explicit). >> 3) Finally declare the primary again, this time [[deprecated]]. >> >> Like this: >> >> template struct S; >> template struct S { }; >> template struct [[deprecated]] S { }; >> template struct [[deprecated]] S { }; >> >> S si; // warning >> S sci; // no warning >> S svi; // warning >> >> This works as expected with Intel ICC. All other compilers >> diagnose all three variables. I'd say for [[deprecated]] it >> should work the way ICC does. (For [[noreturn]] the first >> declaration must be [[noreturn]], so there this solution >> wouldn't work also because of that, in addition to function >> templates not being partially-specializable.) > > My understanding of the reflector discussion, and Richard's comment in > particular, was that [[deprecated]] should apply to the instances, not > the template itself, so that declaring the primary template > [[deprecated]] doesn't affect explicit specializations. Your last > example should work as you expect in this model, but you can also > write the simpler > > template struct [[deprecated]] S { }; > template struct S { }; // no warning With this approach there would be no way to deprecate all of a template's specializations) because it would always be possible for a user to get around deprecation by defining their own specialization, partial or explicit. I think we need to give users the choice of being able to do one without the other (in addition to both). I.e., either of 1) Deprecate a primary and all its uses (including partial and explicit specializations). 2) Deprecate just a subset of specializations of a template without also deprecating the rest. An example of (1) is std::auto_ptr or the std::is_literal_type type trait. The intent is to remove them from namespace std someday and providing any specializations for them will then become an error. An example of (2) is the std::numeric_limits primary template that Richard brought up. That was my understanding of what he wanted to do but even if that's not what he meant it's a reasonable use case as well. Martin