220 17088 <CAOfgUPhhv0OuN7XMHDfz8peq8j-Ft1W7GwOxoT=caq1jenLayg@mail.gmail.com> article
Path: news.gmane.org!not-for-mail
From: Cassio Neri <cassio.neri@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: [c++std-ext-16626] Re: virtual constexpr fields
Date: Wed, 18 Mar 2015 22:03:47 +0000
Lines: 393
Approved: news@gmane.org
Message-ID: <CAOfgUPhhv0OuN7XMHDfz8peq8j-Ft1W7GwOxoT=caq1jenLayg@mail.gmail.com>
References: <532355906.19321.1426710347371.JavaMail.yahoo@mail.yahoo.com>
	<DM2PR0301MB0911105FCB640A60230A94E2B0000@DM2PR0301MB0911.namprd03.prod.outlook.com>
	<11B5438424E807459A28BD01C92339BA759E907C@XMB122CNC.rim.net>
	<CANTur_7HiZ2eHTTaSq-4XReOhCx-zHE_SBuXW5Ga3zaBGH85BQ@mail.gmail.com>
	<5509F174.7000303@stroustrup.com>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/alternative; boundary=f46d044289e8f7688d0511974192
X-Trace: ger.gmane.org 1426716236 7034 80.91.229.3 (18 Mar 2015 22:03:56 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Wed, 18 Mar 2015 22:03:56 +0000 (UTC)
Cc: Tony Van Eerd <tvaneerd@blackberry.com>, 
	"std-proposals@isocpp.org" <std-proposals@isocpp.org>
To: c++std-ext@accu.org
Original-X-From: std-proposals+bncBDEYBBEU2UGBBRHMU6UAKGQEQPDTYZY@isocpp.org Wed Mar 18 23:03:50 2015
Return-path: <std-proposals+bncBDEYBBEU2UGBBRHMU6UAKGQEQPDTYZY@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-we0-f198.google.com ([74.125.82.198])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBDEYBBEU2UGBBRHMU6UAKGQEQPDTYZY@isocpp.org>)
	id 1YYM45-0000ER-R0
	for gclcip-std-proposals@m.gmane.org; Wed, 18 Mar 2015 23:03:49 +0100
Original-Received: by wesk11 with SMTP id k11sf4833963wes.3
        for <gclcip-std-proposals@m.gmane.org>; Wed, 18 Mar 2015 15:03:49 -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:reply-to:in-reply-to:references
         :date:message-id:subject:from:to:cc:content-type:x-original-sender
         :x-original-authentication-results:precedence:mailing-list:list-id
         :list-post:list-help:list-archive:list-subscribe:list-unsubscribe;
        bh=BX7Z4Ie1WoekR0tlf3HN3Xk8DRaE+2KCC1tH1oCOF9c=;
        b=QLdQUEwBr52hbbLE3d4N7L8zvK+sDZC58XYbPc4ddynDCWK5GCFeibZWsj3kWo0cK1
         NB2FHeMVUukefFNDf+FKV23WQrbHl4CWj8NfhQxrA4fGWLe7UMJW5Pp6qCDqdoS1UTYv
         qbNvTS0lO5oaNvB75sJbYD/IJy7HRlMDKP1glowEoDz07Y81YV/5HyPr3ON2W2jSZFeQ
         Jofv4ISSKTzdl0cEG2nLZVV5ywhYXXiAREVna6BQFp6TBBxhkvM4+seFJT9ghohMoiwj
         q4y5kZJ50NeFSjL2AUgPSERFQNmP2jNog4czD+dDnJNu1z4/PXWq17aDwbkQDJqMy4FN
         xNPw==
X-Gm-Message-State: ALoCoQkyF+6S/Mcx0gVOOKNWdxE8y0+MHPrGoEUiEdUq1fdjHdbAApmIe1yx6hAaEY/V5udsgVfM
X-Received: by 10.180.211.199 with SMTP id ne7mr1171260wic.5.1426716229265;
        Wed, 18 Mar 2015 15:03:49 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.180.87.233 with SMTP id bb9ls432770wib.29.gmail; Wed, 18 Mar
 2015 15:03:48 -0700 (PDT)
X-Received: by 10.180.76.4 with SMTP id g4mr10668468wiw.43.1426716228245;
        Wed, 18 Mar 2015 15:03:48 -0700 (PDT)
Original-Received: from mail-wg0-x22e.google.com (mail-wg0-x22e.google.com. [2a00:1450:400c:c00::22e])
        by mx.google.com with ESMTPS id it3si5949213wid.46.2015.03.18.15.03.48
        for <std-proposals@isocpp.org>
        (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
        Wed, 18 Mar 2015 15:03:48 -0700 (PDT)
Received-SPF: pass (google.com: domain of cassio.neri@gmail.com designates 2a00:1450:400c:c00::22e as permitted sender) client-ip=2a00:1450:400c:c00::22e;
Original-Received: by wgdm6 with SMTP id m6so46789412wgd.2
        for <std-proposals@isocpp.org>; Wed, 18 Mar 2015 15:03:48 -0700 (PDT)
X-Received: by 10.180.80.199 with SMTP id t7mr11038800wix.52.1426716228018;
 Wed, 18 Mar 2015 15:03:48 -0700 (PDT)
Original-Received: by 10.27.91.2 with HTTP; Wed, 18 Mar 2015 15:03:47 -0700 (PDT)
Original-Received: by 10.27.91.2 with HTTP; Wed, 18 Mar 2015 15:03:47 -0700 (PDT)
In-Reply-To: <5509F174.7000303@stroustrup.com>
X-Original-Sender: cassio.neri@gmail.com
X-Original-Authentication-Results: mx.google.com;       spf=pass (google.com:
 domain of cassio.neri@gmail.com designates 2a00:1450:400c:c00::22e as
 permitted sender) smtp.mail=cassio.neri@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:17088
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/17088>

--f46d044289e8f7688d0511974192
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

See

https://groups.google.com/a/isocpp.org/forum/?nomobile=3Dtrue#!searchin/std=
-proposals/virtual$20data$20members/std-proposals/Z1QG_3Mrn0Y/lzrwNxDeKUQJ

If the link doesn't work search for "virtual data members" in future
proposals.

Cassio.
On 18 Mar 2015 21:46, "Bjarne Stroustrup" <bjarne@stroustrup.com> wrote:

>  (1) yes it should be immutable
> (2) I described something like that in D&E (and maybe even in the ARM)
> (3) what's the important use case?
>
> On 3/18/2015 4:57 PM, Ehsan Akhgari wrote:
>
>  On Wed, Mar 18, 2015 at 4:52 PM, Tony Van Eerd <tvaneerd@blackberry.com>
> wrote:
>
>>  I would say it needs to be constexpr or static =E2=80=93 at least for i=
t to be
>> stored in the vtable.
>>
>> (ie assuming the vtable is shared by all instances of the class means
>> that the value is shared by all instances of the class)
>>
>
>  Yes, exactly.  Note that from a pragmatic standpoint, it's probably
> important for compilers to be able to store the vtable in read-only memor=
y
> in order to protect against security attacks attempting to overwrite vtab=
le
> entries at runtime.
>
>
>>
>>
>> *From:* Gabriel Dos Reis [mailto:gdr@microsoft.com]
>> *Sent:* Wednesday, March 18, 2015 4:42 PM
>> *To:* 'std-proposals@isocpp.org'; C++std-ext; ehsan@mozilla.com
>> *Subject:* [c++std-ext-16622] Re: [std-proposals] virtual constexpr
>> fields
>>
>>
>>
>> Does the non-static data member need to be constexpr if it is virtual?
>> Why?
>>
>>
>>
>> -- Gaby
>>
>>
>>
>> *From:* 'Botond Ballo' via ISO C++ Standard - Future Proposals [
>> mailto:std-proposals@isocpp.org <std-proposals@isocpp.org>]
>> *Sent:* Wednesday, March 18, 2015 1:26 PM
>> *To:* C++std-ext; ehsan@mozilla.com; std-proposals@isocpp.org
>> *Subject:* [std-proposals] virtual constexpr fields
>>
>>
>>
>> There are cases where you would like to associate constants with a given
>> type. Here is how you can currently do it in C++:
>>
>> struct Merchandise {
>>     virtual int price() { return 0; }
>> };
>>
>> struct Shoe : Merchandise {
>>     virtual int price() { return 10;
>> }
>>
>> If you could do it this way instead:
>>
>> struct Merchandise {
>>     virtual constexpr int price =3D 0;
>> };
>>
>> struct Shoe : Merchandise {
>>     virtual constexpr int price =3D 10;
>> }
>>
>> then the compiler could store the constant value directly in the vtable.
>> This would eliminate the double indirection involved in dereferencing a
>> function vtable entry, the cost of running that function at runtime, and
>> the code size of the function in the compiled binary.
>>
>> Virtual fields would be limited to being constexpr, so that the value to
>> be placed in the vtable, like other values in the vtable, can be determi=
ned
>> at compile time.
>>
>> Has this, or something similar, ever been proposed? Is there any interes=
t
>> in it?
>>
>> -- Botond and Ehsan
>>
>>
>>
>> --
>>
>> ---
>> You received this message because you are subscribed to the Google Group=
s
>> "ISO C++ Standard - Future Proposals" group.
>> To unsubscribe from this group and stop receiving emails from it, send a=
n
>> email to std-proposals+unsubscribe@isocpp.org.
>> To post to this group, send email to std-proposals@isocpp.org.
>> Visit this group at
>> http://groups.google.com/a/isocpp.org/group/std-proposals/.
>>
>
>
>
> --
>  Ehsan
>
>
>

--=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/.

--f46d044289e8f7688d0511974192
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<p dir=3D"ltr">See</p>
<p dir=3D"ltr"><a href=3D"https://groups.google.com/a/isocpp.org/forum/?nom=
obile=3Dtrue#!searchin/std-proposals/virtual$20data$20members/std-proposals=
/Z1QG_3Mrn0Y/lzrwNxDeKUQJ">https://groups.google.com/a/isocpp.org/forum/?no=
mobile=3Dtrue#!searchin/std-proposals/virtual$20data$20members/std-proposal=
s/Z1QG_3Mrn0Y/lzrwNxDeKUQJ</a></p>
<p dir=3D"ltr">If the link doesn&#39;t work search for &quot;virtual data m=
embers&quot; in future proposals.</p>
<p dir=3D"ltr">Cassio.</p>
<div class=3D"gmail_quote">On 18 Mar 2015 21:46, &quot;Bjarne Stroustrup&qu=
ot; &lt;<a href=3D"mailto:bjarne@stroustrup.com">bjarne@stroustrup.com</a>&=
gt; wrote:<br type=3D"attribution"><blockquote class=3D"gmail_quote" style=
=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
 =20
   =20
 =20
  <div bgcolor=3D"#FFFFFF" text=3D"#000000">
    (1) yes it should be immutable<br>
    (2) I described something like that in D&amp;E (and maybe even in
    the ARM)<br>
    (3) what&#39;s the important use case?<br>
    <br>
    <div>On 3/18/2015 4:57 PM, Ehsan Akhgari
      wrote:<br>
    </div>
    <blockquote type=3D"cite">
      <div dir=3D"ltr">
        <div class=3D"gmail_extra">
          <div class=3D"gmail_quote">On Wed, Mar 18, 2015 at 4:52 PM, Tony
            Van Eerd <span dir=3D"ltr">&lt;<a href=3D"mailto:tvaneerd@black=
berry.com" target=3D"_blank">tvaneerd@blackberry.com</a>&gt;</span>
            wrote:<br>
            <blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;bo=
rder-left:1px #ccc solid;padding-left:1ex">
              <div link=3D"blue" vlink=3D"purple" lang=3D"EN-US">
                <div>
                  <p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;fo=
nt-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d">I
                      would say it needs to be constexpr or static =E2=80=
=93 at
                      least for it to be stored in the vtable.</span></p>
                  <p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;fo=
nt-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d">(ie
                      assuming the vtable is shared by all instances of
                      the class means that the value is shared by all
                      instances of the class)</span></p>
                </div>
              </div>
            </blockquote>
            <div><br>
            </div>
            <div>Yes, exactly.=C2=A0 Note that from a pragmatic standpoint,
              it&#39;s probably important for compilers to be able to store
              the vtable in read-only memory in order to protect against
              security attacks attempting to overwrite vtable entries at
              runtime.<br>
            </div>
            <div>=C2=A0</div>
            <blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;bo=
rder-left:1px #ccc solid;padding-left:1ex">
              <div link=3D"blue" vlink=3D"purple" lang=3D"EN-US">
                <div>
                  <p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;fo=
nt-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d"></span>=
</p>
                  <p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;fo=
nt-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d">=C2=A0<=
/span></p>
                  <div style=3D"border:none;border-left:solid blue 1.5pt;pa=
dding:0in 0in 0in 4.0pt">
                    <div>
                      <div style=3D"border:none;border-top:solid #b5c4df 1.=
0pt;padding:3.0pt 0in 0in 0in">
                        <p class=3D"MsoNormal"><b><span style=3D"font-size:=
10.0pt;font-family:&quot;Tahoma&quot;,&quot;sans-serif&quot;">From:</span><=
/b><span style=3D"font-size:10.0pt;font-family:&quot;Tahoma&quot;,&quot;san=
s-serif&quot;">
                            Gabriel Dos Reis [mailto:<a href=3D"mailto:gdr@=
microsoft.com" target=3D"_blank">gdr@microsoft.com</a>]
                            <br>
                            <b>Sent:</b> Wednesday, March 18, 2015 4:42
                            PM<br>
                            <b>To:</b> &#39;<a href=3D"mailto:std-proposals=
@isocpp.org" target=3D"_blank">std-proposals@isocpp.org</a>&#39;;
                            C++std-ext; <a href=3D"mailto:ehsan@mozilla.com=
" target=3D"_blank">ehsan@mozilla.com</a><br>
                            <b>Subject:</b> [c++std-ext-16622] Re:
                            [std-proposals] virtual constexpr fields</span>=
</p>
                      </div>
                    </div>
                    <div>
                      <div>
                        <p class=3D"MsoNormal">=C2=A0</p>
                        <p class=3D"MsoNormal"><span style=3D"font-size:11.=
0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d">D=
oes
                            the non-static data member need to be
                            constexpr if it is virtual?=C2=A0 Why?</span></=
p>
                        <p class=3D"MsoNormal"><span style=3D"font-size:11.=
0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d">=
=C2=A0</span></p>
                        <p class=3D"MsoNormal"><span style=3D"font-size:11.=
0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d">-=
-
                            Gaby</span></p>
                        <p class=3D"MsoNormal"><span style=3D"font-size:11.=
0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d">=
=C2=A0</span></p>
                        <div>
                          <div style=3D"border:none;border-top:solid #e1e1e=
1 1.0pt;padding:3.0pt 0in 0in 0in">
                            <p class=3D"MsoNormal"><b><span style=3D"font-s=
ize:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;">From:</s=
pan></b><span style=3D"font-size:11.0pt;font-family:&quot;Calibri&quot;,&qu=
ot;sans-serif&quot;">
                                &#39;Botond Ballo&#39; via ISO C++ Standard=
 -
                                Future Proposals [<a href=3D"mailto:std-pro=
posals@isocpp.org" target=3D"_blank">mailto:std-proposals@isocpp.org</a>]
                                <br>
                                <b>Sent:</b> Wednesday, March 18, 2015
                                1:26 PM<br>
                                <b>To:</b> C++std-ext; <a href=3D"mailto:eh=
san@mozilla.com" target=3D"_blank">ehsan@mozilla.com</a>;
                                <a href=3D"mailto:std-proposals@isocpp.org"=
 target=3D"_blank">
                                  std-proposals@isocpp.org</a><br>
                                <b>Subject:</b> [std-proposals] virtual
                                constexpr fields</span></p>
                          </div>
                        </div>
                        <p class=3D"MsoNormal">=C2=A0</p>
                        <div>
                          <div>
                            <p class=3D"MsoNormal" style=3D"background:whit=
e"><span style=3D"font-size:9.0pt;font-family:&quot;Helvetica&quot;,&quot;s=
ans-serif&quot;;color:black">There
                                are cases where you would like to
                                associate constants with a given type.
                                Here is how you can currently do it in
                                C++:<br>
                                <br>
                                struct Merchandise {<br>
                                =C2=A0=C2=A0=C2=A0 virtual int price() { re=
turn 0; }<br>
                                };<br>
                                <br>
                                struct Shoe : Merchandise {<br>
                                =C2=A0=C2=A0=C2=A0 virtual int price() { re=
turn 10;<br>
                                }<br>
                                <br>
                                If you could do it this way instead:<br>
                                <br>
                                struct Merchandise {<br>
                                =C2=A0=C2=A0=C2=A0 virtual constexpr int pr=
ice =3D 0;<br>
                                };<br>
                                <br>
                                struct Shoe : Merchandise {<br>
                                =C2=A0=C2=A0=C2=A0 virtual constexpr int pr=
ice =3D 10;<br>
                                }<br>
                                <br>
                                then the compiler could store the
                                constant value directly in the vtable.
                                This would eliminate the double
                                indirection involved in dereferencing a
                                function vtable entry, the cost of
                                running that function at runtime, and
                                the code size of the function in the
                                compiled binary.<br>
                                <br>
                                Virtual fields would be limited to being
                                constexpr, so that the value to be
                                placed in the vtable, like other values
                                in the vtable, can be determined at
                                compile time.<br>
                                <br>
                                Has this, or something similar, ever
                                been proposed? Is there any interest in
                                it?<br>
                                <br>
                                -- Botond and Ehsan</span></p>
                          </div>
                          <div>
                            <p class=3D"MsoNormal" style=3D"background:whit=
e"><span style=3D"font-size:9.0pt;font-family:&quot;Helvetica&quot;,&quot;s=
ans-serif&quot;;color:black">=C2=A0</span></p>
                          </div>
                        </div>
                        <p class=3D"MsoNormal">-- <br>
                          <br>
                          --- <br>
                          You received this message because you are
                          subscribed to the Google Groups &quot;ISO C++
                          Standard - Future Proposals&quot; group.<br>
                          To unsubscribe from this group and stop
                          receiving emails from it, send an email to
                          <a href=3D"mailto:std-proposals+unsubscribe@isocp=
p.org" target=3D"_blank">std-proposals+unsubscribe@isocpp.org</a>.<br>
                          To post to this group, send email to <a href=3D"m=
ailto:std-proposals@isocpp.org" target=3D"_blank">std-proposals@isocpp.org<=
/a>.<br>
                          Visit this group at <a href=3D"http://groups.goog=
le.com/a/isocpp.org/group/std-proposals/" target=3D"_blank">
http://groups.google.com/a/isocpp.org/group/std-proposals/</a>.</p>
                      </div>
                    </div>
                  </div>
                </div>
              </div>
            </blockquote>
          </div>
          <br>
          <br clear=3D"all">
          <br>
          -- <br>
          <div>
            <div dir=3D"ltr">Ehsan<br>
            </div>
          </div>
        </div>
      </div>
    </blockquote>
    <br>
  </div>

</blockquote></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 />

--f46d044289e8f7688d0511974192--

.
