220 11979 <A777C8A0-3FF9-43D9-AC57-8BA11D10062E@gmail.com> article
Path: news.gmane.org!not-for-mail
From: David Krauss <potswa@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Controversy and debate: Uninitialized variables
 by default is a bug
Date: Mon, 21 Jul 2014 12:21:24 +0800
Lines: 144
Approved: news@gmane.org
Message-ID: <A777C8A0-3FF9-43D9-AC57-8BA11D10062E@gmail.com>
References: <60caa4ef-b32d-40fe-97b6-8918fbb2bd51@isocpp.org> <CAGg_6+Ossg1SPRDSw5qnHR4ZW8NrgT4W8z7uHLAgD7mvfh-wtQ@mail.gmail.com> <ec6e4a5c-c6c9-4921-ac4c-38373fc219ae@isocpp.org> <20140620202026.GA29898@bacon.lysator.liu.se> <0329E32D-0EC2-4BE0-85D0-492A4CF22B0B@gmail.com> <8021febe-7c98-400e-8167-3d6dbb695a12@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0 (Mac OS X Mail 7.3 \(1878.6\))
Content-Type: multipart/alternative; boundary="Apple-Mail=_C2289781-1CE1-44E4-B74F-BAD09E53C120"
X-Trace: ger.gmane.org 1405916503 21844 80.91.229.3 (21 Jul 2014 04:21:43 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Mon, 21 Jul 2014 04:21:43 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBCW25A7E3QCRBTVKWKPAKGQEWO765IY@isocpp.org Mon Jul 21 06:21:36 2014
Return-path: <std-proposals+bncBCW25A7E3QCRBTVKWKPAKGQEWO765IY@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-ie0-f200.google.com ([209.85.223.200])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBCW25A7E3QCRBTVKWKPAKGQEWO765IY@isocpp.org>)
	id 1X956V-00050Y-Sx
	for gclcip-std-proposals@m.gmane.org; Mon, 21 Jul 2014 06:21:36 +0200
Original-Received: by mail-ie0-f200.google.com with SMTP id at20sf56641896iec.3
        for <gclcip-std-proposals@m.gmane.org>; Sun, 20 Jul 2014 21:21:34 -0700 (PDT)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:from:message-id:mime-version:subject:date
         :references:to:in-reply-to:x-original-sender
         :x-original-authentication-results:reply-to:precedence:mailing-list
         :list-id:list-post:list-help:list-archive:list-subscribe
         :list-unsubscribe:content-type;
        bh=tr2ZkQNwIyJmrqewTJ6eUC/QNXOgUZ4UXF2MmZ7ec70=;
        b=ja51MQxrKqmFyOV5a0N/guoZnxINB/UBVG6o83Z6vZs5j0klLRnrsf6KV8RYC5az0x
         HiARAXzwOxIupYLegEqfGbpSfvoBQIz3DfYg0mD6/b3/wahoWBtfXTGyotDGm7DV4VGA
         gYpXVEeM20q3Asos69eb0xT2cET7p/MVizdW6h56bnOIUux5qCZI5+h3REbk4TB2fFnD
         cQYxRJqjDecDJrnzZcw5MjUixvqSfBXYJeQP3Q5o1+h7u2IY05fnTXylcu8/IMUBKWPg
         7pXCX/Cu4keGwBKTJv//jaXgrPm355rJdGDqZTtSrq1+8/A/7I0UUAZVaxUnfbIfjcZt
         6AoA==
X-Gm-Message-State: ALoCoQnY7DgLK/qPz67xWO55T6OwyJ5td0e/mWMQrFz1kAcib4/5F91b5irYxxTirqwRgT53Cgll
X-Received: by 10.50.109.131 with SMTP id hs3mr202936igb.8.1405916494762;
        Sun, 20 Jul 2014 21:21:34 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.50.9.99 with SMTP id y3ls1334937iga.12.gmail; Sun, 20 Jul 2014
 21:21:34 -0700 (PDT)
X-Received: by 10.69.18.11 with SMTP id gi11mr11458979pbd.40.1405916493945;
        Sun, 20 Jul 2014 21:21:33 -0700 (PDT)
Original-Received: from mail-pa0-x22c.google.com (mail-pa0-x22c.google.com [2607:f8b0:400e:c03::22c])
        by mx.google.com with ESMTPS id fy14si6454141pdb.507.2014.07.20.21.21.33
        for <std-proposals@isocpp.org>
        (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128);
        Sun, 20 Jul 2014 21:21:33 -0700 (PDT)
Received-SPF: pass (google.com: domain of potswa@gmail.com designates 2607:f8b0:400e:c03::22c as permitted sender) client-ip=2607:f8b0:400e:c03::22c;
Original-Received: by mail-pa0-f44.google.com with SMTP id eu11so9104027pac.3
        for <std-proposals@isocpp.org>; Sun, 20 Jul 2014 21:21:33 -0700 (PDT)
X-Received: by 10.70.127.163 with SMTP id nh3mr811437pdb.139.1405916493577;
        Sun, 20 Jul 2014 21:21:33 -0700 (PDT)
Original-Received: from [172.20.10.2] ([121.54.54.63])
        by mx.google.com with ESMTPSA id wp3sm12676725pbc.67.2014.07.20.21.21.31
        for <std-proposals@isocpp.org>
        (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128);
        Sun, 20 Jul 2014 21:21:32 -0700 (PDT)
In-Reply-To: <8021febe-7c98-400e-8167-3d6dbb695a12@isocpp.org>
X-Mailer: Apple Mail (2.1878.6)
X-Original-Sender: potswa@gmail.com
X-Original-Authentication-Results: mx.google.com;       spf=pass (google.com:
 domain of potswa@gmail.com designates 2607:f8b0:400e:c03::22c as permitted
 sender) smtp.mail=potswa@gmail.com;       dkim=pass header.i=@gmail.com;
       dmarc=pass (p=NONE dis=NONE) header.from=gmail.com
Precedence: list
Mailing-list: list std-proposals@isocpp.org; contact std-proposals+owners@isocpp.org
List-ID: <std-proposals.isocpp.org>
X-Google-Group-Id: 399137483710
List-Post: <http://groups.google.com/a/isocpp.org/group/std-proposals/post>, <mailto:std-proposals@isocpp.org>
List-Help: <http://support.google.com/a/isocpp.org/bin/topic.py?topic=25838>, <mailto:std-proposals+help@isocpp.org>
List-Archive: <http://groups.google.com/a/isocpp.org/group/std-proposals/>
List-Subscribe: <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>,
 <mailto:std-proposals+subscribe@isocpp.org>
List-Unsubscribe: <mailto:googlegroups-manage+399137483710+unsubscribe@googlegroups.com>,
 <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:11979
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/11979>

--Apple-Mail=_C2289781-1CE1-44E4-B74F-BAD09E53C120
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset=ISO-8859-1


On 2014-07-21, at 12:00 PM, Matthew Fioravante <fmatthew5876@gmail.com> wro=
te:

> Why not just a std::noinit<T> wrapper?
>=20
> std::vector<std::noinit<int>>; //Does not initialize contents on construc=
tion
>=20
> Then the non-initialization is documented and enforced by the type system=
..

Transparent wrappers are a can of worms.

If wrapping isn't needed, then you can already use std::aligned_storage. I =
mentioned this earlier in the thread.

The nice thing about a singular value std::uninitialized is that it's also =
guaranteed to propagate by the type system, but only to its own point of us=
e. And, it can be used for overloading. For classes, it would generally con=
vey the idea of "invalid until assignment or further initialization," and i=
t would be implemented by propagating uninitialized initializers to members=
.. A constructor overloaded on std::uninitialized_t, rather than the default=
 constructor, would be the canonical way to write an ugly partial-initializ=
ation semantic.

> Another option is a simple std::allocator implementation.

That allocator could well be standardized. Here's an implementation I have =
lying around, but I don't think it was ever tested.

template< typename client >
struct default_construct_allocator : std::allocator< client > {
	template< typename rebound, typename arg1, typename ... arg >
	void construct( rebound * p, arg1 && a1, arg && ... a )
		{ ::new ( static_cast< void * >( p ) ) rebound { std::forward< arg1 >( a1=
 ), std::forward< arg >( a ) ... }; }
=09
	template< typename rebound >
	void construct( rebound * p )
		{ ::new ( static_cast< void * >( p ) ) rebound; }
=09
	template< typename rebound >
	struct rebind { typedef default_construct_allocator< rebound > other; };
};

--=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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.

--Apple-Mail=_C2289781-1CE1-44E4-B74F-BAD09E53C120
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html; charset=ISO-8859-1

<html><head><meta http-equiv=3D"Content-Type" content=3D"text/html charset=
=3Dwindows-1252"></head><body style=3D"word-wrap: break-word; -webkit-nbsp-=
mode: space; -webkit-line-break: after-white-space;"><br><div><div>On 2014&=
ndash;07&ndash;21, at 12:00 PM, Matthew Fioravante &lt;<a href=3D"mailto:fm=
atthew5876@gmail.com">fmatthew5876@gmail.com</a>&gt; wrote:</div><br class=
=3D"Apple-interchange-newline"><blockquote type=3D"cite"><div style=3D"font=
-family: Helvetica; font-size: 12px; font-style: normal; font-variant: norm=
al; font-weight: normal; letter-spacing: normal; line-height: normal; orpha=
ns: auto; text-align: start; text-indent: 0px; text-transform: none; white-=
space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: =
0px;"><div dir=3D"ltr">Why not just a std::noinit&lt;T&gt; wrapper?<div><br=
></div><div>std::vector&lt;std::noinit&lt;int&gt;&gt;; //Does not initializ=
e contents on construction</div><div><br></div><div>Then the non-initializa=
tion is documented and enforced by the type system. </div></div></div></blo=
ckquote><div><br></div><div>Transparent wrappers are a can of worms.</div><=
div><br></div><div>If wrapping isn&rsquo;t needed, then you can already use=
 <font face=3D"Courier">std::aligned_storage</font>. I mentioned this earli=
er in the thread.</div><div><br></div><div>The nice thing about a singular =
value&nbsp;<font face=3D"Courier">std::uninitialized</font>&nbsp;is that it=
&rsquo;s also guaranteed to propagate by the type system, but only to its o=
wn point of use. And, it can be used for overloading. For classes, it would=
 generally convey the idea of &ldquo;invalid until assignment or further in=
itialization,&rdquo; and it would be implemented by propagating <font face=
=3D"Courier">uninitialized</font>&nbsp;initializers to members. A construct=
or overloaded on <font face=3D"Courier">std::uninitialized_t</font>, rather=
 than the default constructor, would be the canonical way to write an ugly =
partial-initialization semantic.</div><br><blockquote type=3D"cite"><div st=
yle=3D"font-family: Helvetica; font-size: 12px; font-style: normal; font-va=
riant: normal; font-weight: normal; letter-spacing: normal; line-height: no=
rmal; orphans: auto; text-align: start; text-indent: 0px; text-transform: n=
one; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-str=
oke-width: 0px;"><div dir=3D"ltr"><div>Another option is a simple std::allo=
cator implementation.</div></div></div></blockquote><div><br></div><div>Tha=
t allocator could well be standardized. Here&rsquo;s an implementation I ha=
ve lying around, but I don&rsquo;t think it was ever tested.</div><div><br>=
</div><div><div><font face=3D"Courier">template&lt; typename client &gt;</f=
ont></div><div><font face=3D"Courier">struct default_construct_allocator : =
std::allocator&lt; client &gt; {</font></div><div><font face=3D"Courier"><s=
pan class=3D"Apple-tab-span" style=3D"white-space:pre">	</span>template&lt;=
 typename rebound, typename arg1, typename ... arg &gt;</font></div><div><f=
ont face=3D"Courier"><span class=3D"Apple-tab-span" style=3D"white-space:pr=
e">	</span>void construct( rebound * p, arg1 &amp;&amp; a1, arg &amp;&amp; =
.... a )</font></div><div><font face=3D"Courier"><span class=3D"Apple-tab-sp=
an" style=3D"white-space:pre">		</span>{ ::new ( static_cast&lt; void * &gt=
;( p ) ) rebound { std::forward&lt; arg1 &gt;( a1 ), std::forward&lt; arg &=
gt;( a ) ... }; }</font></div><div><span class=3D"Apple-tab-span" style=3D"=
white-space:pre"><font face=3D"Courier">	</font></span></div><div><font fac=
e=3D"Courier"><span class=3D"Apple-tab-span" style=3D"white-space:pre">	</s=
pan>template&lt; typename rebound &gt;</font></div><div><font face=3D"Couri=
er"><span class=3D"Apple-tab-span" style=3D"white-space:pre">	</span>void c=
onstruct( rebound * p )</font></div><div><font face=3D"Courier"><span class=
=3D"Apple-tab-span" style=3D"white-space:pre">		</span>{ ::new ( static_cas=
t&lt; void * &gt;( p ) ) rebound; }</font></div><div><span class=3D"Apple-t=
ab-span" style=3D"white-space:pre"><font face=3D"Courier">	</font></span></=
div><div><font face=3D"Courier"><span class=3D"Apple-tab-span" style=3D"whi=
te-space:pre">	</span>template&lt; typename rebound &gt;</font></div><div><=
font face=3D"Courier"><span class=3D"Apple-tab-span" style=3D"white-space:p=
re">	</span>struct rebind { typedef default_construct_allocator&lt; rebound=
 &gt; other; };</font></div><div><font face=3D"Courier">};</font></div><div=
><br></div></div></div></body></html>

<p></p>

-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an 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 />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

--Apple-Mail=_C2289781-1CE1-44E4-B74F-BAD09E53C120--

.
