Topic: [c++std-ext-16626] virtual constexpr fields


Author: Cassio Neri <cassio.neri@gmail.com>
Date: Wed, 18 Mar 2015 22:03:47 +0000
Raw View
--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--

.