220 11112 <667b8cba-8368-426b-a592-5737ee1fbda0@isocpp.org> article
Path: news.gmane.org!not-for-mail
From: Douglas Boffey <douglas.boffey@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Core Issue: deleted templates
Date: Fri, 6 Jun 2014 07:46:51 -0700 (PDT)
Lines: 316
Approved: news@gmane.org
Message-ID: <667b8cba-8368-426b-a592-5737ee1fbda0@isocpp.org>
References: <a95232ae-71bc-41cc-ad52-511fa4aab43a@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/mixed; 
	boundary="----=_Part_531_17925646.1402066012394"
X-Trace: ger.gmane.org 1402066022 8412 80.91.229.3 (6 Jun 2014 14:47:02 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Fri, 6 Jun 2014 14:47:02 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBDSIZVXVVUFBBXNIY6OAKGQEI74L6CQ@isocpp.org Fri Jun 06 16:46:56 2014
Return-path: <std-proposals+bncBDSIZVXVVUFBBXNIY6OAKGQEI74L6CQ@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-ie0-f200.google.com ([209.85.223.200])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBDSIZVXVVUFBBXNIY6OAKGQEI74L6CQ@isocpp.org>)
	id 1WsvPz-0005QN-Ol
	for gclcip-std-proposals@m.gmane.org; Fri, 06 Jun 2014 16:46:56 +0200
Original-Received: by mail-ie0-f200.google.com with SMTP id to1sf5476151ieb.7
        for <gclcip-std-proposals@m.gmane.org>; Fri, 06 Jun 2014 07:46:54 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20120113;
        h=date:from:to:message-id:in-reply-to:references:subject:mime-version
         :x-original-sender:reply-to:precedence:mailing-list:list-id
         :list-post:list-help:list-archive:list-subscribe:list-unsubscribe
         :content-type;
        bh=9zbEQlxpukxncTDLbsdRfZXObD2rngz/dWvBRd2bo/E=;
        b=suHZdNiwDuQNiXwK60paVgjrBpoJmqTpnfAYfs/zqhP2Fwso2ov51BAupjOU7yTWhu
         3uHScPRui6AxZzgypzYFi9CtejurNzmBsP5s5kCK5a8tfEqxjHJgFuv+J2G5pFvc4aWJ
         l8y3PqsMy6I847WtLeI2EffU/BbOXlyG8j5EgPJUYJzkwNnvdO65rmBd0iVmz7YZwUec
         2oG/xwfQ47pT3Gh206Z8N3ZerAenu6GoQFa4EHqppwqt6heqXqRViSzEzIbtD7/l8dbd
         7KjwZDSF1mZdyCELp6k/JPe/NtI47QZN1t+9cian/AoLOmkYTKxzCPtJKJzELOCLe87L
         PfBA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:date:from:to:message-id:in-reply-to:references
         :subject:mime-version:x-original-sender:reply-to:precedence
         :mailing-list:list-id:list-post:list-help:list-archive
         :list-subscribe:list-unsubscribe:content-type;
        bh=9zbEQlxpukxncTDLbsdRfZXObD2rngz/dWvBRd2bo/E=;
        b=WkFp5GsGKP13fQojUy7aMfQHWRCW4d24sF5wcRWfCyk8VepH4Puqxo8/Qc7zQYqmSY
         I3HyYR+e/3DLNoroExRtjmRAoNSHtB7jVGggOQmrrtz6sQtG6zITlgIXyustfB2sciwO
         6ru3kg1FcEyLnOJcrnbaajermeKR6KjWUqn9ZBtOsmNFk6bbXBGTK9n0sfAlkUT0qMKi
         M1v0sBopvhn148m7ZN/bZ4NpkMGmoMuVdJhmNxrJNTplGpQTE8IPj7LvOhEXLpVe7p6g
         nCiKO3c3UWUQIn/MRi2IsNXGCpbCsdqu+xpLzlWUQIvanF1EkmWZRHigjyLRR2yhFW+o
         AG5w==
X-Gm-Message-State: ALoCoQkIu4bz4CmXIWPdGTSUQj0msyvIlUPpkarIfqgDMCwfgvmN6KohET8zIzpPhRMFATxQyHHa
X-Received: by 10.182.20.195 with SMTP id p3mr2773202obe.26.1402066014650;
        Fri, 06 Jun 2014 07:46:54 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.140.91.201 with SMTP id z67ls757595qgd.94.gmail; Fri, 06 Jun
 2014 07:46:53 -0700 (PDT)
X-Received: by 10.140.27.244 with SMTP id 107mr37869qgx.18.1402066013801;
        Fri, 06 Jun 2014 07:46:53 -0700 (PDT)
In-Reply-To: <a95232ae-71bc-41cc-ad52-511fa4aab43a@isocpp.org>
X-Original-Sender: douglas.boffey@gmail.com
Precedence: list
Mailing-list: list std-proposals@isocpp.org; contact std-proposals+owners@isocpp.org
List-ID: <std-proposals.isocpp.org>
X-Google-Group-Id: 399137483710
List-Post: <http://groups.google.com/a/isocpp.org/group/std-proposals/post>, <mailto:std-proposals@isocpp.org>
List-Help: <http://support.google.com/a/isocpp.org/bin/topic.py?topic=25838>, <mailto:std-proposals+help@isocpp.org>
List-Archive: <http://groups.google.com/a/isocpp.org/group/std-proposals/>
List-Subscribe: <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>,
 <mailto:std-proposals+subscribe@isocpp.org>
List-Unsubscribe: <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>,
 <mailto:googlegroups-manage+399137483710+unsubscribe@googlegroups.com>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:11112
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/11112>

------=_Part_531_17925646.1402066012394
Content-Type: multipart/alternative; 
	boundary="----=_Part_532_24644067.1402066012394"

------=_Part_532_24644067.1402066012394
Content-Type: text/plain; charset=UTF-8

Latest version:

-- 

--- 
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

------=_Part_532_24644067.1402066012394
Content-Type: text/html; charset=UTF-8

Latest version:

<p></p>

-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an email to <a href="mailto:std-proposals+unsubscribe@isocpp.org">std-proposals+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href="mailto:std-proposals@isocpp.org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href="http://groups.google.com/a/isocpp.org/group/std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/</a>.<br />

------=_Part_532_24644067.1402066012394--
------=_Part_531_17925646.1402066012394
Content-Type: text/html; charset=windows-1252; name=deletions.html
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment; filename=deletions.html
X-Attachment-Id: 0e1f78db-45b8-4c92-aad1-6b70758f7396
Content-ID: <0e1f78db-45b8-4c92-aad1-6b70758f7396>

<html>
  <head>
    <title>Class deletions</title>
  </head>
  <body>
    <h1>Class deletions</h1>
    <table>
      <tr>
        <td>Document number:</td>
        <td><i>Nnnnn=3Dyy&ndash;nnnn</i></td>
      </tr>
      <tr>
        <td>Date:</td>
        <td><i>2014&ndash;05&ndash;28</i></td>
      </tr>
      <tr>
        <td>Project:</td>
        <td>Programming Language C++, Evolutionary Working Group</td>
      </tr>
      <tr>
        <td>Reply-to:</td>
        <td><a href=3D"mailto:DougABoffey@netscape.net">Douglas Boffey
             &lt;DougABoffey@netscape.net></a></td>
      </tr>
    </table>
    <h2>Table of Contents</h2>
      <a href=3D"#intro">Introduction</a><p/>
      <a href=3D"#motivation">Motivation and Scope</a><p/>
      <a href=3D"#impact">Impact on the Standard</a><p/>
      <a href=3D"#design">Design decisions</a><p/>
      <a href=3D"#technical">Technical Specifications</a><p/>
      <a href=3D"#ack">Acknowledgements</a><p/>
      <a href=3D"#refs">References</a><p/>
      <a href=3D"#change">Change Log</a><p/>

    <h2><a id=3D"intro"/>Introduction</h2>
      This proposal is for the introduction of deleted classes, allowing th=
e following class definition:<p/>
      <code>class Foo =3D delete;</code><p/>
      This would make any further reference to class Foo an error.<p/>

    <h2><a id=3D"motivation"/>Motivation and Scope</h2>
      There are two problems this proposal addresses:<p/>
      <ol>
        <li><i>templates that are not substantiable</i>&mdash;sometimes, yo=
u may need to create a
            template class, but only specialisations haave any meaning.  Al=
ternatively,
            a specialisation of a group of specialisations needs to be
            deleted, for example, to disallow a zero-dimensional
            matrix (see, for example, page 844 in <a href=3D"#stro2013">[ST=
RO2013]</a>); and</li>
        <li><i>deprecated classes</i>&mdash;after a class has been deprecat=
ed, it may
            no longer be supported.  This is best done by deleting it.</li>
      </ol>
      The notation was chosen to mirror the way functions can be deleted at=
 the
         moment.<p/>
      One shortcoming is that there would be no method of indicating the re=
ason for the
         deletion, except within documentation.<p/>

    <h2><a id=3D"impact"/>Impact on the Standard</h2>
      This would allow a class definition to indicate that the class was de=
leted.<p/>

    <h2><a id=3D"design"/>Design Decisions</h2>
      There are currently two methods of achieving this:<p/>
      <ol>
        <li>not creating a class definition&mdash;this would leave the prog=
rammer to
            write his/her own, this negates the purpose of not defining the=
 class; and</li>
        <li>adding a <code>std::static_assert</code> to the body of the cla=
ss&mdash;this
            has the following problems:</li>
          <ul>
            <li>having a static_assert seems to be abusing the r&ocirc;le o=
f a static_assert, and</li>
            <li>code to indicate a class is not to be substantiated should =
be part of the
                header, not the body of the definition.</li>
          </ul>
      </ol>
      This could alternatively be solved by adding an attribute, for exampl=
e, [[poison]],
        but this would be changing the standard in a way that is contrary t=
o the current language.<p/>

      It was decided not to be able to create a pointer to a deleted class.=
  There are a couple of
        problems with allowing such:
      <ul>
        <li>such a class could never be constructor (no constructor) or des=
troyed (no destructor).</li>
        <li>deleted classes should not have state, but accessing a derived =
deleted class through
          its base&rsquo;s methods (whether virtual or not) would cause pro=
blems.</li>
      </ul>

      Regarding the sizeof of a deleted class, there are three reasonable a=
lternatives:
      <ul>
        <li>take its size to be the size of an empty class with the same ba=
se list</li>
        <li>take its size to be the size of an empty class with no base cla=
sses</li>
        <li>disallow a call of sizeof on a deleted class</li>
      </ul>
      Since it is not clear what sizeof should return, the best alternative=
 is simply to disallow it.

    <h2><a id=3D"technical"/>Technical specifications</h2>
      A class deletion would define a class that could not be used.  It wou=
ld have the following
        properties:<p/>
      <ul>
        <li>Deleted classes can be declared any number of times, but only d=
efined once (as per the ODR).
          [EXAMPLE:
          <code>
            <b>class</b> A;<br/>
            <br/>
            <b>class</b> A =3D <b>delete</b>; <i>// ok</i><br/>
            <br/>
            <b>class</b> A; <i>// ok</i><br/>
            <br/>
            <b>class</b> A {}; <i>// error: class deleted</i><br/>
            <br/>
            <b>class</b> A =3D <b>delete</b>; <i>// error: violation of ODR=
</i><br/>
          </code> &ndash; &ndash;END EXAMPLE]</li>
        <li>Deleted classes can have base classes, and only deleted classes=
 can derive from a deleted
          class.  [EXAMPLE:
          <code>
            <b>class</b> A {};<br/>
            <br/>
            <b>class</b> B : A =3D <b>delete</b>; <i>// ok: the base class =
is ignored</i><br/>
            <br/>
            <b>class</b> C : B {}; <i>// error: class B deleted</i><br/>
            <br/>
            <b>class</b> D : B =3D <b>delete</b>; <i>// ok</i><br/>
          </code> &ndash; &ndash;END EXAMPLE]</li>
        <li>Deleted classes cannot be substantiated or pointed to.  [EXAMPL=
E:
          <code>
            <b>class</b> A;<br/>
            <br/>
            A *a;<br/>
            <br/>
            <b>class</b> A =3D <b>delete</b>; <i>// error: class A in use</=
i><br/>
            <br/>
            <b>class</b> B;<br/>
            <br/>
            <b>class</b> C {<br/>
            &nbsp;&nbsp;B *b;<br/>
            };<br/>
            <br/>
            <b>class</b> B =3D <b>delete</b>; <i>// error: class in use</i>=
<br/>
            <br/>
            <b>class</b> D =3D <b>delete</b>;<br/>
            <br/>
            D *d; <i>// error: D deleted</i><br/>
            D d; <i>// error: D deleted</i><br/>
            <b>void</b> fn1(D d); <i>// error: D deleted</i><br/>
            <b>void</b> fn2(D *d); <i>// error: D deleted</i><br/>
            <b>void</b> fn3(D &d); <i>// error: D deleted</i><br/>
            <b>void</b> fn4(D &&d); <i>// error: D deleted</i><br/>
            D fn5(); <i>// error: D deleted</i><br/>
            D *fn6(); <i>// error: D deleted</i><br/>
            D &fn7(); <i>// error: D deleted</i><br/>
            D &&fn8(); <i>// error: D deleted</i><br/>
          </code> &ndash; &ndash;END EXAMPLE]</li>
        <li>Deleted classes can be befriended.  [EXAMPLE:
          <code>
            <b>class</b> A =3D <b>delete</b>;<br/>
            <br/>
            <b>class</b> B {<br/>
            &nbsp;&nbsp;<b>friend</b> <b>class</b> A; <i>// ok</i><br/>
            &nbsp;&nbsp;<b>friend</b> <b>class</b> C;<br/>
            };<br/>
            <br/>
            <b>class</b> C =3D <b>delete</b>; <i>// ok</i><br/>
          </code> &ndash; &ndash;END EXAMPLE]</li>
        <li>Deleted classes can be aliased. [EXAMPLE:
          <code>
            <b>class</b> A =3D <b>delete</b>;<br/>
            <br/>
            <b>typedef</b> A B; <i>// ok: B treated as deleted</i><br/>
            <b>using</b> C =3D A; <i>// ok: C treated as deleted</i><br/>
            <br/>
            B *b; <i>// error: A deleted</i><br/>
            C *c; <i>// error: A deleted</i><br/>
          </code> &ndash; &ndash;END EXAMPLE]</li>
        <li>sizeof cannot be called on a deleted class, but typeid can be. =
 operator new is
          not allowed to return a deleted class.  [EXAMPLE:
          <code>
            <b>class</b> A =3D deleted;<br/>
            <b>auto</b> s{<b>sizeof</b>(A)}; <i>// error: A deleted</i><br/=
>
            <b>auto</b> t{<b>typeid</b>(A)}; <i>// ok</i><br/>
            <br/>
            <b>auto</b> b =3D <b>new</b> A; <i>// error: A deleted</i><br/>
            <b>auto</b> c =3D <b>new</b> A[10]; <i>// error: A deleted</i><=
br/>
            <b>auto</b> d =3D <b>new</b> (/* whatever */) A; <i>// error: A=
 deleted</i><br/>
          </code> &ndash; &ndash;END EXAMPLE]</li>
        <li>Similarly, casting to a pointer to a deleted class is an error.=
  [EXAMPLE:
          <code>
          </code> &ndash; &ndash;END EXAMPLE]</li>
        <li>In some instances, it may not be possible to detect violations
          in a single compilation unit, and such detection would need to be
          done at link time.  [EXAMPLE:
          <code>
            <i>/* compilation unit a.hpp */</i><br/>
            <br/>
            <b>class</b> A;<br/>
            <br/>
            <i>/* compilation unit a.cpp */</i><br/>
            <br/>
            #include "a.hpp"<br/>
            <br/>
            <b>class</b> A =3D <b>delete</b>;<br/>
            <br/>
            <i>/* compilation unit b.cpp */</i><br/>
            <br/>
            #include "a.hpp"<br/>
            <br/>
            A *a; <i>// error: only detectable at link time</i><br/>
          </code> &ndash; &ndash;END EXAMPLE]</li>
      </ul>

    <h2><a id=3D"ack"/>Acknowledgements</h2>
      I would like to give thanks to everyone who has provided advice on th=
e proposal website.<p/>

    <h2><a id=3D"refs"/>References</h2>
    <a id=3D"#stro2013"/><b>[STRO2013]</b> Stroustrup, B. <i>The C++ Progra=
mming
       Language, 4<sup>th</sup> edition</i> Addison-Wesley, 2013, p. 844<p/=
>

    <h2><a id=3D"change"/>Change Log</h2>
    <ul>
      <li>2014&ndash;06&ndash;05
        <ul>
          <li>added this change log</li>
          <li>added title</li>
          <li>removed all inappropriate &lt;code> tags</li>
          <li>removed the &lsquo;unconditional=92 from the static_assert</l=
i>
          <li>made a first draft at the technical specifications</li>
          <li>changed the format of the references</li>
        </ul>
      </li>
      <li>2014&ndash;06&ndash;06
        <ul>corrected &lt;p> tags</ul>
        <ul>changed rule for classes derived from a deleted class</ul>
        <ul>added rationale for not allowing pointers to deleted classes, u=
sing sizeof on them</ul>
      </li>
    </ul>
  </body>
</html>

------=_Part_531_17925646.1402066012394--

.
