220 25075 <5db50906-b180-475d-9f4d-7453897be2b0@isocpp.org> article
Path: news.gmane.org!not-for-mail
From: Arthur O'Dwyer <arthur.j.odwyer@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: new auto
Date: Tue, 8 Mar 2016 19:16:01 -0800 (PST)
Lines: 156
Approved: news@gmane.org
Message-ID: <5db50906-b180-475d-9f4d-7453897be2b0@isocpp.org>
References: <d98f26dc-e801-4e74-bcbc-7e085986de63@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/mixed; 
	boundary="----=_Part_3535_914147474.1457493361379"
X-Trace: ger.gmane.org 1457493379 19674 80.91.229.3 (9 Mar 2016 03:16:19 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Wed, 9 Mar 2016 03:16:19 +0000 (UTC)
To: ISO C++ Standard - Future Proposals <std-proposals@isocpp.org>
Original-X-From: std-proposals+bncBDLZJYWNDQIPFKX6WYCRUBB3XYVMG@isocpp.org Wed Mar 09 04:16:05 2016
Return-path: <std-proposals+bncBDLZJYWNDQIPFKX6WYCRUBB3XYVMG@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-ig0-f200.google.com ([209.85.213.200])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBDLZJYWNDQIPFKX6WYCRUBB3XYVMG@isocpp.org>)
	id 1adUbU-0002Yq-Bd
	for gclcip-std-proposals@m.gmane.org; Wed, 09 Mar 2016 04:16:04 +0100
Original-Received: by mail-ig0-f200.google.com with SMTP id rx16sf50164004igc.3
        for <gclcip-std-proposals@m.gmane.org>; Tue, 08 Mar 2016 19:16:03 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=isocpp-org.20150623.gappssmtp.com; s=20150623;
        h=date:from:to:message-id:in-reply-to:references:subject:mime-version
         :x-original-sender:reply-to:precedence:mailing-list:list-id
         :x-spam-checked-in-group:list-post:list-help:list-archive:sender
         :list-subscribe:list-unsubscribe;
        bh=TVYd8RGsOuvBMejvfv4jzrgil25Aksw8li66NztvtwQ=;
        b=J/ZopfrTBdHPwerHwHnIMDyauf35J2/961upmws0/v215wkat+ZQoUsougxW8peORH
         6txtJMhuuBPJQnVzGE6SkzHdw3D+gs1p/uKomDkSeLvZqlG2yGRT5XnF2uh0QYTBwDnt
         7oD2YS9UXkSBf+5zXX7YXYShrS4u/BZdgyyH5UIxexJIGbie+y0Mgz7OzFfMI0MBcD+B
         jZUKxd9Qa296BdnRq/BBIM/0xbVEMUsjkQFmQHe3wWMPKunMkDvege4QyShmy/dZex1Y
         MZ1qgXxaV3hs9sqo+20I64NgqUvD2pyU+ok9Be458MQsQUwQbqUp7qn8ZlutBRBghOzy
         Salw==
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20120113;
        h=date:from:to:message-id:in-reply-to:references:subject:mime-version
         :x-original-sender:reply-to:precedence:mailing-list:list-id
         :x-spam-checked-in-group:list-post:list-help:list-archive:sender
         :list-subscribe:list-unsubscribe;
        bh=TVYd8RGsOuvBMejvfv4jzrgil25Aksw8li66NztvtwQ=;
        b=l+q2iRevIvZAxDbOYxXdi/7TENrxMGNV5C4RiRkG82NBe+QBVugq0pSw6XZkcIjPLr
         4/BjD0fW20eS5/zfBnZvvIWHGCi3pIn78op6H2biI8h6mHMU8Bg8avBdaQ3F4Z5lsaUq
         c5mIPhzqnhq1JaGLKPAgrxC/AQDLDH6/wqAtEarHMJ79MyEplhMUkCls599XMiNDr7Ks
         tXJeie7N+JnyLHwSjKBpvD5TC3K9GoeAKy1R94SdaKma2HPLIbAzpqn40P0RXpLZjL8S
         woqkWzwCopfl02mpYJgvK3kZu2cStt7kjcOK4KFbkOXqN99ofriiNoN5OOhF8j0BOGib
         IUZA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:date:from:to:message-id:in-reply-to:references
         :subject:mime-version:x-original-sender:reply-to:precedence
         :mailing-list:list-id:x-spam-checked-in-group:list-post:list-help
         :list-archive:sender:list-subscribe:list-unsubscribe;
        bh=TVYd8RGsOuvBMejvfv4jzrgil25Aksw8li66NztvtwQ=;
        b=BhxNw5h9Ha8jVhYk+xrIKMMlOqFqBdWOjcepixbrw3PzR7xz5oruG5Zll9mNhvi7Y8
         sChz/3euMC9N3PrHMdYzwbkMg9MWCWAZ1lAONVv6ivsFen3aVOFM1wuX91yH0vR66toc
         MlUV4MuM/rgQkMK2sOQrSz+pD+SgXBnhjdoMCEniOZ+/hF4PBX98u4yTIC2znO8pAePD
         u7XGVK+BD/Y654pwysarv7bJht7U0iMNP7wsRNNrOW8/xChNkFKgFiiLlsqwo7dECrRY
         jLACsUfmSBpynTdegxy67ULJPPbF5BuCW4YvKBM959AdXtzq4hCdnncpCmeFAYn9eg3n
         yv9g==
X-Gm-Message-State: AD7BkJLOjX53C5sh20pRlO8ddqTmXxQYIZpbwa3qhjdghoyYiNynzYCk9IDhmRqK/5/pbg==
X-Received: by 10.182.65.135 with SMTP id x7mr24392319obs.13.1457493363370;
        Tue, 08 Mar 2016 19:16:03 -0800 (PST)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.107.164.38 with SMTP id n38ls242240ioe.80.gmail; Tue, 08 Mar
 2016 19:16:02 -0800 (PST)
X-Received: by 10.50.142.39 with SMTP id rt7mr423862igb.8.1457493362071;
        Tue, 08 Mar 2016 19:16:02 -0800 (PST)
In-Reply-To: <d98f26dc-e801-4e74-bcbc-7e085986de63@isocpp.org>
X-Original-Sender: arthur.j.odwyer@gmail.com
Precedence: list
Mailing-list: list std-proposals@isocpp.org; contact std-proposals+owners@isocpp.org
List-ID: <std-proposals.isocpp.org>
X-Spam-Checked-In-Group: std-proposals@isocpp.org
X-Google-Group-Id: 399137483710
List-Post: <https://groups.google.com/a/isocpp.org/group/std-proposals/post>, <mailto:std-proposals@isocpp.org>
List-Help: <https://support.google.com/a/isocpp.org/bin/topic.py?topic=25838>, <mailto:std-proposals+help@isocpp.org>
List-Archive: <https://groups.google.com/a/isocpp.org/group/std-proposals/>
Original-Sender: std-proposals@isocpp.org
List-Subscribe: <https://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>,
 <mailto:std-proposals+subscribe@isocpp.org>
List-Unsubscribe: <mailto:googlegroups-manage+399137483710+unsubscribe@googlegroups.com>,
 <https://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:25075
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/25075>

------=_Part_3535_914147474.1457493361379
Content-Type: multipart/alternative; 
	boundary="----=_Part_3536_1831975150.1457493361379"

------=_Part_3536_1831975150.1457493361379
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

On Tuesday, March 8, 2016 at 10:34:05 AM UTC-8, Dale Weiler wrote:
>
> Exibit
> class A {
>   A();
>   T *a;
> };
>
>
> Need to know type of *a* here to call new correctly:
>  A::A() : a(new T) { }
>
> Imagine the class member type changes but implementing code stays the
> same, thus it allocates an incorrect amount of memory for the object and
> calls the wrong constructor. How do we solve this?=20
> A::A() : a (new typename remove_reference<decltype(A::a)>::type) { }
>
>
Now, now, it's not that bad.

A::A() : a(new std::remove_reference_t<decltype(*a)>) {}

Anyway, you can't have the type of auto in new auto depend on the *context=
=20
in which it's called*. That way lies Perl, and std::initializer_list, and=
=20
various other madnesses.

The "best practices" answer in this context is almost certainly *don't use=
=20
naked new.* Use owning smart pointers, or don't use pointers at all, and=20
then you don't need to use new, and then all your problems related to new's=
=20
weird syntax pretty much go away.

my $.02,
=E2=80=93Arthur

--=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/5db50906-b180-475d-9f4d-7453897be2b0%40isocpp.or=
g.

------=_Part_3536_1831975150.1457493361379
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">On Tuesday, March 8, 2016 at 10:34:05 AM UTC-8, Dale Weile=
r wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0=
..8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><pre><font size=3D"6">=
Exibit</font><br>
<div style=3D"background-color:rgb(250,250,250);border-color:rgb(187,187,18=
7);border-style:solid;border-width:1px;word-wrap:break-word"><code><div><sp=
an style=3D"color:#008">class</span><span style=3D"color:#000"> A </span><s=
pan style=3D"color:#660">{</span><span style=3D"color:#000"><br>=C2=A0 A</s=
pan><span style=3D"color:#660">();</span><span style=3D"color:#000"><br>=C2=
=A0 T </span><span style=3D"color:#660">*</span><span style=3D"color:#000">=
a</span><span style=3D"color:#660">;</span><span style=3D"color:#000"><br><=
/span><span style=3D"color:#660">};</span></div></code></div>

Need to know type of <b>a</b> here to call new correctly:
<div style=3D"background-color:rgb(250,250,250);border-color:rgb(187,187,18=
7);border-style:solid;border-width:1px;word-wrap:break-word"><code><div><sp=
an style=3D"color:#000">=C2=A0A</span><span style=3D"color:#660">::</span><=
span style=3D"color:#000">A</span><span style=3D"color:#660">()</span><span=
 style=3D"color:#000"> </span><span style=3D"color:#660">:</span><span styl=
e=3D"color:#000"> a</span><span style=3D"color:#660">(</span><span style=3D=
"color:#008">new</span><span style=3D"color:#000"> T</span><span style=3D"c=
olor:#660">)</span><span style=3D"color:#000"> </span><span style=3D"color:=
#660">{</span><span style=3D"color:#000"> </span><span style=3D"color:#660"=
>}</span></div></code></div>
Imagine the class member type changes but implementing code stays the
same, thus it allocates an incorrect amount of memory for the object and
calls the wrong constructor. How do we solve this? <br><div style=3D"backgr=
ound-color:rgb(250,250,250);border-color:rgb(187,187,187);border-style:soli=
d;border-width:1px;word-wrap:break-word"><code><div><span style=3D"color:#0=
00">A</span><span style=3D"color:#660">::</span><span style=3D"color:#000">=
A</span><span style=3D"color:#660">()</span><span style=3D"color:#000"> </s=
pan><span style=3D"color:#660">:</span><span style=3D"color:#000"> a </span=
><span style=3D"color:#660">(</span><span style=3D"color:#008">new</span><s=
pan style=3D"color:#000"> </span><span style=3D"color:#008">typename</span>=
<span style=3D"color:#000"> remove_reference</span><span style=3D"color:#66=
0">&lt;</span><span style=3D"color:#008">decltype</span><span style=3D"colo=
r:#660">(</span><span style=3D"color:#000">A</span><span style=3D"color:#66=
0">::</span><span style=3D"color:#000">a</span><span style=3D"color:#660"><=
wbr>)&gt;::</span><span style=3D"color:#000">type</span><span style=3D"colo=
r:#660">)</span><span style=3D"color:#000"> </span><span style=3D"color:#66=
0">{</span><span style=3D"color:#000"> </span><span style=3D"color:#660">}<=
/span></div></code></div></pre></blockquote><div><br></div><div>Now, now, i=
t&#39;s not that bad.</div><div><br></div><div class=3D"prettyprint" style=
=3D"background-color: rgb(250, 250, 250); border: 1px solid rgb(187, 187, 1=
87); word-wrap: break-word;"><code class=3D"prettyprint"><div class=3D"subp=
rettyprint"><span style=3D"color: #000;" class=3D"styled-by-prettify">A</sp=
an><span style=3D"color: #660;" class=3D"styled-by-prettify">::</span><span=
 style=3D"color: #000;" class=3D"styled-by-prettify">A</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;" cl=
ass=3D"styled-by-prettify">:</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"> a</span><span style=3D"color: #660;" class=3D"styled-by-=
prettify">(</span><span style=3D"color: #008;" class=3D"styled-by-prettify"=
>new</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> std</=
span><span style=3D"color: #660;" class=3D"styled-by-prettify">::</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify">remove_reference_t</=
span><span style=3D"color: #660;" class=3D"styled-by-prettify">&lt;</span><=
span style=3D"color: #008;" class=3D"styled-by-prettify">decltype</span><sp=
an style=3D"color: #660;" class=3D"styled-by-prettify">(*</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify">a</span><span style=3D"color=
: #660;" class=3D"styled-by-prettify">)&gt;)</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">{}</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"><br></span></div></code></div><div><br></div><div>Anyway, =
you can&#39;t have the type of <font face=3D"courier new, monospace">auto</=
font> in <font face=3D"courier new, monospace">new auto</font> depend on th=
e <i><b>context in which it&#39;s called</b></i>. That way lies Perl, and <=
font face=3D"courier new, monospace">std::initializer_list</font>, and vari=
ous other madnesses.</div><div><br></div><div>The &quot;best practices&quot=
; answer in this context is almost certainly <b><i>don&#39;t use naked <fon=
t face=3D"courier new, monospace">new</font>.</i></b> Use owning smart poin=
ters, or don&#39;t use pointers at all, and then you don&#39;t need to use =
<font face=3D"courier new, monospace">new</font>, and then all your problem=
s related to <font face=3D"courier new, monospace">new</font>&#39;s weird s=
yntax pretty much go away.</div><div><br></div><div>my $.02,</div><div>=E2=
=80=93Arthur</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/5db50906-b180-475d-9f4d-7453897be2b0%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/5db50906-b180-475d-9f4d-7453897be2b0=
%40isocpp.org</a>.<br />

------=_Part_3536_1831975150.1457493361379--
------=_Part_3535_914147474.1457493361379--

.
