220 10106 <CAOfiQqnHgctE8Wgq3v-aDH-dRoY98Bodgg4n82m3vqLBDo6w7g@mail.gmail.com> article
Path: news.gmane.org!not-for-mail
From: Richard Smith <richard@metafoo.co.uk>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Shouldn't the constexpr variables be treated as
 static by default?
Date: Mon, 31 Mar 2014 00:47:23 -0700
Lines: 137
Approved: news@gmane.org
Message-ID: <CAOfiQqnHgctE8Wgq3v-aDH-dRoY98Bodgg4n82m3vqLBDo6w7g@mail.gmail.com>
References: <21e34045-b833-4468-a39e-dbf177938012@isocpp.org>
	<6838b332-f256-45e7-894b-7cba3593d789@isocpp.org>
	<CA+cyFgspwkCxgc10Gg0ZchetPB2MUfd0z0ji9SNimzpGva5EWQ@mail.gmail.com>
	<4271540.MD85hg9ecn@tjmaciei-mobl4>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/alternative; boundary=089e013a1fcc19d76504f5e243de
X-Trace: ger.gmane.org 1396252052 19115 80.91.229.3 (31 Mar 2014 07:47:32 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Mon, 31 Mar 2014 07:47:32 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBDVNBJG4YAIBBDF34SMQKGQEB3MZROY@isocpp.org Mon Mar 31 09:47:27 2014
Return-path: <std-proposals+bncBDVNBJG4YAIBBDF34SMQKGQEB3MZROY@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-ob0-f200.google.com ([209.85.214.200])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBDVNBJG4YAIBBDF34SMQKGQEB3MZROY@isocpp.org>)
	id 1WUWwI-0003PD-Hc
	for gclcip-std-proposals@m.gmane.org; Mon, 31 Mar 2014 09:47:26 +0200
Original-Received: by mail-ob0-f200.google.com with SMTP id gq1sf27739669obb.7
        for <gclcip-std-proposals@m.gmane.org>; Mon, 31 Mar 2014 00:47:25 -0700 (PDT)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:mime-version:sender:in-reply-to:references:date
         :message-id:subject:from: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=fMJqlUgGR7C9SHFgBUFuSL40fWHO314MZ9UGpg/u2do=;
        b=QyQmgX51T3rUfrpGzSIto7AK0JGphRgPKGnsLILbgslAmJDfewFNQq6tJ50CHORDB+
         fEngk1Mo6iwXAdBPWxPpijBiMiqPceKmm70QTh7m6Yf9ZptF1Yg7bXYTUkz/pYw+UdtE
         dpm0eOI3jdpq49RhXWQCBjRPKQQHJ92rIxgoW7INVpK6+ixYefQCTI/S8NkS5o54cMK/
         BqByDnBKL9D96lSBNnRAkglctR0vhY4wVomJBYf4HChtCwah4Hnoz1Tmsr7/BnWL1i+N
         rASSVEN785/9PoKzYvtx7afZJzqW9mBCkRhXoNJqJT0V2xUvGYOCnS3FtmdEYaFNXmk8
         x6Tg==
X-Gm-Message-State: ALoCoQlDjopI2LAbgLvGYzG7l6i7Fc5auCwR9a6n/wb53mvs/Ch4LW/9EjvE1r+EcOTny2zcgy5I
X-Received: by 10.43.161.202 with SMTP id mh10mr7742765icc.23.1396252045069;
        Mon, 31 Mar 2014 00:47:25 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.140.90.80 with SMTP id w74ls2229488qgd.95.gmail; Mon, 31 Mar
 2014 00:47:24 -0700 (PDT)
X-Received: by 10.52.128.231 with SMTP id nr7mr18516664vdb.17.1396252044417;
        Mon, 31 Mar 2014 00:47:24 -0700 (PDT)
Original-Received: from mail-vc0-x22a.google.com (mail-vc0-x22a.google.com [2607:f8b0:400c:c03::22a])
        by mx.google.com with ESMTPS id tz5si2833057vdc.133.2014.03.31.00.47.24
        for <std-proposals@isocpp.org>
        (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128);
        Mon, 31 Mar 2014 00:47:24 -0700 (PDT)
Received-SPF: pass (google.com: domain of metafoo@gmail.com designates 2607:f8b0:400c:c03::22a as permitted sender) client-ip=2607:f8b0:400c:c03::22a;
Original-Received: by mail-vc0-f170.google.com with SMTP id hu19so8164797vcb.29
        for <std-proposals@isocpp.org>; Mon, 31 Mar 2014 00:47:24 -0700 (PDT)
X-Received: by 10.52.191.100 with SMTP id gx4mr18635584vdc.4.1396252044021;
 Mon, 31 Mar 2014 00:47:24 -0700 (PDT)
Original-Sender: metafoo@gmail.com
Original-Received: by 10.221.12.203 with HTTP; Mon, 31 Mar 2014 00:47:23 -0700 (PDT)
In-Reply-To: <4271540.MD85hg9ecn@tjmaciei-mobl4>
X-Original-Sender: richard@metafoo.co.uk
X-Original-Authentication-Results: mx.google.com;       spf=pass (google.com:
 domain of metafoo@gmail.com designates 2607:f8b0:400c:c03::22a as permitted
 sender) smtp.mail=metafoo@gmail.com;       dkim=pass header.i=@gmail.com
Precedence: list
Mailing-list: list std-proposals@isocpp.org; contact std-proposals+owners@isocpp.org
List-ID: <std-proposals.isocpp.org>
X-Google-Group-Id: 399137483710
List-Post: <http://groups.google.com/a/isocpp.org/group/std-proposals/post>, <mailto:std-proposals@isocpp.org>
List-Help: <http://support.google.com/a/isocpp.org/bin/topic.py?topic=25838>, <mailto:std-proposals+help@isocpp.org>
List-Archive: <http://groups.google.com/a/isocpp.org/group/std-proposals/>
List-Subscribe: <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>,
 <mailto:std-proposals+subscribe@isocpp.org>
List-Unsubscribe: <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>,
 <mailto:googlegroups-manage+399137483710+unsubscribe@googlegroups.com>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:10106
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/10106>

--089e013a1fcc19d76504f5e243de
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

On Sun, Mar 30, 2014 at 11:27 PM, Thiago Macieira <thiago@macieira.org>wrot=
e:

> Em dom 30 mar 2014, =E0s 22:18:43, Geoffrey Romer escreveu:
> > Ah, I hadn't noticed the addresses were varying in the static example. =
I
> > grant that this could theoretically be a breaking change, but how much
> real
> > code would be broken? The kinds of things you'd have to do to notice th=
e
> > difference seem like things that you'd normally never do with a constex=
pr
> > variable.
>
> I'd say that for anyone who caused the address to be taken, they really
> want
> the current behaviour. So it will break a lot of code.
>

Can you point to any code it would break? I'm having a hard time seeing why
you would ever want an automatic storage duration constexpr variable.


> What's the benefit you were looking for?


It'd fix this weirdness:

void f() {
  constexpr auto x =3D { 1, 2, 3 }; // ill-formed
  static constexpr auto y =3D { 1, 2, 3 }; // ok

  // or more obviously...
  constexpr auto &&a =3D 1; // ill-formed
  static constexpr auto &&b =3D 1; // ok
}

The problem in these cases is that a temporary is lifetime-extended to the
lifetime of the variable (an array temporary in the first cases, and an int
temporary in the last cases), and a constexpr reference can't bind to an
automatic storage duration object.

It'd also remove the unnecessary stack usage in common cases like:

void g(const char*);
void h() {
  constexpr char foo[] =3D "some string literal goes here";
  g(foo);
}

Under the current language rules, the compiler is *required* to allocate
stack space and copy that string literal onto the stack each time through
this function (assuming it can't see the definition of 'g').

--=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/.

--089e013a1fcc19d76504f5e243de
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div class=3D"gmail_extra"><div class=3D"gmail_quote">On S=
un, Mar 30, 2014 at 11:27 PM, Thiago Macieira <span dir=3D"ltr">&lt;<a href=
=3D"mailto:thiago@macieira.org" target=3D"_blank">thiago@macieira.org</a>&g=
t;</span> wrote:<br>
<blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p=
x #ccc solid;padding-left:1ex">Em dom 30 mar 2014, =E0s 22:18:43, Geoffrey =
Romer escreveu:<br>
<div class=3D"">&gt; Ah, I hadn&#39;t noticed the addresses were varying in=
 the static example. I<br>
&gt; grant that this could theoretically be a breaking change, but how much=
 real<br>
&gt; code would be broken? The kinds of things you&#39;d have to do to noti=
ce the<br>
&gt; difference seem like things that you&#39;d normally never do with a co=
nstexpr<br>
&gt; variable.<br>
<br>
</div>I&#39;d say that for anyone who caused the address to be taken, they =
really want<br>
the current behaviour. So it will break a lot of code.<br></blockquote><div=
><br></div><div>Can you point to any code it would break? I&#39;m having a =
hard time seeing why you would ever want an automatic storage duration cons=
texpr variable.</div>
<div>=A0</div><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;=
border-left:1px #ccc solid;padding-left:1ex">
What&#39;s the benefit you were looking for?</blockquote><div><br></div><di=
v>It&#39;d fix this weirdness:</div><div><br></div><div>void f() {<br></div=
><div>=A0 constexpr auto x =3D { 1, 2, 3 }; // ill-formed</div><div>=A0 sta=
tic constexpr auto y =3D { 1, 2, 3 }; // ok</div>
<div><br></div><div>=A0 // or more obviously...</div><div>=A0 constexpr aut=
o &amp;&amp;a =3D 1; // ill-formed</div><div>=A0 static constexpr auto &amp=
;&amp;b =3D 1; // ok</div><div>}</div><div><br></div><div>The problem in th=
ese cases is that a temporary is lifetime-extended to the lifetime of the v=
ariable (an array temporary in the first cases, and an int temporary in the=
 last cases), and a constexpr reference can&#39;t bind to an automatic stor=
age duration object.</div>
<div><br></div><div>It&#39;d also remove the unnecessary stack usage in com=
mon cases like:</div><div><br></div><div>void g(const char*);</div><div>voi=
d h() {</div><div>=A0 constexpr char foo[] =3D &quot;some string literal go=
es here&quot;;</div>
<div>=A0 g(foo);</div><div>}</div><div><br></div><div>Under the current lan=
guage rules, the compiler is *required* to allocate stack space and copy th=
at string literal onto the stack each time through this function (assuming =
it can&#39;t see the definition of &#39;g&#39;).</div>
</div></div></div>

<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 />

--089e013a1fcc19d76504f5e243de--

.
