Topic: Make deconstructor virtual by default for pure


Author: Michael van der Werve <mvdwervex@gmail.com>
Date: Thu, 11 Oct 2018 08:09:45 -0700 (PDT)
Raw View
------=_Part_309_418094331.1539270585480
Content-Type: multipart/alternative;
 boundary="----=_Part_310_1034597544.1539270585481"

------=_Part_310_1034597544.1539270585481
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable



Currently, you need to *explicitly *specify the destructor as virtual, even=
=20
if all methods are pure virtual.

Example which does not work correctly.
class Base
{
public:
    // should be overridden=20
    virtual void doSomething() =3D 0;

    // define destructor
    virtual ~Base() =3D default;
};

class Derived : public Base
{
public:
    // override the function
    virtual void doSomething() override {}

    // define the destructor
    virtual ~Derived()
    {
        // do some fancy destructing
        std::cout << "destructed" << std::endl;
    }
};

And then running the following code
// create a derived instance
Derived *derived =3D new Derived();

// cast it to the base
Base *base =3D derived;

// now delete it as the base
delete base;

In the example, the derived class destructor will not be called. It can be=
=20
solved by simply altering the base class as such.
class Base
{
public:
    // should be overridden=20
    virtual void doSomething() =3D 0;

    // add a virtual destructor =20
    virtual ~Base() =3D default;
};

And naturally, everything works as expected.

So let me ask you this, is there any reason that a virtual destructor=20
should not simply be assumed when the class only has pure virtual=20
functions? There will be a virtual method table anyway, so why could it not=
=20
be assumed then?


I=E2=80=99d propose to make it the default, where you *can* make it non-vir=
tual by=20
specifying it explicitly if you want to disallow deleting by a pointer for=
=20
example. Wouldn't that make more sense?


--=20
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 e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp=
..org/d/msgid/std-proposals/17fe64b2-7c78-492e-814d-fef72e3a668b%40isocpp.or=
g.

------=_Part_310_1034597544.1539270585481
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><span id=3D"docs-internal-guid-9fd84c3f-7fff-0641-74b2-054=
e7ad336b7"><p dir=3D"ltr" style=3D"line-height:1.38;margin-top:0pt;margin-b=
ottom:0pt;"><span style=3D"font-size: 11pt; font-family: Arial; color: rgb(=
0, 0, 0); background-color: transparent; font-variant-numeric: normal; font=
-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wra=
p;">Currently, you need to <i>explicitly </i>specify the destructor as virt=
ual, even if all methods are pure virtual.</span><span style=3D"font-size: =
11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparen=
t; font-variant-numeric: normal; font-variant-east-asian: normal; vertical-=
align: baseline; white-space: pre-wrap;"><br class=3D"kix-line-break"></spa=
n><span style=3D"font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); =
background-color: transparent; font-variant-numeric: normal; font-variant-e=
ast-asian: normal; vertical-align: baseline; white-space: pre-wrap;"><br cl=
ass=3D"kix-line-break"></span><span style=3D"font-size: 11pt; font-family: =
Arial; color: rgb(0, 0, 0); background-color: transparent; font-variant-num=
eric: normal; font-variant-east-asian: normal; vertical-align: baseline; wh=
ite-space: pre-wrap;">Example which does not work correctly.</span><span st=
yle=3D"font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background=
-color: transparent; font-variant-numeric: normal; font-variant-east-asian:=
 normal; vertical-align: baseline; white-space: pre-wrap;"><br class=3D"kix=
-line-break"></span></p><div class=3D"prettyprint" style=3D"background-colo=
r: rgb(250, 250, 250); border-color: rgb(187, 187, 187); border-style: soli=
d; border-width: 1px; overflow-wrap: break-word;"><code class=3D"prettyprin=
t"><div class=3D"subprettyprint"><span style=3D"color: #008;" class=3D"styl=
ed-by-prettify">class</span><span style=3D"color: #000;" class=3D"styled-by=
-prettify"> </span><span style=3D"color: #606;" class=3D"styled-by-prettify=
">Base</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>=
</span><span style=3D"color: #660;" class=3D"styled-by-prettify">{</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span st=
yle=3D"color: #008;" class=3D"styled-by-prettify">public</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">:</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 </span><span style=
=3D"color: #800;" class=3D"styled-by-prettify">// should be overridden </sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=
=A0 </span><span style=3D"color: #008;" class=3D"styled-by-prettify">virtua=
l</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><=
span style=3D"color: #008;" class=3D"styled-by-prettify">void</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"> doSomething</span><span=
 style=3D"color: #660;" class=3D"styled-by-prettify">()</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color=
: #660;" class=3D"styled-by-prettify">=3D</span><span style=3D"color: #000;=
" class=3D"styled-by-prettify"> </span><span style=3D"color: #066;" class=
=3D"styled-by-prettify">0</span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">;</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"><br><br>=C2=A0 =C2=A0 </span><span style=3D"color: #800;" class=3D"st=
yled-by-prettify">// define destructor</span><span style=3D"color: #000;" c=
lass=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 </span><span style=3D"color: =
#008;" class=3D"styled-by-prettify">virtual</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">~</span><span style=3D"color: #606;" class=3D"style=
d-by-prettify">Base</span><span style=3D"color: #660;" class=3D"styled-by-p=
rettify">()</span><span style=3D"color: #000;" class=3D"styled-by-prettify"=
> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">=3D</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span s=
tyle=3D"color: #008;" class=3D"styled-by-prettify">default</span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify">;</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"color: #66=
0;" class=3D"styled-by-prettify">};</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify"><br><br></span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">class</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"> </span><span style=3D"color: #606;" class=3D"styled-by-=
prettify">Derived</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">:<=
/span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><sp=
an style=3D"color: #008;" class=3D"styled-by-prettify">public</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"c=
olor: #606;" class=3D"styled-by-prettify">Base</span><span style=3D"color: =
#000;" class=3D"styled-by-prettify"><br></span><span style=3D"color: #660;"=
 class=3D"styled-by-prettify">{</span><span style=3D"color: #000;" class=3D=
"styled-by-prettify"><br></span><span style=3D"color: #008;" class=3D"style=
d-by-prettify">public</span><span style=3D"color: #660;" class=3D"styled-by=
-prettify">:</span><span style=3D"color: #000;" class=3D"styled-by-prettify=
"><br>=C2=A0 =C2=A0 </span><span style=3D"color: #800;" class=3D"styled-by-=
prettify">// override the function</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 </span><span style=3D"color: #008=
;" class=3D"styled-by-prettify">virtual</span><span style=3D"color: #000;" =
class=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=3D"=
styled-by-prettify">void</span><span style=3D"color: #000;" class=3D"styled=
-by-prettify"> doSomething</span><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify">()</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"> </span><span style=3D"color: #008;" class=3D"styled-by-prettify">o=
verride</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </=
span><span style=3D"color: #660;" class=3D"styled-by-prettify">{}</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify"><br><br>=C2=A0 =C2=
=A0 </span><span style=3D"color: #800;" class=3D"styled-by-prettify">// def=
ine the destructor</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"><br>=C2=A0 =C2=A0 </span><span style=3D"color: #008;" class=3D"styl=
ed-by-prettify">virtual</span><span style=3D"color: #000;" class=3D"styled-=
by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">~</span><span style=3D"color: #606;" class=3D"styled-by-prettify">Deriv=
ed</span><span style=3D"color: #660;" class=3D"styled-by-prettify">()</span=
><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=
=A0 </span><span style=3D"color: #660;" class=3D"styled-by-prettify">{</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=
=A0 =C2=A0 =C2=A0 </span><span style=3D"color: #800;" class=3D"styled-by-pr=
ettify">// do some fancy destructing</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 std</span><span s=
tyle=3D"color: #660;" class=3D"styled-by-prettify">::</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify">cout </span><span style=3D"color=
: #660;" class=3D"styled-by-prettify">&lt;&lt;</span><span style=3D"color: =
#000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #080;" cl=
ass=3D"styled-by-prettify">&quot;destructed&quot;</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;"=
 class=3D"styled-by-prettify">&lt;&lt;</span><span style=3D"color: #000;" c=
lass=3D"styled-by-prettify"> std</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">::</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify">endl</span><span style=3D"color: #660;" class=3D"styled-by-=
prettify">;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"=
><br>=C2=A0 =C2=A0 </span><span style=3D"color: #660;" class=3D"styled-by-p=
rettify">}</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
<br></span><span style=3D"color: #660;" class=3D"styled-by-prettify">};</sp=
an></div></code></div><span style=3D"font-size: 11pt; font-family: Arial; c=
olor: rgb(0, 0, 0); background-color: transparent; font-variant-numeric: no=
rmal; font-variant-east-asian: normal; vertical-align: baseline; white-spac=
e: pre-wrap;"><br class=3D"kix-line-break"></span><span style=3D"font-size:=
 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transpare=
nt; font-variant-numeric: normal; font-variant-east-asian: normal; vertical=
-align: baseline; white-space: pre-wrap;">And then running the following co=
de</span><span style=3D"font-size: 11pt; font-family: Arial; color: rgb(0, =
0, 0); background-color: transparent; font-variant-numeric: normal; font-va=
riant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;"=
><br class=3D"kix-line-break"></span><div class=3D"prettyprint" style=3D"ba=
ckground-color: rgb(250, 250, 250); border-color: rgb(187, 187, 187); borde=
r-style: solid; border-width: 1px; overflow-wrap: break-word;"><code class=
=3D"prettyprint"><div class=3D"subprettyprint"><span style=3D"color: #800;"=
 class=3D"styled-by-prettify">// create a derived instance</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"c=
olor: #606;" class=3D"styled-by-prettify">Derived</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;"=
 class=3D"styled-by-prettify">*</span><span style=3D"color: #000;" class=3D=
"styled-by-prettify">derived </span><span style=3D"color: #660;" class=3D"s=
tyled-by-prettify">=3D</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify"> </span><span style=3D"color: #008;" class=3D"styled-by-prettif=
y">new</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </s=
pan><span style=3D"color: #606;" class=3D"styled-by-prettify">Derived</span=
><span style=3D"color: #660;" class=3D"styled-by-prettify">();</span><span =
style=3D"color: #000;" class=3D"styled-by-prettify"><br><br></span><span st=
yle=3D"color: #800;" class=3D"styled-by-prettify">// cast it to the base</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></span><s=
pan style=3D"color: #606;" class=3D"styled-by-prettify">Base</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">*</span><span style=3D"color: #008=
;" class=3D"styled-by-prettify">base</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">=3D</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"> derived</span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><=
br><br></span><span style=3D"color: #800;" class=3D"styled-by-prettify">// =
now delete it as the base</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"><br></span><span style=3D"color: #008;" class=3D"styled-by-p=
rettify">delete</span><span style=3D"color: #000;" class=3D"styled-by-prett=
ify"> </span><span style=3D"color: #008;" class=3D"styled-by-prettify">base=
</span><span style=3D"color: #660;" class=3D"styled-by-prettify">;</span></=
div></code></div><span style=3D"font-size: 11pt; font-family: Arial; color:=
 rgb(0, 0, 0); background-color: transparent; font-variant-numeric: normal;=
 font-variant-east-asian: normal; vertical-align: baseline; white-space: pr=
e-wrap;"><br class=3D"kix-line-break"></span><span style=3D"font-size: 11pt=
; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; f=
ont-variant-numeric: normal; font-variant-east-asian: normal; vertical-alig=
n: baseline; white-space: pre-wrap;">In the example, the derived class dest=
ructor will not be called. It can be solved by simply altering the base cla=
ss as such.</span><span style=3D"font-size: 11pt; font-family: Arial; color=
: rgb(0, 0, 0); background-color: transparent; font-variant-numeric: normal=
; font-variant-east-asian: normal; vertical-align: baseline; white-space: p=
re-wrap;"><br class=3D"kix-line-break"></span><div class=3D"prettyprint" st=
yle=3D"background-color: rgb(250, 250, 250); border-color: rgb(187, 187, 18=
7); border-style: solid; border-width: 1px; overflow-wrap: break-word;"><co=
de class=3D"prettyprint"><div class=3D"subprettyprint"><span style=3D"color=
: #008;" class=3D"styled-by-prettify">class</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"> </span><span style=3D"color: #606;" class=
=3D"styled-by-prettify">Base</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"><br></span><span style=3D"color: #660;" class=3D"styled-b=
y-prettify">{</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y"><br></span><span style=3D"color: #008;" class=3D"styled-by-prettify">pub=
lic</span><span style=3D"color: #660;" class=3D"styled-by-prettify">:</span=
><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=
=A0 </span><span style=3D"color: #800;" class=3D"styled-by-prettify">// sho=
uld be overridden </span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"><br>=C2=A0 =C2=A0 </span><span style=3D"color: #008;" class=3D"styl=
ed-by-prettify">virtual</span><span style=3D"color: #000;" class=3D"styled-=
by-prettify"> </span><span style=3D"color: #008;" class=3D"styled-by-pretti=
fy">void</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> d=
oSomething</span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
()</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"c=
olor: #066;" class=3D"styled-by-prettify">0</span><span style=3D"color: #66=
0;" class=3D"styled-by-prettify">;</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"><br><br>=C2=A0 =C2=A0 </span><span style=3D"color: =
#800;" class=3D"styled-by-prettify">// add a virtual destructor =C2=A0</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=
=A0 </span><span style=3D"color: #008;" class=3D"styled-by-prettify">virtua=
l</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><=
span style=3D"color: #660;" class=3D"styled-by-prettify">~</span><span styl=
e=3D"color: #606;" class=3D"styled-by-prettify">Base</span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">()</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">=3D</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"> </span><span style=3D"color: #008;" class=3D"styled-by-p=
rettify">default</span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br=
></span><span style=3D"color: #660;" class=3D"styled-by-prettify">};</span>=
</div></code></div><span style=3D"font-size: 11pt; font-family: Arial; colo=
r: rgb(0, 0, 0); background-color: transparent; font-variant-numeric: norma=
l; font-variant-east-asian: normal; vertical-align: baseline; white-space: =
pre-wrap;"><br class=3D"kix-line-break"></span><span style=3D"font-size: 11=
pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent;=
 font-variant-numeric: normal; font-variant-east-asian: normal; vertical-al=
ign: baseline; white-space: pre-wrap;">And naturally, everything works as e=
xpected.</span><span style=3D"font-size: 11pt; font-family: Arial; color: r=
gb(0, 0, 0); background-color: transparent; font-variant-numeric: normal; f=
ont-variant-east-asian: normal; vertical-align: baseline; white-space: pre-=
wrap;"><br class=3D"kix-line-break"></span><span style=3D"font-size: 11pt; =
font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; fon=
t-variant-numeric: normal; font-variant-east-asian: normal; vertical-align:=
 baseline; white-space: pre-wrap;"><br class=3D"kix-line-break"></span><spa=
n style=3D"font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); backgr=
ound-color: transparent; font-variant-numeric: normal; font-variant-east-as=
ian: normal; vertical-align: baseline; white-space: pre-wrap;">So let me as=
k you this, is there any reason that a virtual destructor should not simply=
 be assumed when the class only has pure virtual functions? There will be a=
 virtual method table anyway, so why could it not be assumed then?</span><p=
></p><br><p dir=3D"ltr" style=3D"line-height:1.38;margin-top:0pt;margin-bot=
tom:0pt;"><span style=3D"font-size: 11pt; font-family: Arial; color: rgb(0,=
 0, 0); background-color: transparent; font-variant-numeric: normal; font-v=
ariant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;=
">I=E2=80=99d propose to make it the default, where you <i>can</i> make it =
non-virtual by specifying it explicitly if you want to disallow deleting by=
 a pointer for example. Wouldn&#39;t that make more sense?</span></p><div><=
span style=3D"font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); bac=
kground-color: transparent; font-variant-numeric: normal; font-variant-east=
-asian: normal; vertical-align: baseline; white-space: pre-wrap;"><br></spa=
n></div></span><div><br></div></div>

<p></p>

-- <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 e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/17fe64b2-7c78-492e-814d-fef72e3a668b%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/17fe64b2-7c78-492e-814d-fef72e3a668b=
%40isocpp.org</a>.<br />

------=_Part_310_1034597544.1539270585481--

------=_Part_309_418094331.1539270585480--

.


Author: =?UTF-8?B?R2HFoXBlciBBxb5tYW4=?= <gasper.azman@gmail.com>
Date: Thu, 11 Oct 2018 16:13:12 +0100
Raw View
--0000000000008dc8ef0577f56950
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

Well, it's a non-backwards-compatible change that makes a yet another
special case. This language has a long history of not flipping defaults
once they've been established, if the reason isn't EXTREMELY compelling.

So... even though what you're proposing makes sense to do, this change
*silently breaks ABI* for code that intended to not have virtual
destructors, for not that much gain.

Therefore my personal read is you won't get it through the committee.

Ga=C5=A1per

On Thu, Oct 11, 2018 at 4:09 PM Michael van der Werve <mvdwervex@gmail.com>
wrote:

> Currently, you need to *explicitly *specify the destructor as virtual,
> even if all methods are pure virtual.
>
> Example which does not work correctly.
> class Base
> {
> public:
>     // should be overridden
>     virtual void doSomething() =3D 0;
>
>     // define destructor
>     virtual ~Base() =3D default;
> };
>
> class Derived : public Base
> {
> public:
>     // override the function
>     virtual void doSomething() override {}
>
>     // define the destructor
>     virtual ~Derived()
>     {
>         // do some fancy destructing
>         std::cout << "destructed" << std::endl;
>     }
> };
>
> And then running the following code
> // create a derived instance
> Derived *derived =3D new Derived();
>
> // cast it to the base
> Base *base =3D derived;
>
> // now delete it as the base
> delete base;
>
> In the example, the derived class destructor will not be called. It can b=
e
> solved by simply altering the base class as such.
> class Base
> {
> public:
>     // should be overridden
>     virtual void doSomething() =3D 0;
>
>     // add a virtual destructor
>     virtual ~Base() =3D default;
> };
>
> And naturally, everything works as expected.
>
> So let me ask you this, is there any reason that a virtual destructor
> should not simply be assumed when the class only has pure virtual
> functions? There will be a virtual method table anyway, so why could it n=
ot
> be assumed then?
>
>
> I=E2=80=99d propose to make it the default, where you *can* make it non-v=
irtual
> by specifying it explicitly if you want to disallow deleting by a pointer
> for example. Wouldn't that make more sense?
>
>
> --
> 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.
> To view this discussion on the web visit
> https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/17fe64b2-7c7=
8-492e-814d-fef72e3a668b%40isocpp.org
> <https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/17fe64b2-7c=
78-492e-814d-fef72e3a668b%40isocpp.org?utm_medium=3Demail&utm_source=3Dfoot=
er>
> .
>

--=20
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 e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp=
..org/d/msgid/std-proposals/CAANG%3DkUMe%2Bv9nD5NbuCWkEV5dLKbAi6haH06CDvJeDd=
Wyt9r6Q%40mail.gmail.com.

--0000000000008dc8ef0577f56950
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Well, it&#39;s a non-backwards-compatible change that make=
s a yet another special case. This language has a long history of not flipp=
ing defaults once they&#39;ve been established, if the reason isn&#39;t EXT=
REMELY compelling.<div><br></div><div>So... even though what you&#39;re pro=
posing makes sense to do, this change *silently breaks ABI* for code that i=
ntended to not have virtual destructors, for not that much gain.</div><div>=
<br></div><div>Therefore my personal read is you won&#39;t get it through t=
he committee.</div><div><br></div><div>Ga=C5=A1per</div></div><br><div clas=
s=3D"gmail_quote"><div dir=3D"ltr">On Thu, Oct 11, 2018 at 4:09 PM Michael =
van der Werve &lt;<a href=3D"mailto:mvdwervex@gmail.com">mvdwervex@gmail.co=
m</a>&gt; wrote:<br></div><blockquote class=3D"gmail_quote" style=3D"margin=
:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr"><=
span id=3D"m_6797301453727889151docs-internal-guid-9fd84c3f-7fff-0641-74b2-=
054e7ad336b7"><p dir=3D"ltr" style=3D"line-height:1.38;margin-top:0pt;margi=
n-bottom:0pt"><span style=3D"font-size:11pt;font-family:Arial;color:rgb(0,0=
,0);background-color:transparent;font-variant-numeric:normal;font-variant-e=
ast-asian:normal;vertical-align:baseline;white-space:pre-wrap">Currently, y=
ou need to <i>explicitly </i>specify the destructor as virtual, even if all=
 methods are pure virtual.</span><span style=3D"font-size:11pt;font-family:=
Arial;color:rgb(0,0,0);background-color:transparent;font-variant-numeric:no=
rmal;font-variant-east-asian:normal;vertical-align:baseline;white-space:pre=
-wrap"><br class=3D"m_6797301453727889151kix-line-break"></span><span style=
=3D"font-size:11pt;font-family:Arial;color:rgb(0,0,0);background-color:tran=
sparent;font-variant-numeric:normal;font-variant-east-asian:normal;vertical=
-align:baseline;white-space:pre-wrap"><br class=3D"m_6797301453727889151kix=
-line-break"></span><span style=3D"font-size:11pt;font-family:Arial;color:r=
gb(0,0,0);background-color:transparent;font-variant-numeric:normal;font-var=
iant-east-asian:normal;vertical-align:baseline;white-space:pre-wrap">Exampl=
e which does not work correctly.</span><span style=3D"font-size:11pt;font-f=
amily:Arial;color:rgb(0,0,0);background-color:transparent;font-variant-nume=
ric:normal;font-variant-east-asian:normal;vertical-align:baseline;white-spa=
ce:pre-wrap"><br class=3D"m_6797301453727889151kix-line-break"></span></p><=
div class=3D"m_6797301453727889151prettyprint" style=3D"background-color:rg=
b(250,250,250);border-color:rgb(187,187,187);border-style:solid;border-widt=
h:1px"><code class=3D"m_6797301453727889151prettyprint"><div class=3D"m_679=
7301453727889151subprettyprint"><span style=3D"color:#008" class=3D"m_67973=
01453727889151styled-by-prettify">class</span><span style=3D"color:#000" cl=
ass=3D"m_6797301453727889151styled-by-prettify"> </span><span style=3D"colo=
r:#606" class=3D"m_6797301453727889151styled-by-prettify">Base</span><span =
style=3D"color:#000" class=3D"m_6797301453727889151styled-by-prettify"><br>=
</span><span style=3D"color:#660" class=3D"m_6797301453727889151styled-by-p=
rettify">{</span><span style=3D"color:#000" class=3D"m_6797301453727889151s=
tyled-by-prettify"><br></span><span style=3D"color:#008" class=3D"m_6797301=
453727889151styled-by-prettify">public</span><span style=3D"color:#660" cla=
ss=3D"m_6797301453727889151styled-by-prettify">:</span><span style=3D"color=
:#000" class=3D"m_6797301453727889151styled-by-prettify"><br>=C2=A0 =C2=A0 =
</span><span style=3D"color:#800" class=3D"m_6797301453727889151styled-by-p=
rettify">// should be overridden </span><span style=3D"color:#000" class=3D=
"m_6797301453727889151styled-by-prettify"><br>=C2=A0 =C2=A0 </span><span st=
yle=3D"color:#008" class=3D"m_6797301453727889151styled-by-prettify">virtua=
l</span><span style=3D"color:#000" class=3D"m_6797301453727889151styled-by-=
prettify"> </span><span style=3D"color:#008" class=3D"m_6797301453727889151=
styled-by-prettify">void</span><span style=3D"color:#000" class=3D"m_679730=
1453727889151styled-by-prettify"> doSomething</span><span style=3D"color:#6=
60" class=3D"m_6797301453727889151styled-by-prettify">()</span><span style=
=3D"color:#000" class=3D"m_6797301453727889151styled-by-prettify"> </span><=
span style=3D"color:#660" class=3D"m_6797301453727889151styled-by-prettify"=
>=3D</span><span style=3D"color:#000" class=3D"m_6797301453727889151styled-=
by-prettify"> </span><span style=3D"color:#066" class=3D"m_6797301453727889=
151styled-by-prettify">0</span><span style=3D"color:#660" class=3D"m_679730=
1453727889151styled-by-prettify">;</span><span style=3D"color:#000" class=
=3D"m_6797301453727889151styled-by-prettify"><br><br>=C2=A0 =C2=A0 </span><=
span style=3D"color:#800" class=3D"m_6797301453727889151styled-by-prettify"=
>// define destructor</span><span style=3D"color:#000" class=3D"m_679730145=
3727889151styled-by-prettify"><br>=C2=A0 =C2=A0 </span><span style=3D"color=
:#008" class=3D"m_6797301453727889151styled-by-prettify">virtual</span><spa=
n style=3D"color:#000" class=3D"m_6797301453727889151styled-by-prettify"> <=
/span><span style=3D"color:#660" class=3D"m_6797301453727889151styled-by-pr=
ettify">~</span><span style=3D"color:#606" class=3D"m_6797301453727889151st=
yled-by-prettify">Base</span><span style=3D"color:#660" class=3D"m_67973014=
53727889151styled-by-prettify">()</span><span style=3D"color:#000" class=3D=
"m_6797301453727889151styled-by-prettify"> </span><span style=3D"color:#660=
" class=3D"m_6797301453727889151styled-by-prettify">=3D</span><span style=
=3D"color:#000" class=3D"m_6797301453727889151styled-by-prettify"> </span><=
span style=3D"color:#008" class=3D"m_6797301453727889151styled-by-prettify"=
>default</span><span style=3D"color:#660" class=3D"m_6797301453727889151sty=
led-by-prettify">;</span><span style=3D"color:#000" class=3D"m_679730145372=
7889151styled-by-prettify"><br></span><span style=3D"color:#660" class=3D"m=
_6797301453727889151styled-by-prettify">};</span><span style=3D"color:#000"=
 class=3D"m_6797301453727889151styled-by-prettify"><br><br></span><span sty=
le=3D"color:#008" class=3D"m_6797301453727889151styled-by-prettify">class</=
span><span style=3D"color:#000" class=3D"m_6797301453727889151styled-by-pre=
ttify"> </span><span style=3D"color:#606" class=3D"m_6797301453727889151sty=
led-by-prettify">Derived</span><span style=3D"color:#000" class=3D"m_679730=
1453727889151styled-by-prettify"> </span><span style=3D"color:#660" class=
=3D"m_6797301453727889151styled-by-prettify">:</span><span style=3D"color:#=
000" class=3D"m_6797301453727889151styled-by-prettify"> </span><span style=
=3D"color:#008" class=3D"m_6797301453727889151styled-by-prettify">public</s=
pan><span style=3D"color:#000" class=3D"m_6797301453727889151styled-by-pret=
tify"> </span><span style=3D"color:#606" class=3D"m_6797301453727889151styl=
ed-by-prettify">Base</span><span style=3D"color:#000" class=3D"m_6797301453=
727889151styled-by-prettify"><br></span><span style=3D"color:#660" class=3D=
"m_6797301453727889151styled-by-prettify">{</span><span style=3D"color:#000=
" class=3D"m_6797301453727889151styled-by-prettify"><br></span><span style=
=3D"color:#008" class=3D"m_6797301453727889151styled-by-prettify">public</s=
pan><span style=3D"color:#660" class=3D"m_6797301453727889151styled-by-pret=
tify">:</span><span style=3D"color:#000" class=3D"m_6797301453727889151styl=
ed-by-prettify"><br>=C2=A0 =C2=A0 </span><span style=3D"color:#800" class=
=3D"m_6797301453727889151styled-by-prettify">// override the function</span=
><span style=3D"color:#000" class=3D"m_6797301453727889151styled-by-prettif=
y"><br>=C2=A0 =C2=A0 </span><span style=3D"color:#008" class=3D"m_679730145=
3727889151styled-by-prettify">virtual</span><span style=3D"color:#000" clas=
s=3D"m_6797301453727889151styled-by-prettify"> </span><span style=3D"color:=
#008" class=3D"m_6797301453727889151styled-by-prettify">void</span><span st=
yle=3D"color:#000" class=3D"m_6797301453727889151styled-by-prettify"> doSom=
ething</span><span style=3D"color:#660" class=3D"m_6797301453727889151style=
d-by-prettify">()</span><span style=3D"color:#000" class=3D"m_6797301453727=
889151styled-by-prettify"> </span><span style=3D"color:#008" class=3D"m_679=
7301453727889151styled-by-prettify">override</span><span style=3D"color:#00=
0" class=3D"m_6797301453727889151styled-by-prettify"> </span><span style=3D=
"color:#660" class=3D"m_6797301453727889151styled-by-prettify">{}</span><sp=
an style=3D"color:#000" class=3D"m_6797301453727889151styled-by-prettify"><=
br><br>=C2=A0 =C2=A0 </span><span style=3D"color:#800" class=3D"m_679730145=
3727889151styled-by-prettify">// define the destructor</span><span style=3D=
"color:#000" class=3D"m_6797301453727889151styled-by-prettify"><br>=C2=A0 =
=C2=A0 </span><span style=3D"color:#008" class=3D"m_6797301453727889151styl=
ed-by-prettify">virtual</span><span style=3D"color:#000" class=3D"m_6797301=
453727889151styled-by-prettify"> </span><span style=3D"color:#660" class=3D=
"m_6797301453727889151styled-by-prettify">~</span><span style=3D"color:#606=
" class=3D"m_6797301453727889151styled-by-prettify">Derived</span><span sty=
le=3D"color:#660" class=3D"m_6797301453727889151styled-by-prettify">()</spa=
n><span style=3D"color:#000" class=3D"m_6797301453727889151styled-by-pretti=
fy"><br>=C2=A0 =C2=A0 </span><span style=3D"color:#660" class=3D"m_67973014=
53727889151styled-by-prettify">{</span><span style=3D"color:#000" class=3D"=
m_6797301453727889151styled-by-prettify"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 </=
span><span style=3D"color:#800" class=3D"m_6797301453727889151styled-by-pre=
ttify">// do some fancy destructing</span><span style=3D"color:#000" class=
=3D"m_6797301453727889151styled-by-prettify"><br>=C2=A0 =C2=A0 =C2=A0 =C2=
=A0 std</span><span style=3D"color:#660" class=3D"m_6797301453727889151styl=
ed-by-prettify">::</span><span style=3D"color:#000" class=3D"m_679730145372=
7889151styled-by-prettify">cout </span><span style=3D"color:#660" class=3D"=
m_6797301453727889151styled-by-prettify">&lt;&lt;</span><span style=3D"colo=
r:#000" class=3D"m_6797301453727889151styled-by-prettify"> </span><span sty=
le=3D"color:#080" class=3D"m_6797301453727889151styled-by-prettify">&quot;d=
estructed&quot;</span><span style=3D"color:#000" class=3D"m_679730145372788=
9151styled-by-prettify"> </span><span style=3D"color:#660" class=3D"m_67973=
01453727889151styled-by-prettify">&lt;&lt;</span><span style=3D"color:#000"=
 class=3D"m_6797301453727889151styled-by-prettify"> std</span><span style=
=3D"color:#660" class=3D"m_6797301453727889151styled-by-prettify">::</span>=
<span style=3D"color:#000" class=3D"m_6797301453727889151styled-by-prettify=
">endl</span><span style=3D"color:#660" class=3D"m_6797301453727889151style=
d-by-prettify">;</span><span style=3D"color:#000" class=3D"m_67973014537278=
89151styled-by-prettify"><br>=C2=A0 =C2=A0 </span><span style=3D"color:#660=
" class=3D"m_6797301453727889151styled-by-prettify">}</span><span style=3D"=
color:#000" class=3D"m_6797301453727889151styled-by-prettify"><br></span><s=
pan style=3D"color:#660" class=3D"m_6797301453727889151styled-by-prettify">=
};</span></div></code></div><span style=3D"font-size:11pt;font-family:Arial=
;color:rgb(0,0,0);background-color:transparent;font-variant-numeric:normal;=
font-variant-east-asian:normal;vertical-align:baseline;white-space:pre-wrap=
"><br class=3D"m_6797301453727889151kix-line-break"></span><span style=3D"f=
ont-size:11pt;font-family:Arial;color:rgb(0,0,0);background-color:transpare=
nt;font-variant-numeric:normal;font-variant-east-asian:normal;vertical-alig=
n:baseline;white-space:pre-wrap">And then running the following code</span>=
<span style=3D"font-size:11pt;font-family:Arial;color:rgb(0,0,0);background=
-color:transparent;font-variant-numeric:normal;font-variant-east-asian:norm=
al;vertical-align:baseline;white-space:pre-wrap"><br class=3D"m_67973014537=
27889151kix-line-break"></span><div class=3D"m_6797301453727889151prettypri=
nt" style=3D"background-color:rgb(250,250,250);border-color:rgb(187,187,187=
);border-style:solid;border-width:1px"><code class=3D"m_6797301453727889151=
prettyprint"><div class=3D"m_6797301453727889151subprettyprint"><span style=
=3D"color:#800" class=3D"m_6797301453727889151styled-by-prettify">// create=
 a derived instance</span><span style=3D"color:#000" class=3D"m_67973014537=
27889151styled-by-prettify"><br></span><span style=3D"color:#606" class=3D"=
m_6797301453727889151styled-by-prettify">Derived</span><span style=3D"color=
:#000" class=3D"m_6797301453727889151styled-by-prettify"> </span><span styl=
e=3D"color:#660" class=3D"m_6797301453727889151styled-by-prettify">*</span>=
<span style=3D"color:#000" class=3D"m_6797301453727889151styled-by-prettify=
">derived </span><span style=3D"color:#660" class=3D"m_6797301453727889151s=
tyled-by-prettify">=3D</span><span style=3D"color:#000" class=3D"m_67973014=
53727889151styled-by-prettify"> </span><span style=3D"color:#008" class=3D"=
m_6797301453727889151styled-by-prettify">new</span><span style=3D"color:#00=
0" class=3D"m_6797301453727889151styled-by-prettify"> </span><span style=3D=
"color:#606" class=3D"m_6797301453727889151styled-by-prettify">Derived</spa=
n><span style=3D"color:#660" class=3D"m_6797301453727889151styled-by-pretti=
fy">();</span><span style=3D"color:#000" class=3D"m_6797301453727889151styl=
ed-by-prettify"><br><br></span><span style=3D"color:#800" class=3D"m_679730=
1453727889151styled-by-prettify">// cast it to the base</span><span style=
=3D"color:#000" class=3D"m_6797301453727889151styled-by-prettify"><br></spa=
n><span style=3D"color:#606" class=3D"m_6797301453727889151styled-by-pretti=
fy">Base</span><span style=3D"color:#000" class=3D"m_6797301453727889151sty=
led-by-prettify"> </span><span style=3D"color:#660" class=3D"m_679730145372=
7889151styled-by-prettify">*</span><span style=3D"color:#008" class=3D"m_67=
97301453727889151styled-by-prettify">base</span><span style=3D"color:#000" =
class=3D"m_6797301453727889151styled-by-prettify"> </span><span style=3D"co=
lor:#660" class=3D"m_6797301453727889151styled-by-prettify">=3D</span><span=
 style=3D"color:#000" class=3D"m_6797301453727889151styled-by-prettify"> de=
rived</span><span style=3D"color:#660" class=3D"m_6797301453727889151styled=
-by-prettify">;</span><span style=3D"color:#000" class=3D"m_679730145372788=
9151styled-by-prettify"><br><br></span><span style=3D"color:#800" class=3D"=
m_6797301453727889151styled-by-prettify">// now delete it as the base</span=
><span style=3D"color:#000" class=3D"m_6797301453727889151styled-by-prettif=
y"><br></span><span style=3D"color:#008" class=3D"m_6797301453727889151styl=
ed-by-prettify">delete</span><span style=3D"color:#000" class=3D"m_67973014=
53727889151styled-by-prettify"> </span><span style=3D"color:#008" class=3D"=
m_6797301453727889151styled-by-prettify">base</span><span style=3D"color:#6=
60" class=3D"m_6797301453727889151styled-by-prettify">;</span></div></code>=
</div><span style=3D"font-size:11pt;font-family:Arial;color:rgb(0,0,0);back=
ground-color:transparent;font-variant-numeric:normal;font-variant-east-asia=
n:normal;vertical-align:baseline;white-space:pre-wrap"><br class=3D"m_67973=
01453727889151kix-line-break"></span><span style=3D"font-size:11pt;font-fam=
ily:Arial;color:rgb(0,0,0);background-color:transparent;font-variant-numeri=
c:normal;font-variant-east-asian:normal;vertical-align:baseline;white-space=
:pre-wrap">In the example, the derived class destructor will not be called.=
 It can be solved by simply altering the base class as such.</span><span st=
yle=3D"font-size:11pt;font-family:Arial;color:rgb(0,0,0);background-color:t=
ransparent;font-variant-numeric:normal;font-variant-east-asian:normal;verti=
cal-align:baseline;white-space:pre-wrap"><br class=3D"m_6797301453727889151=
kix-line-break"></span><div class=3D"m_6797301453727889151prettyprint" styl=
e=3D"background-color:rgb(250,250,250);border-color:rgb(187,187,187);border=
-style:solid;border-width:1px"><code class=3D"m_6797301453727889151prettypr=
int"><div class=3D"m_6797301453727889151subprettyprint"><span style=3D"colo=
r:#008" class=3D"m_6797301453727889151styled-by-prettify">class</span><span=
 style=3D"color:#000" class=3D"m_6797301453727889151styled-by-prettify"> </=
span><span style=3D"color:#606" class=3D"m_6797301453727889151styled-by-pre=
ttify">Base</span><span style=3D"color:#000" class=3D"m_6797301453727889151=
styled-by-prettify"><br></span><span style=3D"color:#660" class=3D"m_679730=
1453727889151styled-by-prettify">{</span><span style=3D"color:#000" class=
=3D"m_6797301453727889151styled-by-prettify"><br></span><span style=3D"colo=
r:#008" class=3D"m_6797301453727889151styled-by-prettify">public</span><spa=
n style=3D"color:#660" class=3D"m_6797301453727889151styled-by-prettify">:<=
/span><span style=3D"color:#000" class=3D"m_6797301453727889151styled-by-pr=
ettify"><br>=C2=A0 =C2=A0 </span><span style=3D"color:#800" class=3D"m_6797=
301453727889151styled-by-prettify">// should be overridden </span><span sty=
le=3D"color:#000" class=3D"m_6797301453727889151styled-by-prettify"><br>=C2=
=A0 =C2=A0 </span><span style=3D"color:#008" class=3D"m_6797301453727889151=
styled-by-prettify">virtual</span><span style=3D"color:#000" class=3D"m_679=
7301453727889151styled-by-prettify"> </span><span style=3D"color:#008" clas=
s=3D"m_6797301453727889151styled-by-prettify">void</span><span style=3D"col=
or:#000" class=3D"m_6797301453727889151styled-by-prettify"> doSomething</sp=
an><span style=3D"color:#660" class=3D"m_6797301453727889151styled-by-prett=
ify">()</span><span style=3D"color:#000" class=3D"m_6797301453727889151styl=
ed-by-prettify"> </span><span style=3D"color:#660" class=3D"m_6797301453727=
889151styled-by-prettify">=3D</span><span style=3D"color:#000" class=3D"m_6=
797301453727889151styled-by-prettify"> </span><span style=3D"color:#066" cl=
ass=3D"m_6797301453727889151styled-by-prettify">0</span><span style=3D"colo=
r:#660" class=3D"m_6797301453727889151styled-by-prettify">;</span><span sty=
le=3D"color:#000" class=3D"m_6797301453727889151styled-by-prettify"><br><br=
>=C2=A0 =C2=A0 </span><span style=3D"color:#800" class=3D"m_679730145372788=
9151styled-by-prettify">// add a virtual destructor =C2=A0</span><span styl=
e=3D"color:#000" class=3D"m_6797301453727889151styled-by-prettify"><br>=C2=
=A0 =C2=A0 </span><span style=3D"color:#008" class=3D"m_6797301453727889151=
styled-by-prettify">virtual</span><span style=3D"color:#000" class=3D"m_679=
7301453727889151styled-by-prettify"> </span><span style=3D"color:#660" clas=
s=3D"m_6797301453727889151styled-by-prettify">~</span><span style=3D"color:=
#606" class=3D"m_6797301453727889151styled-by-prettify">Base</span><span st=
yle=3D"color:#660" class=3D"m_6797301453727889151styled-by-prettify">()</sp=
an><span style=3D"color:#000" class=3D"m_6797301453727889151styled-by-prett=
ify"> </span><span style=3D"color:#660" class=3D"m_6797301453727889151style=
d-by-prettify">=3D</span><span style=3D"color:#000" class=3D"m_679730145372=
7889151styled-by-prettify"> </span><span style=3D"color:#008" class=3D"m_67=
97301453727889151styled-by-prettify">default</span><span style=3D"color:#66=
0" class=3D"m_6797301453727889151styled-by-prettify">;</span><span style=3D=
"color:#000" class=3D"m_6797301453727889151styled-by-prettify"><br></span><=
span style=3D"color:#660" class=3D"m_6797301453727889151styled-by-prettify"=
>};</span></div></code></div><span style=3D"font-size:11pt;font-family:Aria=
l;color:rgb(0,0,0);background-color:transparent;font-variant-numeric:normal=
;font-variant-east-asian:normal;vertical-align:baseline;white-space:pre-wra=
p"><br class=3D"m_6797301453727889151kix-line-break"></span><span style=3D"=
font-size:11pt;font-family:Arial;color:rgb(0,0,0);background-color:transpar=
ent;font-variant-numeric:normal;font-variant-east-asian:normal;vertical-ali=
gn:baseline;white-space:pre-wrap">And naturally, everything works as expect=
ed.</span><span style=3D"font-size:11pt;font-family:Arial;color:rgb(0,0,0);=
background-color:transparent;font-variant-numeric:normal;font-variant-east-=
asian:normal;vertical-align:baseline;white-space:pre-wrap"><br class=3D"m_6=
797301453727889151kix-line-break"></span><span style=3D"font-size:11pt;font=
-family:Arial;color:rgb(0,0,0);background-color:transparent;font-variant-nu=
meric:normal;font-variant-east-asian:normal;vertical-align:baseline;white-s=
pace:pre-wrap"><br class=3D"m_6797301453727889151kix-line-break"></span><sp=
an style=3D"font-size:11pt;font-family:Arial;color:rgb(0,0,0);background-co=
lor:transparent;font-variant-numeric:normal;font-variant-east-asian:normal;=
vertical-align:baseline;white-space:pre-wrap">So let me ask you this, is th=
ere any reason that a virtual destructor should not simply be assumed when =
the class only has pure virtual functions? There will be a virtual method t=
able anyway, so why could it not be assumed then?</span><p></p><br><p dir=
=3D"ltr" style=3D"line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span =
style=3D"font-size:11pt;font-family:Arial;color:rgb(0,0,0);background-color=
:transparent;font-variant-numeric:normal;font-variant-east-asian:normal;ver=
tical-align:baseline;white-space:pre-wrap">I=E2=80=99d propose to make it t=
he default, where you <i>can</i> make it non-virtual by specifying it expli=
citly if you want to disallow deleting by a pointer for example. Wouldn&#39=
;t that make more sense?</span></p><div><span style=3D"font-size:11pt;font-=
family:Arial;color:rgb(0,0,0);background-color:transparent;font-variant-num=
eric:normal;font-variant-east-asian:normal;vertical-align:baseline;white-sp=
ace:pre-wrap"><br></span></div></span><div><br></div></div>

<p></p>

-- <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 e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org" target=3D"_=
blank">std-proposals+unsubscribe@isocpp.org</a>.<br>
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org" target=3D"_blank">std-proposals@isocpp.org</a>.<br>
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/17fe64b2-7c78-492e-814d-fef72e3a668b%=
40isocpp.org?utm_medium=3Demail&amp;utm_source=3Dfooter" target=3D"_blank">=
https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/17fe64b2-7c78-=
492e-814d-fef72e3a668b%40isocpp.org</a>.<br>
</blockquote></div>

<p></p>

-- <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 e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/CAANG%3DkUMe%2Bv9nD5NbuCWkEV5dLKbAi6h=
aH06CDvJeDdWyt9r6Q%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter"=
>https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAANG%3DkUMe%=
2Bv9nD5NbuCWkEV5dLKbAi6haH06CDvJeDdWyt9r6Q%40mail.gmail.com</a>.<br />

--0000000000008dc8ef0577f56950--

.


Author: Michael van der Werve <mvdwervex@gmail.com>
Date: Thu, 11 Oct 2018 08:18:34 -0700 (PDT)
Raw View
------=_Part_289_1545222372.1539271114429
Content-Type: multipart/alternative;
 boundary="----=_Part_290_919418998.1539271114431"

------=_Part_290_919418998.1539271114431
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable



Currently, you need to specify the destructor as virtual, even if all=20
methods are pure virtual.

Example which does not work correctly.
class Base
{
public:
    // should be overridden=20
    virtual void doSomething() =3D 0;
};

class Derived : public Base
{
public:
    // override the function
    virtual void doSomething() override {}

    // define the destructor
    virtual ~Derived()
    {
        // do some fancy destructing
        std::cout << "destructed" << std::endl;
    }
};

And then running the following code
// create a derived instance
Derived *derived =3D new Derived();

// cast it to the base
Base *base =3D derived;

// now delete it as the base
delete base;

In the example, the derived class destructor will not be called. It can be=
=20
solved by simply altering the base class as such.
class Base
{
public:
    // should be overridden=20
    virtual void doSomething() =3D 0;

    // add a virtual destructor =20
    virtual ~Base() =3D default;
};


And naturally, everything works as expected.

So let me ask you this, is there any reason that a virtual destructor=20
should not simply be assumed when the class only has pure virtual=20
functions? There will be a virtual method table anyway, so why could it not=
=20
be assumed then?


I=E2=80=99d propose to make it the default, where you _can_ make it nonvirt=
ual if=20
you want to disallow deleting by a pointer explicitly.


PREVIOUSLY POSTED & EDITED: there was an error in the example, and I=20
couldn't find an edit post button.

--=20
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 e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp=
..org/d/msgid/std-proposals/144065d2-ab69-4a75-8544-7236a1850dc3%40isocpp.or=
g.

------=_Part_290_919418998.1539271114431
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><span id=3D"docs-internal-guid-b8359b98-7fff-c7a6-0f1c-9a3=
ff17a5c04"><p dir=3D"ltr" style=3D"line-height:1.38;margin-top:0pt;margin-b=
ottom:0pt;"><span style=3D"font-size: 11pt; font-family: Arial; color: rgb(=
0, 0, 0); background-color: transparent; font-variant-numeric: normal; font=
-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wra=
p;">Currently, you need to specify the destructor as virtual, even if all m=
ethods are pure virtual.</span><span style=3D"font-size: 11pt; font-family:=
 Arial; color: rgb(0, 0, 0); background-color: transparent; font-variant-nu=
meric: normal; font-variant-east-asian: normal; vertical-align: baseline; w=
hite-space: pre-wrap;"><br class=3D"kix-line-break"></span><span style=3D"f=
ont-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: =
transparent; font-variant-numeric: normal; font-variant-east-asian: normal;=
 vertical-align: baseline; white-space: pre-wrap;"><br class=3D"kix-line-br=
eak"></span><span style=3D"font-size: 11pt; font-family: Arial; color: rgb(=
0, 0, 0); background-color: transparent; font-variant-numeric: normal; font=
-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wra=
p;">Example which does not work correctly.</span><span style=3D"font-size: =
11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparen=
t; font-variant-numeric: normal; font-variant-east-asian: normal; vertical-=
align: baseline; white-space: pre-wrap;"><br class=3D"kix-line-break"></spa=
n></p><div class=3D"prettyprint" style=3D"background-color: rgb(250, 250, 2=
50); border-color: rgb(187, 187, 187); border-style: solid; border-width: 1=
px; overflow-wrap: break-word;"><code class=3D"prettyprint"><div class=3D"s=
ubprettyprint"><span style=3D"color: #008;" class=3D"styled-by-prettify">cl=
ass</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span=
><span style=3D"color: #606;" class=3D"styled-by-prettify">Base</span><span=
 style=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">{</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"color: #008=
;" class=3D"styled-by-prettify">public</span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify">:</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"><br>=C2=A0 =C2=A0 </span><span style=3D"color: #800;" cl=
ass=3D"styled-by-prettify">// should be overridden </span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 </span><span sty=
le=3D"color: #008;" class=3D"styled-by-prettify">virtual</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color=
: #008;" class=3D"styled-by-prettify">void</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"> doSomething</span><span style=3D"color: #6=
60;" class=3D"styled-by-prettify">()</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">=3D</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"> </span><span style=3D"color: #066;" class=3D"styled-by-prettify"=
>0</span><span style=3D"color: #660;" class=3D"styled-by-prettify">;</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span =
style=3D"color: #660;" class=3D"styled-by-prettify">};</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify"><br><br></span><span style=3D"f=
ont-variant-numeric: normal; font-variant-east-asian: normal; background-co=
lor: transparent; font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0);=
 vertical-align: baseline; white-space: pre-wrap;"><span style=3D"color: #0=
08;" class=3D"styled-by-prettify">class</span><span style=3D"color: #000;" =
class=3D"styled-by-prettify"> </span><span style=3D"color: #606;" class=3D"=
styled-by-prettify">Derived</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">:</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> =
</span><span style=3D"color: #008;" class=3D"styled-by-prettify">public</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span =
style=3D"color: #606;" class=3D"styled-by-prettify">Base</span></span><span=
 style=3D"font-variant-numeric: normal; font-variant-east-asian: normal; ba=
ckground-color: transparent; font-size: 11pt; font-family: Arial; color: rg=
b(0, 0, 0); vertical-align: baseline; white-space: pre-wrap;"><span style=
=3D"color: #000;" class=3D"styled-by-prettify"><br></span></span><span styl=
e=3D"font-variant-numeric: normal; font-variant-east-asian: normal; backgro=
und-color: transparent; font-size: 11pt; font-family: Arial; color: rgb(0, =
0, 0); vertical-align: baseline; white-space: pre-wrap;"><span style=3D"col=
or: #660;" class=3D"styled-by-prettify">{</span></span><span style=3D"font-=
variant-numeric: normal; font-variant-east-asian: normal; background-color:=
 transparent; font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); ver=
tical-align: baseline; white-space: pre-wrap;"><span style=3D"color: #000;"=
 class=3D"styled-by-prettify"><br></span></span><span style=3D"font-variant=
-numeric: normal; font-variant-east-asian: normal; background-color: transp=
arent; font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); vertical-a=
lign: baseline; white-space: pre-wrap;"><span style=3D"color: #008;" class=
=3D"styled-by-prettify">public</span><span style=3D"color: #660;" class=3D"=
styled-by-prettify">:</span></span><span style=3D"font-variant-numeric: nor=
mal; font-variant-east-asian: normal; background-color: transparent; font-s=
ize: 11pt; font-family: Arial; color: rgb(0, 0, 0); vertical-align: baselin=
e; white-space: pre-wrap;"><span style=3D"color: #000;" class=3D"styled-by-=
prettify"><br></span></span><span style=3D"font-variant-numeric: normal; fo=
nt-variant-east-asian: normal; background-color: transparent; font-size: 11=
pt; font-family: Arial; color: rgb(0, 0, 0); vertical-align: baseline; whit=
e-space: pre-wrap;"><span style=3D"color: #000;" class=3D"styled-by-prettif=
y">=C2=A0 =C2=A0 </span><span style=3D"color: #800;" class=3D"styled-by-pre=
ttify">// override the function</span></span><span style=3D"font-variant-nu=
meric: normal; font-variant-east-asian: normal; background-color: transpare=
nt; font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); vertical-alig=
n: baseline; white-space: pre-wrap;"><span style=3D"color: #000;" class=3D"=
styled-by-prettify"><br></span></span><span style=3D"font-variant-numeric: =
normal; font-variant-east-asian: normal; background-color: transparent; fon=
t-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); vertical-align: base=
line; white-space: pre-wrap;"><span style=3D"color: #000;" class=3D"styled-=
by-prettify">=C2=A0 =C2=A0 </span><span style=3D"color: #008;" class=3D"sty=
led-by-prettify">virtual</span><span style=3D"color: #000;" class=3D"styled=
-by-prettify"> </span><span style=3D"color: #008;" class=3D"styled-by-prett=
ify">void</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> =
doSomething</span><span style=3D"color: #660;" class=3D"styled-by-prettify"=
>()</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span=
><span style=3D"color: #008;" class=3D"styled-by-prettify">override</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify">{}</span></span><span style=
=3D"font-variant-numeric: normal; font-variant-east-asian: normal; backgrou=
nd-color: transparent; font-size: 11pt; font-family: Arial; color: rgb(0, 0=
, 0); vertical-align: baseline; white-space: pre-wrap;"><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify"><br></span></span><span style=3D"fon=
t-variant-numeric: normal; font-variant-east-asian: normal; background-colo=
r: transparent; font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); v=
ertical-align: baseline; white-space: pre-wrap;"><span style=3D"color: #000=
;" class=3D"styled-by-prettify"><br></span></span><span style=3D"font-varia=
nt-numeric: normal; font-variant-east-asian: normal; background-color: tran=
sparent; font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); vertical=
-align: baseline; white-space: pre-wrap;"><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify">=C2=A0 =C2=A0 </span><span style=3D"color: #800;" =
class=3D"styled-by-prettify">// define the destructor</span></span><span st=
yle=3D"font-variant-numeric: normal; font-variant-east-asian: normal; backg=
round-color: transparent; font-size: 11pt; font-family: Arial; color: rgb(0=
, 0, 0); vertical-align: baseline; white-space: pre-wrap;"><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify"><br></span></span><span style=3D"=
font-variant-numeric: normal; font-variant-east-asian: normal; background-c=
olor: transparent; font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0)=
; vertical-align: baseline; white-space: pre-wrap;"><span style=3D"color: #=
000;" class=3D"styled-by-prettify">=C2=A0 =C2=A0 </span><span style=3D"colo=
r: #008;" class=3D"styled-by-prettify">virtual</span><span style=3D"color: =
#000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" cl=
ass=3D"styled-by-prettify">~</span><span style=3D"color: #606;" class=3D"st=
yled-by-prettify">Derived</span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">()</span></span><span style=3D"font-variant-numeric: normal;=
 font-variant-east-asian: normal; background-color: transparent; font-size:=
 11pt; font-family: Arial; color: rgb(0, 0, 0); vertical-align: baseline; w=
hite-space: pre-wrap;"><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"><br></span></span><span style=3D"font-variant-numeric: normal; font-v=
ariant-east-asian: normal; background-color: transparent; font-size: 11pt; =
font-family: Arial; color: rgb(0, 0, 0); vertical-align: baseline; white-sp=
ace: pre-wrap;"><span style=3D"color: #000;" class=3D"styled-by-prettify">=
=C2=A0 =C2=A0 </span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">{</span></span><span style=3D"font-variant-numeric: normal; font-varian=
t-east-asian: normal; background-color: transparent; font-size: 11pt; font-=
family: Arial; color: rgb(0, 0, 0); vertical-align: baseline; white-space: =
pre-wrap;"><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></=
span></span><span style=3D"font-variant-numeric: normal; font-variant-east-=
asian: normal; background-color: transparent; font-size: 11pt; font-family:=
 Arial; color: rgb(0, 0, 0); vertical-align: baseline; white-space: pre-wra=
p;"><span style=3D"color: #000;" class=3D"styled-by-prettify">=C2=A0 =C2=A0=
 =C2=A0 =C2=A0 </span><span style=3D"color: #800;" class=3D"styled-by-prett=
ify">// do some fancy destructing</span></span><span style=3D"font-variant-=
numeric: normal; font-variant-east-asian: normal; background-color: transpa=
rent; font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); vertical-al=
ign: baseline; white-space: pre-wrap;"><span style=3D"color: #000;" class=
=3D"styled-by-prettify"><br></span></span><span style=3D"font-variant-numer=
ic: normal; font-variant-east-asian: normal; background-color: transparent;=
 font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); vertical-align: =
baseline; white-space: pre-wrap;"><span style=3D"color: #000;" class=3D"sty=
led-by-prettify">=C2=A0 =C2=A0 =C2=A0 =C2=A0 std</span><span style=3D"color=
: #660;" class=3D"styled-by-prettify">::</span><span style=3D"color: #000;"=
 class=3D"styled-by-prettify">cout </span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">&lt;&lt;</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span><span style=3D"color: #080;" class=3D"style=
d-by-prettify">&quot;destructed&quot;</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">&lt;&lt;</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify"> std</span><span style=3D"color: #660;" class=3D"styled-by-=
prettify">::</span><span style=3D"color: #000;" class=3D"styled-by-prettify=
">endl</span><span style=3D"color: #660;" class=3D"styled-by-prettify">;</s=
pan></span><span style=3D"font-variant-numeric: normal; font-variant-east-a=
sian: normal; background-color: transparent; font-size: 11pt; font-family: =
Arial; color: rgb(0, 0, 0); vertical-align: baseline; white-space: pre-wrap=
;"><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></span></s=
pan><span style=3D"font-variant-numeric: normal; font-variant-east-asian: n=
ormal; background-color: transparent; font-size: 11pt; font-family: Arial; =
color: rgb(0, 0, 0); vertical-align: baseline; white-space: pre-wrap;"><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify">=C2=A0 =C2=A0 </span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify">}</span></span><s=
pan style=3D"font-variant-numeric: normal; font-variant-east-asian: normal;=
 background-color: transparent; font-size: 11pt; font-family: Arial; color:=
 rgb(0, 0, 0); vertical-align: baseline; white-space: pre-wrap;"><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"><br></span></span><span sty=
le=3D"font-variant-numeric: normal; font-variant-east-asian: normal; backgr=
ound-color: transparent; font-size: 11pt; font-family: Arial; color: rgb(0,=
 0, 0); vertical-align: baseline; white-space: pre-wrap;"><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">};</span></span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"><br></span></div></code></div><span=
 style=3D"font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); backgro=
und-color: transparent; font-variant-numeric: normal; font-variant-east-asi=
an: normal; vertical-align: baseline; white-space: pre-wrap;"><br class=3D"=
kix-line-break"></span><span style=3D"font-size: 11pt; font-family: Arial; =
color: rgb(0, 0, 0); background-color: transparent; font-variant-numeric: n=
ormal; font-variant-east-asian: normal; vertical-align: baseline; white-spa=
ce: pre-wrap;">And then running the following code</span><span style=3D"fon=
t-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: tr=
ansparent; font-variant-numeric: normal; font-variant-east-asian: normal; v=
ertical-align: baseline; white-space: pre-wrap;"><br class=3D"kix-line-brea=
k"></span><div class=3D"prettyprint" style=3D"background-color: rgb(250, 25=
0, 250); border-color: rgb(187, 187, 187); border-style: solid; border-widt=
h: 1px; overflow-wrap: break-word;"><code class=3D"prettyprint"><div class=
=3D"subprettyprint"><span style=3D"color: #800;" class=3D"styled-by-prettif=
y">// create a derived instance</span><span style=3D"color: #000;" class=3D=
"styled-by-prettify"><br></span><span style=3D"color: #606;" class=3D"style=
d-by-prettify">Derived</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">*</span><span style=3D"color: #000;" class=3D"styled-by-prettify">derive=
d </span><span style=3D"color: #660;" class=3D"styled-by-prettify">=3D</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span s=
tyle=3D"color: #008;" class=3D"styled-by-prettify">new</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #=
606;" class=3D"styled-by-prettify">Derived</span><span style=3D"color: #660=
;" class=3D"styled-by-prettify">();</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify"><br><br></span><span style=3D"color: #800;" class=
=3D"styled-by-prettify">// cast it to the base</span><span style=3D"color: =
#000;" class=3D"styled-by-prettify"><br></span><span style=3D"color: #606;"=
 class=3D"styled-by-prettify">Base</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">*</span><span style=3D"color: #008;" class=3D"styled-by-pret=
tify">base</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
 </span><span style=3D"color: #660;" class=3D"styled-by-prettify">=3D</span=
><span style=3D"color: #000;" class=3D"styled-by-prettify"> derived</span><=
span style=3D"color: #660;" class=3D"styled-by-prettify">;</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"><br><br></span><span style=
=3D"color: #800;" class=3D"styled-by-prettify">// now delete it as the base=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></span=
><span style=3D"color: #008;" class=3D"styled-by-prettify">delete</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=
=3D"color: #008;" class=3D"styled-by-prettify">base</span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">;</span></div></code></div><span s=
tyle=3D"font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); backgroun=
d-color: transparent; font-variant-numeric: normal; font-variant-east-asian=
: normal; vertical-align: baseline; white-space: pre-wrap;"><br class=3D"ki=
x-line-break"></span><span style=3D"font-size: 11pt; font-family: Arial; co=
lor: rgb(0, 0, 0); background-color: transparent; font-variant-numeric: nor=
mal; font-variant-east-asian: normal; vertical-align: baseline; white-space=
: pre-wrap;">In the example, the derived class destructor will not be calle=
d. It can be solved by simply altering the base class as such.</span><span =
style=3D"font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); backgrou=
nd-color: transparent; font-variant-numeric: normal; font-variant-east-asia=
n: normal; vertical-align: baseline; white-space: pre-wrap;"><br class=3D"k=
ix-line-break"></span><div class=3D"prettyprint" style=3D"background-color:=
 rgb(250, 250, 250); border-color: rgb(187, 187, 187); border-style: solid;=
 border-width: 1px; overflow-wrap: break-word;"><code class=3D"prettyprint"=
><div class=3D"subprettyprint"><span style=3D"color: #008;" class=3D"styled=
-by-prettify">class</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"> </span><span style=3D"color: #606;" class=3D"styled-by-prettify">=
Base</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></=
span><span style=3D"color: #660;" class=3D"styled-by-prettify">{</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span styl=
e=3D"color: #008;" class=3D"styled-by-prettify">public</span><span style=3D=
"color: #660;" class=3D"styled-by-prettify">:</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 </span><span style=3D"=
color: #800;" class=3D"styled-by-prettify">// should be overridden </span><=
span style=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 =
</span><span style=3D"color: #008;" class=3D"styled-by-prettify">virtual</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span=
 style=3D"color: #008;" class=3D"styled-by-prettify">void</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> doSomething</span><span sty=
le=3D"color: #660;" class=3D"styled-by-prettify">()</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660=
;" class=3D"styled-by-prettify">=3D</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify"> </span><span style=3D"color: #066;" class=3D"styl=
ed-by-prettify">0</span><span style=3D"color: #660;" class=3D"styled-by-pre=
ttify">;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><b=
r><br>=C2=A0 =C2=A0 </span><span style=3D"color: #800;" class=3D"styled-by-=
prettify">// add a virtual destructor =C2=A0</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 </span><span style=3D"c=
olor: #008;" class=3D"styled-by-prettify">virtual</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;"=
 class=3D"styled-by-prettify">~</span><span style=3D"color: #606;" class=3D=
"styled-by-prettify">Base</span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">()</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
=3D</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span=
><span style=3D"color: #008;" class=3D"styled-by-prettify">default</span><s=
pan style=3D"color: #660;" class=3D"styled-by-prettify">;</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">};</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"><br><br></span></div></code></div><span st=
yle=3D"font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background=
-color: transparent; font-variant-numeric: normal; font-variant-east-asian:=
 normal; vertical-align: baseline; white-space: pre-wrap;"><br class=3D"kix=
-line-break"></span><span style=3D"font-size: 11pt; font-family: Arial; col=
or: rgb(0, 0, 0); background-color: transparent; font-variant-numeric: norm=
al; font-variant-east-asian: normal; vertical-align: baseline; white-space:=
 pre-wrap;">And naturally, everything works as expected.</span><span style=
=3D"font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-co=
lor: transparent; font-variant-numeric: normal; font-variant-east-asian: no=
rmal; vertical-align: baseline; white-space: pre-wrap;"><br class=3D"kix-li=
ne-break"></span><span style=3D"font-size: 11pt; font-family: Arial; color:=
 rgb(0, 0, 0); background-color: transparent; font-variant-numeric: normal;=
 font-variant-east-asian: normal; vertical-align: baseline; white-space: pr=
e-wrap;"><br class=3D"kix-line-break"></span><span style=3D"font-size: 11pt=
; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; f=
ont-variant-numeric: normal; font-variant-east-asian: normal; vertical-alig=
n: baseline; white-space: pre-wrap;">So let me ask you this, is there any r=
eason that a virtual destructor should not simply be assumed when the class=
 only has pure virtual functions? There will be a virtual method table anyw=
ay, so why could it not be assumed then?</span><p></p><br><p dir=3D"ltr" st=
yle=3D"line-height:1.38;margin-top:0pt;margin-bottom:0pt;"><span style=3D"f=
ont-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: =
transparent; font-variant-numeric: normal; font-variant-east-asian: normal;=
 vertical-align: baseline; white-space: pre-wrap;">I=E2=80=99d propose to m=
ake it the default, where you _can_ make it nonvirtual if you want to disal=
low deleting by a pointer explicitly.</span></p><p dir=3D"ltr" style=3D"lin=
e-height:1.38;margin-top:0pt;margin-bottom:0pt;"><span style=3D"font-size: =
11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: transparen=
t; font-variant-numeric: normal; font-variant-east-asian: normal; vertical-=
align: baseline; white-space: pre-wrap;"><br></span></p><p dir=3D"ltr" styl=
e=3D"line-height:1.38;margin-top:0pt;margin-bottom:0pt;"><font color=3D"#00=
0000" face=3D"Arial"><span style=3D"font-size: 14.6667px; white-space: pre-=
wrap;">PREVIOUSLY POSTED &amp; EDITED: there was an error in the example, a=
nd I couldn&#39;t find an edit post button.</span></font></p><div><span sty=
le=3D"font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-=
color: transparent; font-variant-numeric: normal; font-variant-east-asian: =
normal; vertical-align: baseline; white-space: pre-wrap;"><br></span></div>=
</span></div>

<p></p>

-- <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 e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/144065d2-ab69-4a75-8544-7236a1850dc3%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/144065d2-ab69-4a75-8544-7236a1850dc3=
%40isocpp.org</a>.<br />

------=_Part_290_919418998.1539271114431--

------=_Part_289_1545222372.1539271114429--

.


Author: Michael van der Werve <mvdwervex@gmail.com>
Date: Thu, 11 Oct 2018 08:20:17 -0700 (PDT)
Raw View
------=_Part_293_1442688773.1539271217956
Content-Type: multipart/alternative;
 boundary="----=_Part_294_1903770565.1539271217956"

------=_Part_294_1903770565.1539271217956
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

Sorry, I noticed a mistake in the example so I reposted it (couldn't find=
=20
the edit button). However, I see your point.=20

On Thursday, 11 October 2018 17:13:27 UTC+2, Ga=C5=A1per A=C5=BEman wrote:
>
> Well, it's a non-backwards-compatible change that makes a yet another=20
> special case. This language has a long history of not flipping defaults=
=20
> once they've been established, if the reason isn't EXTREMELY compelling.
>
> So... even though what you're proposing makes sense to do, this change=20
> *silently breaks ABI* for code that intended to not have virtual=20
> destructors, for not that much gain.
>
> Therefore my personal read is you won't get it through the committee.
>
> Ga=C5=A1per
>
> On Thu, Oct 11, 2018 at 4:09 PM Michael van der Werve <mvdw...@gmail.com=
=20
> <javascript:>> wrote:
>
>> Currently, you need to *explicitly *specify the destructor as virtual,=
=20
>> even if all methods are pure virtual.
>>
>> Example which does not work correctly.
>> class Base
>> {
>> public:
>>     // should be overridden=20
>>     virtual void doSomething() =3D 0;
>>
>>     // define destructor
>>     virtual ~Base() =3D default;
>> };
>>
>> class Derived : public Base
>> {
>> public:
>>     // override the function
>>     virtual void doSomething() override {}
>>
>>     // define the destructor
>>     virtual ~Derived()
>>     {
>>         // do some fancy destructing
>>         std::cout << "destructed" << std::endl;
>>     }
>> };
>>
>> And then running the following code
>> // create a derived instance
>> Derived *derived =3D new Derived();
>>
>> // cast it to the base
>> Base *base =3D derived;
>>
>> // now delete it as the base
>> delete base;
>>
>> In the example, the derived class destructor will not be called. It can=
=20
>> be solved by simply altering the base class as such.
>> class Base
>> {
>> public:
>>     // should be overridden=20
>>     virtual void doSomething() =3D 0;
>>
>>     // add a virtual destructor =20
>>     virtual ~Base() =3D default;
>> };
>>
>> And naturally, everything works as expected.
>>
>> So let me ask you this, is there any reason that a virtual destructor=20
>> should not simply be assumed when the class only has pure virtual=20
>> functions? There will be a virtual method table anyway, so why could it =
not=20
>> be assumed then?
>>
>>
>> I=E2=80=99d propose to make it the default, where you *can* make it non-=
virtual=20
>> by specifying it explicitly if you want to disallow deleting by a pointe=
r=20
>> for example. Wouldn't that make more sense?
>>
>>
>> --=20
>> You received this message because you are subscribed to the Google Group=
s=20
>> "ISO C++ Standard - Future Proposals" group.
>> To unsubscribe from this group and stop receiving emails from it, send a=
n=20
>> email to std-proposal...@isocpp.org <javascript:>.
>> To post to this group, send email to std-pr...@isocpp.org <javascript:>.
>> To view this discussion on the web visit=20
>> https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/17fe64b2-7c=
78-492e-814d-fef72e3a668b%40isocpp.org=20
>> <https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/17fe64b2-7=
c78-492e-814d-fef72e3a668b%40isocpp.org?utm_medium=3Demail&utm_source=3Dfoo=
ter>
>> .
>>
>

--=20
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 e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp=
..org/d/msgid/std-proposals/4082ddd4-097b-4652-ace2-7153cb4c26ea%40isocpp.or=
g.

------=_Part_294_1903770565.1539271217956
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Sorry, I noticed a mistake in the example so I reposted it=
 (couldn&#39;t find the edit button). However, I see your point.=C2=A0<br><=
br>On Thursday, 11 October 2018 17:13:27 UTC+2, Ga=C5=A1per A=C5=BEman  wro=
te:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;=
border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr">Well, it&#=
39;s a non-backwards-compatible change that makes a yet another special cas=
e. This language has a long history of not flipping defaults once they&#39;=
ve been established, if the reason isn&#39;t EXTREMELY compelling.<div><br>=
</div><div>So... even though what you&#39;re proposing makes sense to do, t=
his change *silently breaks ABI* for code that intended to not have virtual=
 destructors, for not that much gain.</div><div><br></div><div>Therefore my=
 personal read is you won&#39;t get it through the committee.</div><div><br=
></div><div>Ga=C5=A1per</div></div><br><div class=3D"gmail_quote"><div dir=
=3D"ltr">On Thu, Oct 11, 2018 at 4:09 PM Michael van der Werve &lt;<a href=
=3D"javascript:" target=3D"_blank" gdf-obfuscated-mailto=3D"93FICssiAwAJ" r=
el=3D"nofollow" onmousedown=3D"this.href=3D&#39;javascript:&#39;;return tru=
e;" onclick=3D"this.href=3D&#39;javascript:&#39;;return true;">mvdw...@gmai=
l.com</a>&gt; wrote:<br></div><blockquote class=3D"gmail_quote" style=3D"ma=
rgin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"lt=
r"><span><p dir=3D"ltr" style=3D"line-height:1.38;margin-top:0pt;margin-bot=
tom:0pt"><span style=3D"font-size:11pt;font-family:Arial;color:rgb(0,0,0);b=
ackground-color:transparent;vertical-align:baseline;white-space:pre-wrap">C=
urrently, you need to <i>explicitly </i>specify the destructor as virtual, =
even if all methods are pure virtual.</span><span style=3D"font-size:11pt;f=
ont-family:Arial;color:rgb(0,0,0);background-color:transparent;vertical-ali=
gn:baseline;white-space:pre-wrap"><br></span><span style=3D"font-size:11pt;=
font-family:Arial;color:rgb(0,0,0);background-color:transparent;vertical-al=
ign:baseline;white-space:pre-wrap"><br></span><span style=3D"font-size:11pt=
;font-family:Arial;color:rgb(0,0,0);background-color:transparent;vertical-a=
lign:baseline;white-space:pre-wrap">Example which does not work correctly.<=
/span><span style=3D"font-size:11pt;font-family:Arial;color:rgb(0,0,0);back=
ground-color:transparent;vertical-align:baseline;white-space:pre-wrap"><br>=
</span></p><div style=3D"background-color:rgb(250,250,250);border-color:rgb=
(187,187,187);border-style:solid;border-width:1px"><code><div><span style=
=3D"color:#008">class</span><span style=3D"color:#000"> </span><span style=
=3D"color:#606">Base</span><span style=3D"color:#000"><br></span><span styl=
e=3D"color:#660">{</span><span style=3D"color:#000"><br></span><span style=
=3D"color:#008">public</span><span style=3D"color:#660">:</span><span style=
=3D"color:#000"><br>=C2=A0 =C2=A0 </span><span style=3D"color:#800">// shou=
ld be overridden </span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 </span=
><span style=3D"color:#008">virtual</span><span style=3D"color:#000"> </spa=
n><span style=3D"color:#008">void</span><span style=3D"color:#000"> doSomet=
hing</span><span style=3D"color:#660">()</span><span style=3D"color:#000"> =
</span><span style=3D"color:#660">=3D</span><span style=3D"color:#000"> </s=
pan><span style=3D"color:#066">0</span><span style=3D"color:#660">;</span><=
span style=3D"color:#000"><br><br>=C2=A0 =C2=A0 </span><span style=3D"color=
:#800">// define destructor</span><span style=3D"color:#000"><br>=C2=A0 =C2=
=A0 </span><span style=3D"color:#008">virtual</span><span style=3D"color:#0=
00"> </span><span style=3D"color:#660">~</span><span style=3D"color:#606">B=
ase</span><span style=3D"color:#660">()</span><span style=3D"color:#000"> <=
/span><span style=3D"color:#660">=3D</span><span style=3D"color:#000"> </sp=
an><span style=3D"color:#008">default</span><span style=3D"color:#660">;</s=
pan><span style=3D"color:#000"><br></span><span style=3D"color:#660">};</sp=
an><span style=3D"color:#000"><br><br></span><span style=3D"color:#008">cla=
ss</span><span style=3D"color:#000"> </span><span style=3D"color:#606">Deri=
ved</span><span style=3D"color:#000"> </span><span style=3D"color:#660">:</=
span><span style=3D"color:#000"> </span><span style=3D"color:#008">public</=
span><span style=3D"color:#000"> </span><span style=3D"color:#606">Base</sp=
an><span style=3D"color:#000"><br></span><span style=3D"color:#660">{</span=
><span style=3D"color:#000"><br></span><span style=3D"color:#008">public</s=
pan><span style=3D"color:#660">:</span><span style=3D"color:#000"><br>=C2=
=A0 =C2=A0 </span><span style=3D"color:#800">// override the function</span=
><span style=3D"color:#000"><br>=C2=A0 =C2=A0 </span><span style=3D"color:#=
008">virtual</span><span style=3D"color:#000"> </span><span style=3D"color:=
#008">void</span><span style=3D"color:#000"> doSomething</span><span style=
=3D"color:#660">()</span><span style=3D"color:#000"> </span><span style=3D"=
color:#008">override</span><span style=3D"color:#000"> </span><span style=
=3D"color:#660">{}</span><span style=3D"color:#000"><br><br>=C2=A0 =C2=A0 <=
/span><span style=3D"color:#800">// define the destructor</span><span style=
=3D"color:#000"><br>=C2=A0 =C2=A0 </span><span style=3D"color:#008">virtual=
</span><span style=3D"color:#000"> </span><span style=3D"color:#660">~</spa=
n><span style=3D"color:#606">Derived</span><span style=3D"color:#660">()</s=
pan><span style=3D"color:#000"><br>=C2=A0 =C2=A0 </span><span style=3D"colo=
r:#660">{</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =
</span><span style=3D"color:#800">// do some fancy destructing</span><span =
style=3D"color:#000"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 std</span><span style=
=3D"color:#660">::</span><span style=3D"color:#000">cout </span><span style=
=3D"color:#660">&lt;&lt;</span><span style=3D"color:#000"> </span><span sty=
le=3D"color:#080">&quot;destructed&quot;</span><span style=3D"color:#000"> =
</span><span style=3D"color:#660">&lt;&lt;</span><span style=3D"color:#000"=
> std</span><span style=3D"color:#660">::</span><span style=3D"color:#000">=
endl</span><span style=3D"color:#660">;</span><span style=3D"color:#000"><b=
r>=C2=A0 =C2=A0 </span><span style=3D"color:#660">}</span><span style=3D"co=
lor:#000"><br></span><span style=3D"color:#660">};</span></div></code></div=
><span style=3D"font-size:11pt;font-family:Arial;color:rgb(0,0,0);backgroun=
d-color:transparent;vertical-align:baseline;white-space:pre-wrap"><br></spa=
n><span style=3D"font-size:11pt;font-family:Arial;color:rgb(0,0,0);backgrou=
nd-color:transparent;vertical-align:baseline;white-space:pre-wrap">And then=
 running the following code</span><span style=3D"font-size:11pt;font-family=
:Arial;color:rgb(0,0,0);background-color:transparent;vertical-align:baselin=
e;white-space:pre-wrap"><br></span><div style=3D"background-color:rgb(250,2=
50,250);border-color:rgb(187,187,187);border-style:solid;border-width:1px">=
<code><div><span style=3D"color:#800">// create a derived instance</span><s=
pan style=3D"color:#000"><br></span><span style=3D"color:#606">Derived</spa=
n><span style=3D"color:#000"> </span><span style=3D"color:#660">*</span><sp=
an style=3D"color:#000">derived </span><span style=3D"color:#660">=3D</span=
><span style=3D"color:#000"> </span><span style=3D"color:#008">new</span><s=
pan style=3D"color:#000"> </span><span style=3D"color:#606">Derived</span><=
span style=3D"color:#660">();</span><span style=3D"color:#000"><br><br></sp=
an><span style=3D"color:#800">// cast it to the base</span><span style=3D"c=
olor:#000"><br></span><span style=3D"color:#606">Base</span><span style=3D"=
color:#000"> </span><span style=3D"color:#660">*</span><span style=3D"color=
:#008">base</span><span style=3D"color:#000"> </span><span style=3D"color:#=
660">=3D</span><span style=3D"color:#000"> derived</span><span style=3D"col=
or:#660">;</span><span style=3D"color:#000"><br><br></span><span style=3D"c=
olor:#800">// now delete it as the base</span><span style=3D"color:#000"><b=
r></span><span style=3D"color:#008">delete</span><span style=3D"color:#000"=
> </span><span style=3D"color:#008">base</span><span style=3D"color:#660">;=
</span></div></code></div><span style=3D"font-size:11pt;font-family:Arial;c=
olor:rgb(0,0,0);background-color:transparent;vertical-align:baseline;white-=
space:pre-wrap"><br></span><span style=3D"font-size:11pt;font-family:Arial;=
color:rgb(0,0,0);background-color:transparent;vertical-align:baseline;white=
-space:pre-wrap">In the example, the derived class destructor will not be c=
alled. It can be solved by simply altering the base class as such.</span><s=
pan style=3D"font-size:11pt;font-family:Arial;color:rgb(0,0,0);background-c=
olor:transparent;vertical-align:baseline;white-space:pre-wrap"><br></span><=
div style=3D"background-color:rgb(250,250,250);border-color:rgb(187,187,187=
);border-style:solid;border-width:1px"><code><div><span style=3D"color:#008=
">class</span><span style=3D"color:#000"> </span><span style=3D"color:#606"=
>Base</span><span style=3D"color:#000"><br></span><span style=3D"color:#660=
">{</span><span style=3D"color:#000"><br></span><span style=3D"color:#008">=
public</span><span style=3D"color:#660">:</span><span style=3D"color:#000">=
<br>=C2=A0 =C2=A0 </span><span style=3D"color:#800">// should be overridden=
 </span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 </span><span style=3D"=
color:#008">virtual</span><span style=3D"color:#000"> </span><span style=3D=
"color:#008">void</span><span style=3D"color:#000"> doSomething</span><span=
 style=3D"color:#660">()</span><span style=3D"color:#000"> </span><span sty=
le=3D"color:#660">=3D</span><span style=3D"color:#000"> </span><span style=
=3D"color:#066">0</span><span style=3D"color:#660">;</span><span style=3D"c=
olor:#000"><br><br>=C2=A0 =C2=A0 </span><span style=3D"color:#800">// add a=
 virtual destructor =C2=A0</span><span style=3D"color:#000"><br>=C2=A0 =C2=
=A0 </span><span style=3D"color:#008">virtual</span><span style=3D"color:#0=
00"> </span><span style=3D"color:#660">~</span><span style=3D"color:#606">B=
ase</span><span style=3D"color:#660">()</span><span style=3D"color:#000"> <=
/span><span style=3D"color:#660">=3D</span><span style=3D"color:#000"> </sp=
an><span style=3D"color:#008">default</span><span style=3D"color:#660">;</s=
pan><span style=3D"color:#000"><br></span><span style=3D"color:#660">};</sp=
an></div></code></div><span style=3D"font-size:11pt;font-family:Arial;color=
:rgb(0,0,0);background-color:transparent;vertical-align:baseline;white-spac=
e:pre-wrap"><br></span><span style=3D"font-size:11pt;font-family:Arial;colo=
r:rgb(0,0,0);background-color:transparent;vertical-align:baseline;white-spa=
ce:pre-wrap">And naturally, everything works as expected.</span><span style=
=3D"font-size:11pt;font-family:Arial;color:rgb(0,0,0);background-color:tran=
sparent;vertical-align:baseline;white-space:pre-wrap"><br></span><span styl=
e=3D"font-size:11pt;font-family:Arial;color:rgb(0,0,0);background-color:tra=
nsparent;vertical-align:baseline;white-space:pre-wrap"><br></span><span sty=
le=3D"font-size:11pt;font-family:Arial;color:rgb(0,0,0);background-color:tr=
ansparent;vertical-align:baseline;white-space:pre-wrap">So let me ask you t=
his, is there any reason that a virtual destructor should not simply be ass=
umed when the class only has pure virtual functions? There will be a virtua=
l method table anyway, so why could it not be assumed then?</span><p></p><b=
r><p dir=3D"ltr" style=3D"line-height:1.38;margin-top:0pt;margin-bottom:0pt=
"><span style=3D"font-size:11pt;font-family:Arial;color:rgb(0,0,0);backgrou=
nd-color:transparent;vertical-align:baseline;white-space:pre-wrap">I=E2=80=
=99d propose to make it the default, where you <i>can</i> make it non-virtu=
al by specifying it explicitly if you want to disallow deleting by a pointe=
r for example. Wouldn&#39;t that make more sense?</span></p><div><span styl=
e=3D"font-size:11pt;font-family:Arial;color:rgb(0,0,0);background-color:tra=
nsparent;vertical-align:baseline;white-space:pre-wrap"><br></span></div></s=
pan><div><br></div></div>

<p></p>

-- <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 e=
mail to <a href=3D"javascript:" target=3D"_blank" gdf-obfuscated-mailto=3D"=
93FICssiAwAJ" rel=3D"nofollow" onmousedown=3D"this.href=3D&#39;javascript:&=
#39;;return true;" onclick=3D"this.href=3D&#39;javascript:&#39;;return true=
;">std-proposal...@<wbr>isocpp.org</a>.<br>
To post to this group, send email to <a href=3D"javascript:" target=3D"_bla=
nk" gdf-obfuscated-mailto=3D"93FICssiAwAJ" rel=3D"nofollow" onmousedown=3D"=
this.href=3D&#39;javascript:&#39;;return true;" onclick=3D"this.href=3D&#39=
;javascript:&#39;;return true;">std-pr...@isocpp.org</a>.<br>
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/17fe64b2-7c78-492e-814d-fef72e3a668b%=
40isocpp.org?utm_medium=3Demail&amp;utm_source=3Dfooter" target=3D"_blank" =
rel=3D"nofollow" onmousedown=3D"this.href=3D&#39;https://groups.google.com/=
a/isocpp.org/d/msgid/std-proposals/17fe64b2-7c78-492e-814d-fef72e3a668b%40i=
socpp.org?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;" on=
click=3D"this.href=3D&#39;https://groups.google.com/a/isocpp.org/d/msgid/st=
d-proposals/17fe64b2-7c78-492e-814d-fef72e3a668b%40isocpp.org?utm_medium\x3=
demail\x26utm_source\x3dfooter&#39;;return true;">https://groups.google.com=
/a/<wbr>isocpp.org/d/msgid/std-<wbr>proposals/17fe64b2-7c78-492e-<wbr>814d-=
fef72e3a668b%40isocpp.org</a><wbr>.<br>
</blockquote></div>
</blockquote></div>

<p></p>

-- <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 e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/4082ddd4-097b-4652-ace2-7153cb4c26ea%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/4082ddd4-097b-4652-ace2-7153cb4c26ea=
%40isocpp.org</a>.<br />

------=_Part_294_1903770565.1539271217956--

------=_Part_293_1442688773.1539271217956--

.


Author: Richard Smith <richard@metafoo.co.uk>
Date: Thu, 11 Oct 2018 13:09:37 -0700
Raw View
--0000000000008cc7bb0577f98d1e
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

On Thu, 11 Oct 2018 at 08:18, Michael van der Werve <mvdwervex@gmail.com>
wrote:

> Currently, you need to specify the destructor as virtual, even if all
> methods are pure virtual.
>
> Example which does not work correctly.
> class Base
> {
> public:
>     // should be overridden
>     virtual void doSomething() =3D 0;
> };
>
> class Derived : public Base
> {
> public:
>     // override the function
>     virtual void doSomething() override {}
>
>     // define the destructor
>     virtual ~Derived()
>     {
>         // do some fancy destructing
>         std::cout << "destructed" << std::endl;
>     }
> };
>
> And then running the following code
> // create a derived instance
> Derived *derived =3D new Derived();
>
> // cast it to the base
> Base *base =3D derived;
>
> // now delete it as the base
> delete base;
>
> In the example, the derived class destructor will not be called. It can b=
e
> solved by simply altering the base class as such.
> class Base
> {
> public:
>     // should be overridden
>     virtual void doSomething() =3D 0;
>
>     // add a virtual destructor
>     virtual ~Base() =3D default;
> };
>
>
> And naturally, everything works as expected.
>
> So let me ask you this, is there any reason that a virtual destructor
> should not simply be assumed when the class only has pure virtual functio=
ns?
>

Yes. Consider:

shared_ptr<Base> make() { return std::make_shared<Derived>(); }

This does not need the destructor to be virtual to function properly
(shared_ptr type-erases the destruction for the most-derived type), so
making the destructor virtual makes this code less efficient for no benefit=
..

Likewise:

struct FooBase {
  virtual Base *get();
  // ...
  virtual ~FooBase();
};
struct FooDerived {
  Derived *get() override { return &d; }
  // ...
private:
  Derived d;
};

Here, again, there is no benefit of making the Base destructor virtual,
because Base objects are never intended to be destroyed polymorphically.
(The disadvantage of a virtual destructor in this case is that it makes the
vtable larger and potentially makes Derived destruction non-trivial.)

The properties that you can make polymorphic calls on an object and that
you can destroy it polymorphically are correlated, but they are not
fundamentally tied together.

Disallowing *deletion* of an object of an abstract class type with a
non-virtual destructor would make sense as a language rule; indeed,at least
one compiler already warns on that by default.


> There will be a virtual method table anyway, so why could it not be
> assumed then?
>
>
> I=E2=80=99d propose to make it the default, where you _can_ make it nonvi=
rtual if
> you want to disallow deleting by a pointer explicitly.
>
>
> PREVIOUSLY POSTED & EDITED: there was an error in the example, and I
> couldn't find an edit post button.
>
> --
> 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.
> To view this discussion on the web visit
> https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/144065d2-ab6=
9-4a75-8544-7236a1850dc3%40isocpp.org
> <https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/144065d2-ab=
69-4a75-8544-7236a1850dc3%40isocpp.org?utm_medium=3Demail&utm_source=3Dfoot=
er>
> .
>

--=20
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 e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp=
..org/d/msgid/std-proposals/CAOfiQqnOFwfv_ebt3CeDvF934PEv5F3RLCMjibcHEyn2E1B=
Rjw%40mail.gmail.com.

--0000000000008cc7bb0577f98d1e
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div class=3D"gmail_quote"><div dir=3D"ltr">On Thu, 11 Oct=
 2018 at 08:18, Michael van der Werve &lt;<a href=3D"mailto:mvdwervex@gmail=
..com">mvdwervex@gmail.com</a>&gt; wrote:<br></div><blockquote class=3D"gmai=
l_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left=
:1ex"><div dir=3D"ltr"><span id=3D"m_3774939073749314107docs-internal-guid-=
b8359b98-7fff-c7a6-0f1c-9a3ff17a5c04"><p dir=3D"ltr" style=3D"line-height:1=
..38;margin-top:0pt;margin-bottom:0pt"><span style=3D"font-size:11pt;font-fa=
mily:Arial;color:rgb(0,0,0);background-color:transparent;font-variant-numer=
ic:normal;font-variant-east-asian:normal;vertical-align:baseline;white-spac=
e:pre-wrap">Currently, you need to specify the destructor as virtual, even =
if all methods are pure virtual.</span><span style=3D"font-size:11pt;font-f=
amily:Arial;color:rgb(0,0,0);background-color:transparent;font-variant-nume=
ric:normal;font-variant-east-asian:normal;vertical-align:baseline;white-spa=
ce:pre-wrap"><br class=3D"m_3774939073749314107kix-line-break"></span><span=
 style=3D"font-size:11pt;font-family:Arial;color:rgb(0,0,0);background-colo=
r:transparent;font-variant-numeric:normal;font-variant-east-asian:normal;ve=
rtical-align:baseline;white-space:pre-wrap"><br class=3D"m_3774939073749314=
107kix-line-break"></span><span style=3D"font-size:11pt;font-family:Arial;c=
olor:rgb(0,0,0);background-color:transparent;font-variant-numeric:normal;fo=
nt-variant-east-asian:normal;vertical-align:baseline;white-space:pre-wrap">=
Example which does not work correctly.</span><span style=3D"font-size:11pt;=
font-family:Arial;color:rgb(0,0,0);background-color:transparent;font-varian=
t-numeric:normal;font-variant-east-asian:normal;vertical-align:baseline;whi=
te-space:pre-wrap"><br class=3D"m_3774939073749314107kix-line-break"></span=
></p><div class=3D"m_3774939073749314107prettyprint" style=3D"background-co=
lor:rgb(250,250,250);border-color:rgb(187,187,187);border-style:solid;borde=
r-width:1px"><code class=3D"m_3774939073749314107prettyprint"><div class=3D=
"m_3774939073749314107subprettyprint"><span style=3D"color:#008" class=3D"m=
_3774939073749314107styled-by-prettify">class</span><span style=3D"color:#0=
00" class=3D"m_3774939073749314107styled-by-prettify"> </span><span style=
=3D"color:#606" class=3D"m_3774939073749314107styled-by-prettify">Base</spa=
n><span style=3D"color:#000" class=3D"m_3774939073749314107styled-by-pretti=
fy"><br></span><span style=3D"color:#660" class=3D"m_3774939073749314107sty=
led-by-prettify">{</span><span style=3D"color:#000" class=3D"m_377493907374=
9314107styled-by-prettify"><br></span><span style=3D"color:#008" class=3D"m=
_3774939073749314107styled-by-prettify">public</span><span style=3D"color:#=
660" class=3D"m_3774939073749314107styled-by-prettify">:</span><span style=
=3D"color:#000" class=3D"m_3774939073749314107styled-by-prettify"><br>=C2=
=A0 =C2=A0 </span><span style=3D"color:#800" class=3D"m_3774939073749314107=
styled-by-prettify">// should be overridden </span><span style=3D"color:#00=
0" class=3D"m_3774939073749314107styled-by-prettify"><br>=C2=A0 =C2=A0 </sp=
an><span style=3D"color:#008" class=3D"m_3774939073749314107styled-by-prett=
ify">virtual</span><span style=3D"color:#000" class=3D"m_377493907374931410=
7styled-by-prettify"> </span><span style=3D"color:#008" class=3D"m_37749390=
73749314107styled-by-prettify">void</span><span style=3D"color:#000" class=
=3D"m_3774939073749314107styled-by-prettify"> doSomething</span><span style=
=3D"color:#660" class=3D"m_3774939073749314107styled-by-prettify">()</span>=
<span style=3D"color:#000" class=3D"m_3774939073749314107styled-by-prettify=
"> </span><span style=3D"color:#660" class=3D"m_3774939073749314107styled-b=
y-prettify">=3D</span><span style=3D"color:#000" class=3D"m_377493907374931=
4107styled-by-prettify"> </span><span style=3D"color:#066" class=3D"m_37749=
39073749314107styled-by-prettify">0</span><span style=3D"color:#660" class=
=3D"m_3774939073749314107styled-by-prettify">;</span><span style=3D"color:#=
000" class=3D"m_3774939073749314107styled-by-prettify"><br></span><span sty=
le=3D"color:#660" class=3D"m_3774939073749314107styled-by-prettify">};</spa=
n><span style=3D"color:#000" class=3D"m_3774939073749314107styled-by-pretti=
fy"><br><br></span><span style=3D"font-variant-numeric:normal;font-variant-=
east-asian:normal;background-color:transparent;font-size:11pt;font-family:A=
rial;color:rgb(0,0,0);vertical-align:baseline;white-space:pre-wrap"><span s=
tyle=3D"color:#008" class=3D"m_3774939073749314107styled-by-prettify">class=
</span><span style=3D"color:#000" class=3D"m_3774939073749314107styled-by-p=
rettify"> </span><span style=3D"color:#606" class=3D"m_3774939073749314107s=
tyled-by-prettify">Derived</span><span style=3D"color:#000" class=3D"m_3774=
939073749314107styled-by-prettify"> </span><span style=3D"color:#660" class=
=3D"m_3774939073749314107styled-by-prettify">:</span><span style=3D"color:#=
000" class=3D"m_3774939073749314107styled-by-prettify"> </span><span style=
=3D"color:#008" class=3D"m_3774939073749314107styled-by-prettify">public</s=
pan><span style=3D"color:#000" class=3D"m_3774939073749314107styled-by-pret=
tify"> </span><span style=3D"color:#606" class=3D"m_3774939073749314107styl=
ed-by-prettify">Base</span></span><span style=3D"font-variant-numeric:norma=
l;font-variant-east-asian:normal;background-color:transparent;font-size:11p=
t;font-family:Arial;color:rgb(0,0,0);vertical-align:baseline;white-space:pr=
e-wrap"><span style=3D"color:#000" class=3D"m_3774939073749314107styled-by-=
prettify"><br></span></span><span style=3D"font-variant-numeric:normal;font=
-variant-east-asian:normal;background-color:transparent;font-size:11pt;font=
-family:Arial;color:rgb(0,0,0);vertical-align:baseline;white-space:pre-wrap=
"><span style=3D"color:#660" class=3D"m_3774939073749314107styled-by-pretti=
fy">{</span></span><span style=3D"font-variant-numeric:normal;font-variant-=
east-asian:normal;background-color:transparent;font-size:11pt;font-family:A=
rial;color:rgb(0,0,0);vertical-align:baseline;white-space:pre-wrap"><span s=
tyle=3D"color:#000" class=3D"m_3774939073749314107styled-by-prettify"><br><=
/span></span><span style=3D"font-variant-numeric:normal;font-variant-east-a=
sian:normal;background-color:transparent;font-size:11pt;font-family:Arial;c=
olor:rgb(0,0,0);vertical-align:baseline;white-space:pre-wrap"><span style=
=3D"color:#008" class=3D"m_3774939073749314107styled-by-prettify">public</s=
pan><span style=3D"color:#660" class=3D"m_3774939073749314107styled-by-pret=
tify">:</span></span><span style=3D"font-variant-numeric:normal;font-varian=
t-east-asian:normal;background-color:transparent;font-size:11pt;font-family=
:Arial;color:rgb(0,0,0);vertical-align:baseline;white-space:pre-wrap"><span=
 style=3D"color:#000" class=3D"m_3774939073749314107styled-by-prettify"><br=
></span></span><span style=3D"font-variant-numeric:normal;font-variant-east=
-asian:normal;background-color:transparent;font-size:11pt;font-family:Arial=
;color:rgb(0,0,0);vertical-align:baseline;white-space:pre-wrap"><span style=
=3D"color:#000" class=3D"m_3774939073749314107styled-by-prettify">=C2=A0 =
=C2=A0 </span><span style=3D"color:#800" class=3D"m_3774939073749314107styl=
ed-by-prettify">// override the function</span></span><span style=3D"font-v=
ariant-numeric:normal;font-variant-east-asian:normal;background-color:trans=
parent;font-size:11pt;font-family:Arial;color:rgb(0,0,0);vertical-align:bas=
eline;white-space:pre-wrap"><span style=3D"color:#000" class=3D"m_377493907=
3749314107styled-by-prettify"><br></span></span><span style=3D"font-variant=
-numeric:normal;font-variant-east-asian:normal;background-color:transparent=
;font-size:11pt;font-family:Arial;color:rgb(0,0,0);vertical-align:baseline;=
white-space:pre-wrap"><span style=3D"color:#000" class=3D"m_377493907374931=
4107styled-by-prettify">=C2=A0 =C2=A0 </span><span style=3D"color:#008" cla=
ss=3D"m_3774939073749314107styled-by-prettify">virtual</span><span style=3D=
"color:#000" class=3D"m_3774939073749314107styled-by-prettify"> </span><spa=
n style=3D"color:#008" class=3D"m_3774939073749314107styled-by-prettify">vo=
id</span><span style=3D"color:#000" class=3D"m_3774939073749314107styled-by=
-prettify"> doSomething</span><span style=3D"color:#660" class=3D"m_3774939=
073749314107styled-by-prettify">()</span><span style=3D"color:#000" class=
=3D"m_3774939073749314107styled-by-prettify"> </span><span style=3D"color:#=
008" class=3D"m_3774939073749314107styled-by-prettify">override</span><span=
 style=3D"color:#000" class=3D"m_3774939073749314107styled-by-prettify"> </=
span><span style=3D"color:#660" class=3D"m_3774939073749314107styled-by-pre=
ttify">{}</span></span><span style=3D"font-variant-numeric:normal;font-vari=
ant-east-asian:normal;background-color:transparent;font-size:11pt;font-fami=
ly:Arial;color:rgb(0,0,0);vertical-align:baseline;white-space:pre-wrap"><sp=
an style=3D"color:#000" class=3D"m_3774939073749314107styled-by-prettify"><=
br></span></span><span style=3D"font-variant-numeric:normal;font-variant-ea=
st-asian:normal;background-color:transparent;font-size:11pt;font-family:Ari=
al;color:rgb(0,0,0);vertical-align:baseline;white-space:pre-wrap"><span sty=
le=3D"color:#000" class=3D"m_3774939073749314107styled-by-prettify"><br></s=
pan></span><span style=3D"font-variant-numeric:normal;font-variant-east-asi=
an:normal;background-color:transparent;font-size:11pt;font-family:Arial;col=
or:rgb(0,0,0);vertical-align:baseline;white-space:pre-wrap"><span style=3D"=
color:#000" class=3D"m_3774939073749314107styled-by-prettify">=C2=A0 =C2=A0=
 </span><span style=3D"color:#800" class=3D"m_3774939073749314107styled-by-=
prettify">// define the destructor</span></span><span style=3D"font-variant=
-numeric:normal;font-variant-east-asian:normal;background-color:transparent=
;font-size:11pt;font-family:Arial;color:rgb(0,0,0);vertical-align:baseline;=
white-space:pre-wrap"><span style=3D"color:#000" class=3D"m_377493907374931=
4107styled-by-prettify"><br></span></span><span style=3D"font-variant-numer=
ic:normal;font-variant-east-asian:normal;background-color:transparent;font-=
size:11pt;font-family:Arial;color:rgb(0,0,0);vertical-align:baseline;white-=
space:pre-wrap"><span style=3D"color:#000" class=3D"m_3774939073749314107st=
yled-by-prettify">=C2=A0 =C2=A0 </span><span style=3D"color:#008" class=3D"=
m_3774939073749314107styled-by-prettify">virtual</span><span style=3D"color=
:#000" class=3D"m_3774939073749314107styled-by-prettify"> </span><span styl=
e=3D"color:#660" class=3D"m_3774939073749314107styled-by-prettify">~</span>=
<span style=3D"color:#606" class=3D"m_3774939073749314107styled-by-prettify=
">Derived</span><span style=3D"color:#660" class=3D"m_3774939073749314107st=
yled-by-prettify">()</span></span><span style=3D"font-variant-numeric:norma=
l;font-variant-east-asian:normal;background-color:transparent;font-size:11p=
t;font-family:Arial;color:rgb(0,0,0);vertical-align:baseline;white-space:pr=
e-wrap"><span style=3D"color:#000" class=3D"m_3774939073749314107styled-by-=
prettify"><br></span></span><span style=3D"font-variant-numeric:normal;font=
-variant-east-asian:normal;background-color:transparent;font-size:11pt;font=
-family:Arial;color:rgb(0,0,0);vertical-align:baseline;white-space:pre-wrap=
"><span style=3D"color:#000" class=3D"m_3774939073749314107styled-by-pretti=
fy">=C2=A0 =C2=A0 </span><span style=3D"color:#660" class=3D"m_377493907374=
9314107styled-by-prettify">{</span></span><span style=3D"font-variant-numer=
ic:normal;font-variant-east-asian:normal;background-color:transparent;font-=
size:11pt;font-family:Arial;color:rgb(0,0,0);vertical-align:baseline;white-=
space:pre-wrap"><span style=3D"color:#000" class=3D"m_3774939073749314107st=
yled-by-prettify"><br></span></span><span style=3D"font-variant-numeric:nor=
mal;font-variant-east-asian:normal;background-color:transparent;font-size:1=
1pt;font-family:Arial;color:rgb(0,0,0);vertical-align:baseline;white-space:=
pre-wrap"><span style=3D"color:#000" class=3D"m_3774939073749314107styled-b=
y-prettify">=C2=A0 =C2=A0 =C2=A0 =C2=A0 </span><span style=3D"color:#800" c=
lass=3D"m_3774939073749314107styled-by-prettify">// do some fancy destructi=
ng</span></span><span style=3D"font-variant-numeric:normal;font-variant-eas=
t-asian:normal;background-color:transparent;font-size:11pt;font-family:Aria=
l;color:rgb(0,0,0);vertical-align:baseline;white-space:pre-wrap"><span styl=
e=3D"color:#000" class=3D"m_3774939073749314107styled-by-prettify"><br></sp=
an></span><span style=3D"font-variant-numeric:normal;font-variant-east-asia=
n:normal;background-color:transparent;font-size:11pt;font-family:Arial;colo=
r:rgb(0,0,0);vertical-align:baseline;white-space:pre-wrap"><span style=3D"c=
olor:#000" class=3D"m_3774939073749314107styled-by-prettify">=C2=A0 =C2=A0 =
=C2=A0 =C2=A0 std</span><span style=3D"color:#660" class=3D"m_3774939073749=
314107styled-by-prettify">::</span><span style=3D"color:#000" class=3D"m_37=
74939073749314107styled-by-prettify">cout </span><span style=3D"color:#660"=
 class=3D"m_3774939073749314107styled-by-prettify">&lt;&lt;</span><span sty=
le=3D"color:#000" class=3D"m_3774939073749314107styled-by-prettify"> </span=
><span style=3D"color:#080" class=3D"m_3774939073749314107styled-by-prettif=
y">&quot;destructed&quot;</span><span style=3D"color:#000" class=3D"m_37749=
39073749314107styled-by-prettify"> </span><span style=3D"color:#660" class=
=3D"m_3774939073749314107styled-by-prettify">&lt;&lt;</span><span style=3D"=
color:#000" class=3D"m_3774939073749314107styled-by-prettify"> std</span><s=
pan style=3D"color:#660" class=3D"m_3774939073749314107styled-by-prettify">=
::</span><span style=3D"color:#000" class=3D"m_3774939073749314107styled-by=
-prettify">endl</span><span style=3D"color:#660" class=3D"m_377493907374931=
4107styled-by-prettify">;</span></span><span style=3D"font-variant-numeric:=
normal;font-variant-east-asian:normal;background-color:transparent;font-siz=
e:11pt;font-family:Arial;color:rgb(0,0,0);vertical-align:baseline;white-spa=
ce:pre-wrap"><span style=3D"color:#000" class=3D"m_3774939073749314107style=
d-by-prettify"><br></span></span><span style=3D"font-variant-numeric:normal=
;font-variant-east-asian:normal;background-color:transparent;font-size:11pt=
;font-family:Arial;color:rgb(0,0,0);vertical-align:baseline;white-space:pre=
-wrap"><span style=3D"color:#000" class=3D"m_3774939073749314107styled-by-p=
rettify">=C2=A0 =C2=A0 </span><span style=3D"color:#660" class=3D"m_3774939=
073749314107styled-by-prettify">}</span></span><span style=3D"font-variant-=
numeric:normal;font-variant-east-asian:normal;background-color:transparent;=
font-size:11pt;font-family:Arial;color:rgb(0,0,0);vertical-align:baseline;w=
hite-space:pre-wrap"><span style=3D"color:#000" class=3D"m_3774939073749314=
107styled-by-prettify"><br></span></span><span style=3D"font-variant-numeri=
c:normal;font-variant-east-asian:normal;background-color:transparent;font-s=
ize:11pt;font-family:Arial;color:rgb(0,0,0);vertical-align:baseline;white-s=
pace:pre-wrap"><span style=3D"color:#660" class=3D"m_3774939073749314107sty=
led-by-prettify">};</span></span><span style=3D"color:#000" class=3D"m_3774=
939073749314107styled-by-prettify"><br></span></div></code></div><span styl=
e=3D"font-size:11pt;font-family:Arial;color:rgb(0,0,0);background-color:tra=
nsparent;font-variant-numeric:normal;font-variant-east-asian:normal;vertica=
l-align:baseline;white-space:pre-wrap"><br class=3D"m_3774939073749314107ki=
x-line-break"></span><span style=3D"font-size:11pt;font-family:Arial;color:=
rgb(0,0,0);background-color:transparent;font-variant-numeric:normal;font-va=
riant-east-asian:normal;vertical-align:baseline;white-space:pre-wrap">And t=
hen running the following code</span><span style=3D"font-size:11pt;font-fam=
ily:Arial;color:rgb(0,0,0);background-color:transparent;font-variant-numeri=
c:normal;font-variant-east-asian:normal;vertical-align:baseline;white-space=
:pre-wrap"><br class=3D"m_3774939073749314107kix-line-break"></span><div cl=
ass=3D"m_3774939073749314107prettyprint" style=3D"background-color:rgb(250,=
250,250);border-color:rgb(187,187,187);border-style:solid;border-width:1px"=
><code class=3D"m_3774939073749314107prettyprint"><div class=3D"m_377493907=
3749314107subprettyprint"><span style=3D"color:#800" class=3D"m_37749390737=
49314107styled-by-prettify">// create a derived instance</span><span style=
=3D"color:#000" class=3D"m_3774939073749314107styled-by-prettify"><br></spa=
n><span style=3D"color:#606" class=3D"m_3774939073749314107styled-by-pretti=
fy">Derived</span><span style=3D"color:#000" class=3D"m_3774939073749314107=
styled-by-prettify"> </span><span style=3D"color:#660" class=3D"m_377493907=
3749314107styled-by-prettify">*</span><span style=3D"color:#000" class=3D"m=
_3774939073749314107styled-by-prettify">derived </span><span style=3D"color=
:#660" class=3D"m_3774939073749314107styled-by-prettify">=3D</span><span st=
yle=3D"color:#000" class=3D"m_3774939073749314107styled-by-prettify"> </spa=
n><span style=3D"color:#008" class=3D"m_3774939073749314107styled-by-pretti=
fy">new</span><span style=3D"color:#000" class=3D"m_3774939073749314107styl=
ed-by-prettify"> </span><span style=3D"color:#606" class=3D"m_3774939073749=
314107styled-by-prettify">Derived</span><span style=3D"color:#660" class=3D=
"m_3774939073749314107styled-by-prettify">();</span><span style=3D"color:#0=
00" class=3D"m_3774939073749314107styled-by-prettify"><br><br></span><span =
style=3D"color:#800" class=3D"m_3774939073749314107styled-by-prettify">// c=
ast it to the base</span><span style=3D"color:#000" class=3D"m_377493907374=
9314107styled-by-prettify"><br></span><span style=3D"color:#606" class=3D"m=
_3774939073749314107styled-by-prettify">Base</span><span style=3D"color:#00=
0" class=3D"m_3774939073749314107styled-by-prettify"> </span><span style=3D=
"color:#660" class=3D"m_3774939073749314107styled-by-prettify">*</span><spa=
n style=3D"color:#008" class=3D"m_3774939073749314107styled-by-prettify">ba=
se</span><span style=3D"color:#000" class=3D"m_3774939073749314107styled-by=
-prettify"> </span><span style=3D"color:#660" class=3D"m_377493907374931410=
7styled-by-prettify">=3D</span><span style=3D"color:#000" class=3D"m_377493=
9073749314107styled-by-prettify"> derived</span><span style=3D"color:#660" =
class=3D"m_3774939073749314107styled-by-prettify">;</span><span style=3D"co=
lor:#000" class=3D"m_3774939073749314107styled-by-prettify"><br><br></span>=
<span style=3D"color:#800" class=3D"m_3774939073749314107styled-by-prettify=
">// now delete it as the base</span><span style=3D"color:#000" class=3D"m_=
3774939073749314107styled-by-prettify"><br></span><span style=3D"color:#008=
" class=3D"m_3774939073749314107styled-by-prettify">delete</span><span styl=
e=3D"color:#000" class=3D"m_3774939073749314107styled-by-prettify"> </span>=
<span style=3D"color:#008" class=3D"m_3774939073749314107styled-by-prettify=
">base</span><span style=3D"color:#660" class=3D"m_3774939073749314107style=
d-by-prettify">;</span></div></code></div><span style=3D"font-size:11pt;fon=
t-family:Arial;color:rgb(0,0,0);background-color:transparent;font-variant-n=
umeric:normal;font-variant-east-asian:normal;vertical-align:baseline;white-=
space:pre-wrap"><br class=3D"m_3774939073749314107kix-line-break"></span><s=
pan style=3D"font-size:11pt;font-family:Arial;color:rgb(0,0,0);background-c=
olor:transparent;font-variant-numeric:normal;font-variant-east-asian:normal=
;vertical-align:baseline;white-space:pre-wrap">In the example, the derived =
class destructor will not be called. It can be solved by simply altering th=
e base class as such.</span><span style=3D"font-size:11pt;font-family:Arial=
;color:rgb(0,0,0);background-color:transparent;font-variant-numeric:normal;=
font-variant-east-asian:normal;vertical-align:baseline;white-space:pre-wrap=
"><br class=3D"m_3774939073749314107kix-line-break"></span><div class=3D"m_=
3774939073749314107prettyprint" style=3D"background-color:rgb(250,250,250);=
border-color:rgb(187,187,187);border-style:solid;border-width:1px"><code cl=
ass=3D"m_3774939073749314107prettyprint"><div class=3D"m_377493907374931410=
7subprettyprint"><span style=3D"color:#008" class=3D"m_3774939073749314107s=
tyled-by-prettify">class</span><span style=3D"color:#000" class=3D"m_377493=
9073749314107styled-by-prettify"> </span><span style=3D"color:#606" class=
=3D"m_3774939073749314107styled-by-prettify">Base</span><span style=3D"colo=
r:#000" class=3D"m_3774939073749314107styled-by-prettify"><br></span><span =
style=3D"color:#660" class=3D"m_3774939073749314107styled-by-prettify">{</s=
pan><span style=3D"color:#000" class=3D"m_3774939073749314107styled-by-pret=
tify"><br></span><span style=3D"color:#008" class=3D"m_3774939073749314107s=
tyled-by-prettify">public</span><span style=3D"color:#660" class=3D"m_37749=
39073749314107styled-by-prettify">:</span><span style=3D"color:#000" class=
=3D"m_3774939073749314107styled-by-prettify"><br>=C2=A0 =C2=A0 </span><span=
 style=3D"color:#800" class=3D"m_3774939073749314107styled-by-prettify">// =
should be overridden </span><span style=3D"color:#000" class=3D"m_377493907=
3749314107styled-by-prettify"><br>=C2=A0 =C2=A0 </span><span style=3D"color=
:#008" class=3D"m_3774939073749314107styled-by-prettify">virtual</span><spa=
n style=3D"color:#000" class=3D"m_3774939073749314107styled-by-prettify"> <=
/span><span style=3D"color:#008" class=3D"m_3774939073749314107styled-by-pr=
ettify">void</span><span style=3D"color:#000" class=3D"m_377493907374931410=
7styled-by-prettify"> doSomething</span><span style=3D"color:#660" class=3D=
"m_3774939073749314107styled-by-prettify">()</span><span style=3D"color:#00=
0" class=3D"m_3774939073749314107styled-by-prettify"> </span><span style=3D=
"color:#660" class=3D"m_3774939073749314107styled-by-prettify">=3D</span><s=
pan style=3D"color:#000" class=3D"m_3774939073749314107styled-by-prettify">=
 </span><span style=3D"color:#066" class=3D"m_3774939073749314107styled-by-=
prettify">0</span><span style=3D"color:#660" class=3D"m_3774939073749314107=
styled-by-prettify">;</span><span style=3D"color:#000" class=3D"m_377493907=
3749314107styled-by-prettify"><br><br>=C2=A0 =C2=A0 </span><span style=3D"c=
olor:#800" class=3D"m_3774939073749314107styled-by-prettify">// add a virtu=
al destructor =C2=A0</span><span style=3D"color:#000" class=3D"m_3774939073=
749314107styled-by-prettify"><br>=C2=A0 =C2=A0 </span><span style=3D"color:=
#008" class=3D"m_3774939073749314107styled-by-prettify">virtual</span><span=
 style=3D"color:#000" class=3D"m_3774939073749314107styled-by-prettify"> </=
span><span style=3D"color:#660" class=3D"m_3774939073749314107styled-by-pre=
ttify">~</span><span style=3D"color:#606" class=3D"m_3774939073749314107sty=
led-by-prettify">Base</span><span style=3D"color:#660" class=3D"m_377493907=
3749314107styled-by-prettify">()</span><span style=3D"color:#000" class=3D"=
m_3774939073749314107styled-by-prettify"> </span><span style=3D"color:#660"=
 class=3D"m_3774939073749314107styled-by-prettify">=3D</span><span style=3D=
"color:#000" class=3D"m_3774939073749314107styled-by-prettify"> </span><spa=
n style=3D"color:#008" class=3D"m_3774939073749314107styled-by-prettify">de=
fault</span><span style=3D"color:#660" class=3D"m_3774939073749314107styled=
-by-prettify">;</span><span style=3D"color:#000" class=3D"m_377493907374931=
4107styled-by-prettify"><br></span><span style=3D"color:#660" class=3D"m_37=
74939073749314107styled-by-prettify">};</span><span style=3D"color:#000" cl=
ass=3D"m_3774939073749314107styled-by-prettify"><br><br></span></div></code=
></div><span style=3D"font-size:11pt;font-family:Arial;color:rgb(0,0,0);bac=
kground-color:transparent;font-variant-numeric:normal;font-variant-east-asi=
an:normal;vertical-align:baseline;white-space:pre-wrap"><br class=3D"m_3774=
939073749314107kix-line-break"></span><span style=3D"font-size:11pt;font-fa=
mily:Arial;color:rgb(0,0,0);background-color:transparent;font-variant-numer=
ic:normal;font-variant-east-asian:normal;vertical-align:baseline;white-spac=
e:pre-wrap">And naturally, everything works as expected.</span><span style=
=3D"font-size:11pt;font-family:Arial;color:rgb(0,0,0);background-color:tran=
sparent;font-variant-numeric:normal;font-variant-east-asian:normal;vertical=
-align:baseline;white-space:pre-wrap"><br class=3D"m_3774939073749314107kix=
-line-break"></span><span style=3D"font-size:11pt;font-family:Arial;color:r=
gb(0,0,0);background-color:transparent;font-variant-numeric:normal;font-var=
iant-east-asian:normal;vertical-align:baseline;white-space:pre-wrap"><br cl=
ass=3D"m_3774939073749314107kix-line-break"></span><span style=3D"font-size=
:11pt;font-family:Arial;color:rgb(0,0,0);background-color:transparent;font-=
variant-numeric:normal;font-variant-east-asian:normal;vertical-align:baseli=
ne;white-space:pre-wrap">So let me ask you this, is there any reason that a=
 virtual destructor should not simply be assumed when the class only has pu=
re virtual functions?</span></span></div></blockquote><div><br></div><div>Y=
es. Consider:</div><div><br></div><div>shared_ptr&lt;Base&gt; make() { retu=
rn std::make_shared&lt;Derived&gt;(); }</div><div><br></div><div>This does =
not need the destructor to be virtual to function properly (shared_ptr type=
-erases the destruction for the most-derived type), so making the destructo=
r virtual=C2=A0makes this code less efficient for no benefit.</div><div><br=
></div><div>Likewise:</div><div><br></div><div>struct FooBase {</div><div>=
=C2=A0 virtual Base *get();</div><div>=C2=A0 // ...</div><div>=C2=A0 virtua=
l ~FooBase();</div><div>};</div><div>struct FooDerived {</div><div>=C2=A0 D=
erived *get() override { return &amp;d; }</div><div>=C2=A0 // ...</div><div=
>private:<br></div><div>=C2=A0 Derived d;</div><div>};</div><div><br></div>=
<div>Here, again, there is no benefit of making the Base destructor virtual=
, because Base objects are never intended to be destroyed polymorphically. =
(The disadvantage of a virtual destructor in this case is that it makes the=
 vtable larger and potentially makes Derived destruction non-trivial.)</div=
><div><br></div><div>The properties that you can make polymorphic calls on =
an object and that you can destroy it polymorphically are correlated, but t=
hey are not fundamentally tied together.</div><div><br></div><div>Disallowi=
ng *deletion* of an object of an abstract class type with a non-virtual des=
tructor would make sense as a language rule; indeed,at least one compiler a=
lready warns on that by default.</div><div>=C2=A0</div><blockquote class=3D=
"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding=
-left:1ex"><div dir=3D"ltr"><span id=3D"m_3774939073749314107docs-internal-=
guid-b8359b98-7fff-c7a6-0f1c-9a3ff17a5c04"><span style=3D"font-size:11pt;fo=
nt-family:Arial;color:rgb(0,0,0);background-color:transparent;font-variant-=
numeric:normal;font-variant-east-asian:normal;vertical-align:baseline;white=
-space:pre-wrap">There will be a virtual method table anyway, so why could =
it not be assumed then?</span><p></p><br><p dir=3D"ltr" style=3D"line-heigh=
t:1.38;margin-top:0pt;margin-bottom:0pt"><span style=3D"font-size:11pt;font=
-family:Arial;color:rgb(0,0,0);background-color:transparent;font-variant-nu=
meric:normal;font-variant-east-asian:normal;vertical-align:baseline;white-s=
pace:pre-wrap">I=E2=80=99d propose to make it the default, where you _can_ =
make it nonvirtual if you want to disallow deleting by a pointer explicitly=
..</span></p><p dir=3D"ltr" style=3D"line-height:1.38;margin-top:0pt;margin-=
bottom:0pt"><span style=3D"font-size:11pt;font-family:Arial;color:rgb(0,0,0=
);background-color:transparent;font-variant-numeric:normal;font-variant-eas=
t-asian:normal;vertical-align:baseline;white-space:pre-wrap"><br></span></p=
><p dir=3D"ltr" style=3D"line-height:1.38;margin-top:0pt;margin-bottom:0pt"=
><font color=3D"#000000" face=3D"Arial"><span style=3D"font-size:14.6667px;=
white-space:pre-wrap">PREVIOUSLY POSTED &amp; EDITED: there was an error in=
 the example, and I couldn&#39;t find an edit post button.</span></font></p=
><div><span style=3D"font-size:11pt;font-family:Arial;color:rgb(0,0,0);back=
ground-color:transparent;font-variant-numeric:normal;font-variant-east-asia=
n:normal;vertical-align:baseline;white-space:pre-wrap"><br></span></div></s=
pan></div>

<p></p>

-- <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 e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org" target=3D"_=
blank">std-proposals+unsubscribe@isocpp.org</a>.<br>
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org" target=3D"_blank">std-proposals@isocpp.org</a>.<br>
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/144065d2-ab69-4a75-8544-7236a1850dc3%=
40isocpp.org?utm_medium=3Demail&amp;utm_source=3Dfooter" target=3D"_blank">=
https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/144065d2-ab69-=
4a75-8544-7236a1850dc3%40isocpp.org</a>.<br>
</blockquote></div></div>

<p></p>

-- <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 e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/CAOfiQqnOFwfv_ebt3CeDvF934PEv5F3RLCMj=
ibcHEyn2E1BRjw%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter">htt=
ps://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAOfiQqnOFwfv_ebt=
3CeDvF934PEv5F3RLCMjibcHEyn2E1BRjw%40mail.gmail.com</a>.<br />

--0000000000008cc7bb0577f98d1e--

.


Author: Magnus Fromreide <magfr@lysator.liu.se>
Date: Thu, 11 Oct 2018 23:23:03 +0200
Raw View
On Thu, Oct 11, 2018 at 08:09:45AM -0700, Michael van der Werve wrote:
>=20
>=20
> Currently, you need to *explicitly *specify the destructor as virtual, ev=
en=20
> if all methods are pure virtual.
>=20
> Example which does not work correctly.
> class Base
> {
> public:
>     // should be overridden=20
>     virtual void doSomething() =3D 0;
>=20
>     // define destructor
>     virtual ~Base() =3D default;
> };
>=20
> class Derived : public Base
> {
> public:
>     // override the function
>     virtual void doSomething() override {}
>=20
>     // define the destructor
>     virtual ~Derived()
>     {
>         // do some fancy destructing
>         std::cout << "destructed" << std::endl;
>     }
> };
>=20
> And then running the following code
> // create a derived instance
> Derived *derived =3D new Derived();
>=20
> // cast it to the base
> Base *base =3D derived;
>=20
> // now delete it as the base
> delete base;
>=20
> In the example, the derived class destructor will not be called. It can b=
e=20
> solved by simply altering the base class as such.
> class Base
> {
> public:
>     // should be overridden=20
>     virtual void doSomething() =3D 0;
>=20
>     // add a virtual destructor =20
>     virtual ~Base() =3D default;
> };
>=20
> And naturally, everything works as expected.
>=20
> So let me ask you this, is there any reason that a virtual destructor=20
> should not simply be assumed when the class only has pure virtual=20
> functions? There will be a virtual method table anyway, so why could it n=
ot=20
> be assumed then?
>=20
>=20
> I=E2=80=99d propose to make it the default, where you *can* make it non-v=
irtual by=20
> specifying it explicitly if you want to disallow deleting by a pointer fo=
r=20
> example. Wouldn't that make more sense?

There is also the other reasonable kind of interface:

class fooInterface
{
protected:
 ~fooInterface() =3D default;
public:
 virtual void doFooThing() =3D 0;
};

This one is then passed to a function that needs a class with a fooInterfac=
e
but have no interest in deleting that object.

The destructor of that class might very well be virtual but a consumer of a
fooInterface doesn't care about that at all.

/MF

>=20
> --=20
> 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.
> To view this discussion on the web visit https://groups.google.com/a/isoc=
pp.org/d/msgid/std-proposals/17fe64b2-7c78-492e-814d-fef72e3a668b%40isocpp.=
org.

--=20
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 e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp=
..org/d/msgid/std-proposals/20181011212302.GA18849%40noemi.bahnhof.se.

.


Author: pasa@lib.hu
Date: Thu, 18 Oct 2018 15:45:38 -0700 (PDT)
Raw View
------=_Part_3351_323553904.1539902738126
Content-Type: multipart/alternative;
 boundary="----=_Part_3352_525231504.1539902738126"

------=_Part_3352_525231504.1539902738126
Content-Type: text/plain; charset="UTF-8"

Yes, it would be more logical is the rules worked along the guidelines: if
a class has virtual functions, it should have virtual destructor.

But that ship is gone. We have 30 years of code written with the
"destructor is nonvirtual" rule in mind. I doubt you can provide a good
explanation on why is it good idea to just break everyone's code -- and how
that will be safe.

Yes, writing those virtual dtors at root of hierarchies is PITA. But
fortunately it is then propagated. So overall the situation is rare enough
to meet.

--
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.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/8a394f9d-4be8-4d74-988c-e1eb0a5e252d%40isocpp.org.

------=_Part_3352_525231504.1539902738126
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div>Yes, it would be more logical is the rules worked alo=
ng the guidelines: if a class has virtual functions, it should have virtual=
 destructor. <br></div><div><br></div><div>But that ship is gone. We have 3=
0 years of code written with the &quot;destructor is nonvirtual&quot; rule =
in mind. I doubt you can provide a good explanation on why is it good idea =
to just break everyone&#39;s code -- and how that will be safe. <br></div><=
div><br></div><div>Yes, writing those virtual dtors at root of hierarchies =
is PITA. But fortunately it is then propagated. So overall the situation is=
 rare enough to meet. <br></div></div>

<p></p>

-- <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 e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/8a394f9d-4be8-4d74-988c-e1eb0a5e252d%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/8a394f9d-4be8-4d74-988c-e1eb0a5e252d=
%40isocpp.org</a>.<br />

------=_Part_3352_525231504.1539902738126--

------=_Part_3351_323553904.1539902738126--

.


Author: Richard Hodges <hodges.r@gmail.com>
Date: Fri, 19 Oct 2018 00:14:55 +0100
Raw View
--=-oHDjKloRx2vufqG2PRSZ
Content-Type: multipart/alternative; boundary="=-7WGARWWhllEyL+bLD5Xo"


--=-7WGARWWhllEyL+bLD5Xo
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

On Thu, 2018-10-11 at 08:09 -0700, Michael van der Werve wrote:
> Currently, you need to explicitly specify the destructor as virtual,
> even if all methods are pure virtual.

This is fine when using type-erased destructors, as in the case of
shared_ptr.
example:
std::shared_ptr<Base> test(){    return std::make_shared<Derived>();}
int main(){    test()->doSomething();
    // Derived::~Derived() is called here}
It's worth noting that if you replace shared_ptr with unique_ptr in the
above code, gcc will not warn you of your mistake. It probably should
be mandated in the standard that this is UB, diagnostic absolutely
required.
> Example which does not work correctly.
>=20
> class Base
> {
> public:
>     // should be overridden=20
>     virtual void doSomething() =3D 0;
>=20
>     // define destructor
>     virtual ~Base() =3D default;
> };
>=20
> class Derived : public Base
> {
> public:
>     // override the function
>     virtual void doSomething() override {}
>=20
>     // define the destructor
>     virtual ~Derived()
>     {
>         // do some fancy destructing
>         std::cout << "destructed" << std::endl;
>     }
> };
>=20
> And then running the following code
> // create a derived instance
> Derived *derived =3D new Derived();
>=20
> // cast it to the base
> Base *base =3D derived;
>=20
> // now delete it as the base
> delete base;
>=20
> In the example, the derived class destructor will not be called. It
> can be solved by simply altering the base class as such.
> class Base
> {
> public:
>     // should be overridden=20
>     virtual void doSomething() =3D 0;
>=20
>     // add a virtual destructor =20
>     virtual ~Base() =3D default;
> };
>=20
> And naturally, everything works as expected.
>=20
> So let me ask you this, is there any reason that a virtual destructor
> should not simply be assumed when the class only has pure virtual
> functions? There will be a virtual method table anyway, so why could
> it not be assumed then?
>=20
> I=E2=80=99d propose to make it the default, where you can make it non-vir=
tual=20
> by specifying it explicitly if you want to disallow deleting by a
> pointer for example. Wouldn't that make more sense?
>=20
>=20
>=20
>=20
>=20
>=20
> --=20
>=20
> You received this message because you are subscribed to the Google
> Groups "ISO C++ Standard - Future Proposals" group.
>=20
> To unsubscribe from this group and stop receiving emails from it,
> send an email to std-proposals+unsubscribe@isocpp.org.
>=20
> To post to this group, send email to std-proposals@isocpp.org.
>=20
> To view this discussion on the web visit https://groups.google.com/a/
> isocpp.org/d/msgid/std-proposals/17fe64b2-7c78-492e-814d-
> fef72e3a668b%40isocpp.org.
>=20

--=20
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 e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp=
..org/d/msgid/std-proposals/1539904495.24185.37.camel%40gmail.com.

--=-7WGARWWhllEyL+bLD5Xo
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<html><head></head><body><div>On Thu, 2018-10-11 at 08:09 -0700, Michael va=
n der Werve wrote:</div><blockquote type=3D"cite" style=3D"margin:0 0 0 .8e=
x; border-left:2px #729fcf solid;padding-left:1ex"><div dir=3D"ltr"><span i=
d=3D"docs-internal-guid-9fd84c3f-7fff-0641-74b2-054e7ad336b7"><p dir=3D"ltr=
" style=3D"line-height:1.38;margin-top:0pt;margin-bottom:0pt;"><span style=
=3D"font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-co=
lor: transparent; font-variant-numeric: normal; font-variant-east-asian: no=
rmal; vertical-align: baseline; white-space: pre-wrap;">Currently, you need=
 to <i>explicitly </i>specify the destructor as virtual, even if all method=
s are pure virtual.</span><span style=3D"font-size: 11pt; font-family: Aria=
l; color: rgb(0, 0, 0); background-color: transparent; font-variant-numeric=
: normal; font-variant-east-asian: normal; vertical-align: baseline; white-=
space: pre-wrap;"><br class=3D"kix-line-break"></span></p></span></div></bl=
ockquote><div><br></div><div>This is fine when using type-erased destructor=
s, as in the case of shared_ptr.</div><div><br></div><div>example:</div><di=
v><br></div><div><div style=3D"color: #000000;background-color: #fffffe;fon=
t-family: Consolas, " liberation=3D"" mono",=3D"" courier,=3D"" monospace;f=
ont-weight:=3D"" normal;font-size:=3D"" 18.059231232px;line-height:=3D"" 24=
px;white-space:=3D"" pre;"=3D""><pre>std::shared_ptr&lt;Base&gt; test()</pr=
e><pre>{</pre><pre>    <span style=3D"color: #0000ff;">return</span> std::m=
ake_shared&lt;Derived&gt;();</pre><pre>}</pre><pre><br></pre><pre><span sty=
le=3D"color: #0000ff;">int</span> main()</pre><pre>{</pre><pre>    test()-&=
gt;doSomething();</pre><pre><br></pre><pre>    <span style=3D"color: #00800=
0;">// Derived::~Derived() is called here</span></pre><pre>}</pre><br></div=
></div><div>It's worth noting that if you replace shared_ptr with unique_pt=
r in the above code, gcc will not warn you of your mistake. It probably sho=
uld be mandated in the standard that this is UB, diagnostic absolutely requ=
ired.</div><div><br></div><blockquote type=3D"cite" style=3D"margin:0 0 0 .=
8ex; border-left:2px #729fcf solid;padding-left:1ex"><div dir=3D"ltr"><span=
 id=3D"docs-internal-guid-9fd84c3f-7fff-0641-74b2-054e7ad336b7"><p dir=3D"l=
tr" style=3D"line-height:1.38;margin-top:0pt;margin-bottom:0pt;"><span styl=
e=3D"font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-c=
olor: transparent; font-variant-numeric: normal; font-variant-east-asian: n=
ormal; vertical-align: baseline; white-space: pre-wrap;"><br class=3D"kix-l=
ine-break"></span><span style=3D"font-size: 11pt; font-family: Arial; color=
: rgb(0, 0, 0); background-color: transparent; font-variant-numeric: normal=
; font-variant-east-asian: normal; vertical-align: baseline; white-space: p=
re-wrap;">Example which does not work correctly.</span><span style=3D"font-=
size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: tran=
sparent; font-variant-numeric: normal; font-variant-east-asian: normal; ver=
tical-align: baseline; white-space: pre-wrap;"><br class=3D"kix-line-break"=
></span></p><div class=3D"prettyprint" style=3D"background-color: rgb(250, =
250, 250); border-color: rgb(187, 187, 187); border-style: solid; border-wi=
dth: 1px; overflow-wrap: break-word;"><code class=3D"prettyprint"><div clas=
s=3D"subprettyprint"><span style=3D"color: #008;" class=3D"styled-by-pretti=
fy">class</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> =
</span><span style=3D"color: #606;" class=3D"styled-by-prettify">Base</span=
><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span=
 style=3D"color: #660;" class=3D"styled-by-prettify">{</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"color=
: #008;" class=3D"styled-by-prettify">public</span><span style=3D"color: #6=
60;" class=3D"styled-by-prettify">:</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify"><br>&nbsp; &nbsp; </span><span style=3D"color: #80=
0;" class=3D"styled-by-prettify">// should be overridden </span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp; </span><sp=
an style=3D"color: #008;" class=3D"styled-by-prettify">virtual</span><span =
style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"=
color: #008;" class=3D"styled-by-prettify">void</span><span style=3D"color:=
 #000;" class=3D"styled-by-prettify"> doSomething</span><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify">()</span><span style=3D"color: #000;=
" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">=3D</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"> </span><span style=3D"color: #066;" class=3D"styled-by-pr=
ettify">0</span><span style=3D"color: #660;" class=3D"styled-by-prettify">;=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br><br>&n=
bsp; &nbsp; </span><span style=3D"color: #800;" class=3D"styled-by-prettify=
">// define destructor</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify"><br>&nbsp; &nbsp; </span><span style=3D"color: #008;" class=3D"=
styled-by-prettify">virtual</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">~</span><span style=3D"color: #606;" class=3D"styled-by-prettify">B=
ase</span><span style=3D"color: #660;" class=3D"styled-by-prettify">()</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span s=
tyle=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #=
008;" class=3D"styled-by-prettify">default</span><span style=3D"color: #660=
;" class=3D"styled-by-prettify">;</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"><br></span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">};</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"><br><br></span><span style=3D"color: #008;" class=3D"styled-by-pr=
ettify">class</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y"> </span><span style=3D"color: #606;" class=3D"styled-by-prettify">Derive=
d</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><=
span style=3D"color: #660;" class=3D"styled-by-prettify">:</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"colo=
r: #008;" class=3D"styled-by-prettify">public</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #606;" cla=
ss=3D"styled-by-prettify">Base</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"><br></span><span style=3D"color: #660;" class=3D"styled=
-by-prettify">{</span><span style=3D"color: #000;" class=3D"styled-by-prett=
ify"><br></span><span style=3D"color: #008;" class=3D"styled-by-prettify">p=
ublic</span><span style=3D"color: #660;" class=3D"styled-by-prettify">:</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp; &nb=
sp; </span><span style=3D"color: #800;" class=3D"styled-by-prettify">// ove=
rride the function</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"><br>&nbsp; &nbsp; </span><span style=3D"color: #008;" class=3D"styl=
ed-by-prettify">virtual</span><span style=3D"color: #000;" class=3D"styled-=
by-prettify"> </span><span style=3D"color: #008;" class=3D"styled-by-pretti=
fy">void</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> d=
oSomething</span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
()</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span>=
<span style=3D"color: #008;" class=3D"styled-by-prettify">override</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">{}</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify"><br><br>&nbsp; &nbsp; </span><span s=
tyle=3D"color: #800;" class=3D"styled-by-prettify">// define the destructor=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp;=
 &nbsp; </span><span style=3D"color: #008;" class=3D"styled-by-prettify">vi=
rtual</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </sp=
an><span style=3D"color: #660;" class=3D"styled-by-prettify">~</span><span =
style=3D"color: #606;" class=3D"styled-by-prettify">Derived</span><span sty=
le=3D"color: #660;" class=3D"styled-by-prettify">()</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp; </span><span sty=
le=3D"color: #660;" class=3D"styled-by-prettify">{</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp; &nbsp; &nbsp; </s=
pan><span style=3D"color: #800;" class=3D"styled-by-prettify">// do some fa=
ncy destructing</span><span style=3D"color: #000;" class=3D"styled-by-prett=
ify"><br>&nbsp; &nbsp; &nbsp; &nbsp; std</span><span style=3D"color: #660;"=
 class=3D"styled-by-prettify">::</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify">cout </span><span style=3D"color: #660;" class=3D"s=
tyled-by-prettify">&lt;&lt;</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"> </span><span style=3D"color: #080;" class=3D"styled-by-pr=
ettify">"destructed"</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify"=
>&lt;&lt;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> =
std</span><span style=3D"color: #660;" class=3D"styled-by-prettify">::</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify">endl</span><spa=
n style=3D"color: #660;" class=3D"styled-by-prettify">;</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp; </span><sp=
an style=3D"color: #660;" class=3D"styled-by-prettify">}</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">};</span></div></code></div><span =
style=3D"font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); backgrou=
nd-color: transparent; font-variant-numeric: normal; font-variant-east-asia=
n: normal; vertical-align: baseline; white-space: pre-wrap;"><br class=3D"k=
ix-line-break"></span><span style=3D"font-size: 11pt; font-family: Arial; c=
olor: rgb(0, 0, 0); background-color: transparent; font-variant-numeric: no=
rmal; font-variant-east-asian: normal; vertical-align: baseline; white-spac=
e: pre-wrap;">And then running the following code</span><span style=3D"font=
-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color: tra=
nsparent; font-variant-numeric: normal; font-variant-east-asian: normal; ve=
rtical-align: baseline; white-space: pre-wrap;"><br class=3D"kix-line-break=
"></span><div class=3D"prettyprint" style=3D"background-color: rgb(250, 250=
, 250); border-color: rgb(187, 187, 187); border-style: solid; border-width=
: 1px; overflow-wrap: break-word;"><code class=3D"prettyprint"><div class=
=3D"subprettyprint"><span style=3D"color: #800;" class=3D"styled-by-prettif=
y">// create a derived instance</span><span style=3D"color: #000;" class=3D=
"styled-by-prettify"><br></span><span style=3D"color: #606;" class=3D"style=
d-by-prettify">Derived</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">*</span><span style=3D"color: #000;" class=3D"styled-by-prettify">derive=
d </span><span style=3D"color: #660;" class=3D"styled-by-prettify">=3D</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span s=
tyle=3D"color: #008;" class=3D"styled-by-prettify">new</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #=
606;" class=3D"styled-by-prettify">Derived</span><span style=3D"color: #660=
;" class=3D"styled-by-prettify">();</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify"><br><br></span><span style=3D"color: #800;" class=
=3D"styled-by-prettify">// cast it to the base</span><span style=3D"color: =
#000;" class=3D"styled-by-prettify"><br></span><span style=3D"color: #606;"=
 class=3D"styled-by-prettify">Base</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">*</span><span style=3D"color: #008;" class=3D"styled-by-pret=
tify">base</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
 </span><span style=3D"color: #660;" class=3D"styled-by-prettify">=3D</span=
><span style=3D"color: #000;" class=3D"styled-by-prettify"> derived</span><=
span style=3D"color: #660;" class=3D"styled-by-prettify">;</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"><br><br></span><span style=
=3D"color: #800;" class=3D"styled-by-prettify">// now delete it as the base=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></span=
><span style=3D"color: #008;" class=3D"styled-by-prettify">delete</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=
=3D"color: #008;" class=3D"styled-by-prettify">base</span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">;</span></div></code></div><span s=
tyle=3D"font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); backgroun=
d-color: transparent; font-variant-numeric: normal; font-variant-east-asian=
: normal; vertical-align: baseline; white-space: pre-wrap;"><br class=3D"ki=
x-line-break"></span><span style=3D"font-size: 11pt; font-family: Arial; co=
lor: rgb(0, 0, 0); background-color: transparent; font-variant-numeric: nor=
mal; font-variant-east-asian: normal; vertical-align: baseline; white-space=
: pre-wrap;">In the example, the derived class destructor will not be calle=
d. It can be solved by simply altering the base class as such.</span><span =
style=3D"font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); backgrou=
nd-color: transparent; font-variant-numeric: normal; font-variant-east-asia=
n: normal; vertical-align: baseline; white-space: pre-wrap;"><br class=3D"k=
ix-line-break"></span><div class=3D"prettyprint" style=3D"background-color:=
 rgb(250, 250, 250); border-color: rgb(187, 187, 187); border-style: solid;=
 border-width: 1px; overflow-wrap: break-word;"><code class=3D"prettyprint"=
><div class=3D"subprettyprint"><span style=3D"color: #008;" class=3D"styled=
-by-prettify">class</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"> </span><span style=3D"color: #606;" class=3D"styled-by-prettify">=
Base</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></=
span><span style=3D"color: #660;" class=3D"styled-by-prettify">{</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span styl=
e=3D"color: #008;" class=3D"styled-by-prettify">public</span><span style=3D=
"color: #660;" class=3D"styled-by-prettify">:</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp; </span><span style=3D"=
color: #800;" class=3D"styled-by-prettify">// should be overridden </span><=
span style=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp; =
</span><span style=3D"color: #008;" class=3D"styled-by-prettify">virtual</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span=
 style=3D"color: #008;" class=3D"styled-by-prettify">void</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> doSomething</span><span sty=
le=3D"color: #660;" class=3D"styled-by-prettify">()</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660=
;" class=3D"styled-by-prettify">=3D</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify"> </span><span style=3D"color: #066;" class=3D"styl=
ed-by-prettify">0</span><span style=3D"color: #660;" class=3D"styled-by-pre=
ttify">;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><b=
r><br>&nbsp; &nbsp; </span><span style=3D"color: #800;" class=3D"styled-by-=
prettify">// add a virtual destructor &nbsp;</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp; </span><span style=3D"c=
olor: #008;" class=3D"styled-by-prettify">virtual</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;"=
 class=3D"styled-by-prettify">~</span><span style=3D"color: #606;" class=3D=
"styled-by-prettify">Base</span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">()</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
=3D</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span=
><span style=3D"color: #008;" class=3D"styled-by-prettify">default</span><s=
pan style=3D"color: #660;" class=3D"styled-by-prettify">;</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">};</span></div></code></div><span =
style=3D"font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); backgrou=
nd-color: transparent; font-variant-numeric: normal; font-variant-east-asia=
n: normal; vertical-align: baseline; white-space: pre-wrap;"><br class=3D"k=
ix-line-break"></span><span style=3D"font-size: 11pt; font-family: Arial; c=
olor: rgb(0, 0, 0); background-color: transparent; font-variant-numeric: no=
rmal; font-variant-east-asian: normal; vertical-align: baseline; white-spac=
e: pre-wrap;">And naturally, everything works as expected.</span><span styl=
e=3D"font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-c=
olor: transparent; font-variant-numeric: normal; font-variant-east-asian: n=
ormal; vertical-align: baseline; white-space: pre-wrap;"><br class=3D"kix-l=
ine-break"></span><span style=3D"font-size: 11pt; font-family: Arial; color=
: rgb(0, 0, 0); background-color: transparent; font-variant-numeric: normal=
; font-variant-east-asian: normal; vertical-align: baseline; white-space: p=
re-wrap;"><br class=3D"kix-line-break"></span><span style=3D"font-size: 11p=
t; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; =
font-variant-numeric: normal; font-variant-east-asian: normal; vertical-ali=
gn: baseline; white-space: pre-wrap;">So let me ask you this, is there any =
reason that a virtual destructor should not simply be assumed when the clas=
s only has pure virtual functions? There will be a virtual method table any=
way, so why could it not be assumed then?</span><p></p><br><p dir=3D"ltr" s=
tyle=3D"line-height:1.38;margin-top:0pt;margin-bottom:0pt;"><span style=3D"=
font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); background-color:=
 transparent; font-variant-numeric: normal; font-variant-east-asian: normal=
; vertical-align: baseline; white-space: pre-wrap;">I=E2=80=99d propose to =
make it the default, where you <i>can</i> make it non-virtual by specifying=
 it explicitly if you want to disallow deleting by a pointer for example. W=
ouldn't that make more sense?</span></p><div><span style=3D"font-size: 11pt=
; font-family: Arial; color: rgb(0, 0, 0); background-color: transparent; f=
ont-variant-numeric: normal; font-variant-east-asian: normal; vertical-alig=
n: baseline; white-space: pre-wrap;"><br></span></div></span><div><br></div=
></div>

<p></p>

-- <br>
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.<br>
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br>
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br>
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/17fe64b2-7c78-492e-814d-fef72e3a668b%=
40isocpp.org?utm_medium=3Demail&amp;utm_source=3Dfooter">https://groups.goo=
gle.com/a/isocpp.org/d/msgid/std-proposals/17fe64b2-7c78-492e-814d-fef72e3a=
668b%40isocpp.org</a>.<br>
</blockquote></body></html>

<p></p>

-- <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 e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/1539904495.24185.37.camel%40gmail.com=
?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.com/a/isocpp=
..org/d/msgid/std-proposals/1539904495.24185.37.camel%40gmail.com</a>.<br />

--=-7WGARWWhllEyL+bLD5Xo--

--=-oHDjKloRx2vufqG2PRSZ
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: This is a digitally signed message part
Content-Transfer-Encoding: 7bit

-----BEGIN PGP SIGNATURE-----

iQIzBAABCAAdFiEE3RJb20ryY2ALx0Tw6HZ1IvK3CgsFAlvJE+8ACgkQ6HZ1IvK3
Cgs8Mw/6AgI8chEf85lLmj9URzKpUy9FuHwMd7lvnUDG6g7sslHi2AKXEnPGyXb8
8MB53n87kfOXbjqRlZ47VJo0QdH4gFzGgTvzC36Rq7aHdqXndut/gvNtZW+dNkjj
ugbY12/JgTOoCRwFu0AlNG/yHPEDnThi7y0wv3BARFyE3yAhPFOETkCV49YfPcGb
m4t4mvB8hG+2O56u3ImuA3wSIFFaKQf9TP+mQHFc1VN45N/UqpL59FAjGu4b1FVK
kRqZW/ks9HE7H8j3UaUv5okzMFxEYyhvhe3vk6VsONW2/orcT/mTKTk0l6cJyf1A
lQycIFecpXtaUi+okInVd77w835FQecRlt5HdYyaRyMAUUAFEX01xIYMjJT+djRj
xSSEjlhi920tykz+iEldJaqJnQ1U7j6w7d4EPdMz+qQvcZtnw9sJ/+4qL6rJCqzV
XZP5LFePfpHxrXiRBbw2iPIfNrtgRbBP8yWHIuP+QZ+K1oxIGA94IsIx4pvz2H0j
gYy50gmSCNZpYnYpDSk+zV8NivuTQpegbpJcY0mkfdl3oIv/aOpJ2jGMQP0tvibi
Ty+8trnceI72teY3ydmFdVworhcJwGaglP2SkBPMzXCWrY68f/pyU5VMhQpBbDTg
bLMnfsFlbUUAGjxaVFABq2d821DApPd46cv1dm43ZEgycq9K03M=
=uPMK
-----END PGP SIGNATURE-----

--=-oHDjKloRx2vufqG2PRSZ--


.


Author: Matthew Woehlke <mwoehlke.floss@gmail.com>
Date: Fri, 19 Oct 2018 09:49:34 -0400
Raw View
On 18/10/2018 19.14, Richard Hodges wrote:
> On Thu, 2018-10-11 at 08:09 -0700, Michael van der Werve wrote:
>> Currently, you need to explicitly specify the destructor as
>> virtual, even if all methods are pure virtual.
>
> This is fine when using type-erased destructors, as in the case of
> shared_ptr. example: std::shared_ptr<Base> test(){    return
> std::make_shared<Derived>();} int main(){
> test()->doSomething(); // Derived::~Derived() is called here} It's
> worth noting that if you replace shared_ptr with unique_ptr in the
> above code, gcc will not warn you of your mistake. It probably
> should be mandated in the standard that this is UB, diagnostic
> absolutely required.

Do you mean making the warning suggested by
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=58876 a hard error
instead? (I'd probably go for that...)

--
Matthew

--
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.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/f647a707-21d0-05b0-4b35-6ff4f03d44f1%40gmail.com.

.


Author: Richard Hodges <hodges.r@gmail.com>
Date: Fri, 19 Oct 2018 15:58:02 +0200
Raw View
> On 19 Oct 2018, at 15:49, Matthew Woehlke <mwoehlke.floss@gmail.com> wrot=
e:
>=20
> On 18/10/2018 19.14, Richard Hodges wrote:
>> On Thu, 2018-10-11 at 08:09 -0700, Michael van der Werve wrote:
>>> Currently, you need to explicitly specify the destructor as
>>> virtual, even if all methods are pure virtual.
>>=20
>> This is fine when using type-erased destructors, as in the case of=20
>> shared_ptr. example: std::shared_ptr<Base> test(){    return
>> std::make_shared<Derived>();} int main(){
>> test()->doSomething(); // Derived::~Derived() is called here} It's
>> worth noting that if you replace shared_ptr with unique_ptr in the=20
>> above code, gcc will not warn you of your mistake. It probably
>> should be mandated in the standard that this is UB, diagnostic
>> absolutely required.
>=20
> Do you mean making the warning suggested by
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D58876 a hard error
> instead? (I'd probably go for that=E2=80=A6)

Yes. In my view if UB is at all detectable it should always be a hard error=
, unless the programmer puts in some signal to indicate that the UB is desi=
red (which would be a strong signal that the language is deficient and need=
s a new feature).

>=20
> --=20
> Matthew

--=20
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 e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp=
..org/d/msgid/std-proposals/46DDFD13-DDDC-4376-BF66-FF41F1A79BB1%40gmail.com=
..

.