220 17081 <11B5438424E807459A28BD01C92339BA759E907C@XMB122CNC.rim.net> article
Path: news.gmane.org!not-for-mail
From: Tony Van Eerd <tvaneerd@blackberry.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: RE: virtual constexpr fields
Date: Wed, 18 Mar 2015 20:52:59 +0000
Lines: 321
Approved: news@gmane.org
Message-ID: <11B5438424E807459A28BD01C92339BA759E907C@XMB122CNC.rim.net>
References: <532355906.19321.1426710347371.JavaMail.yahoo@mail.yahoo.com>
 <DM2PR0301MB0911105FCB640A60230A94E2B0000@DM2PR0301MB0911.namprd03.prod.outlook.com>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/alternative;
	boundary="_000_11B5438424E807459A28BD01C92339BA759E907CXMB122CNCrimnet_"
X-Trace: ger.gmane.org 1426712025 31519 80.91.229.3 (18 Mar 2015 20:53:45 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Wed, 18 Mar 2015 20:53:45 +0000 (UTC)
To: "c++std-ext@accu.org" <c++std-ext@accu.org>, "'std-proposals@isocpp.org'"
	<std-proposals@isocpp.org>, "ehsan@mozilla.com" <ehsan@mozilla.com>
Original-X-From: std-proposals+bncBCOJZ74BXIBRBMGLU6UAKGQEVKKCXOY@isocpp.org Wed Mar 18 21:53:39 2015
Return-path: <std-proposals+bncBCOJZ74BXIBRBMGLU6UAKGQEVKKCXOY@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-yh0-f70.google.com ([209.85.213.70])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBCOJZ74BXIBRBMGLU6UAKGQEVKKCXOY@isocpp.org>)
	id 1YYKxe-0007vj-JR
	for gclcip-std-proposals@m.gmane.org; Wed, 18 Mar 2015 21:53:07 +0100
Original-Received: by yhoa41 with SMTP id a41sf31263734yho.2
        for <gclcip-std-proposals@m.gmane.org>; Wed, 18 Mar 2015 13:53:05 -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:to:subject:thread-topic:thread-index:date
         :message-id:references:in-reply-to:accept-language:content-language
         :content-type:mime-version:x-original-sender
         :x-original-authentication-results:reply-to:precedence:mailing-list
         :list-id:list-post:list-help:list-archive:list-subscribe
         :list-unsubscribe;
        bh=scoXnUwxI/FgM7mWZT5xvux0UiQVNPsQ70USevP9uaQ=;
        b=FW+7eS80klRJ9L2f2kUqXpTMw4bNahvMagsB8GYAozFRJw6Oe4XyA2HWgHsHQWz+RP
         F4UfNZtDFjZxwDCNYLfRzadMmAoueWUlcGNEgWLkbTiWqx4fDmbKjtxLfZ6LpYAayniY
         GsY3sF9Z/HlRFtEa3QEqoa5HYU/jnGx0eGnWZHOZ9dNwKGFEgxaJWNnG3HljhRZxliGy
         qtLyR4JzTo0366Oam/Gbx5Zqw9hrk23QlfzDMU2eQ+6OyNguR1Tz9Ro2K9pdVnWt5bmp
         URO+XKw/909v0TggTbpwGF/bBXm/RE8Ox4/hKbF1RgI5wIIR2 
X-Gm-Message-State: ALoCoQmosxZ81utWBH2NJ2Qzry4rI5iemSqellwQ6stjN3EEdkO4LFT2pCb7EVukopVtF6BHwKCM
X-Received: by 10.236.40.112 with SMTP id e76mr85812518yhb.5.1426711985241;
        Wed, 18 Mar 2015 13:53:05 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.107.10.220 with SMTP id 89ls631588iok.5.gmail; Wed, 18 Mar
 2015 13:53:04 -0700 (PDT)
X-Received: by 10.42.27.14 with SMTP id h14mr12426272icc.19.1426711984579;
        Wed, 18 Mar 2015 13:53:04 -0700 (PDT)
Original-Received: from smtp-p01.blackberry.com (smtp-p01.blackberry.com. [208.65.78.88])
        by mx.google.com with ESMTP id r2si3109092igh.60.2015.03.18.13.53.04
        for <std-proposals@isocpp.org>;
        Wed, 18 Mar 2015 13:53:04 -0700 (PDT)
Received-SPF: none (google.com: tvaneerd@blackberry.com does not designate permitted sender hosts) client-ip=208.65.78.88;
Original-Received: from xct108cnc.rim.net ([10.65.161.208])
  by mhs212cnc.rim.net with ESMTP/TLS/AES128-SHA; 18 Mar 2015 16:53:01 -0400
Original-Received: from XMB122CNC.rim.net ([fe80::28c6:fa1c:91c6:2e23]) by
 XCT108CNC.rim.net ([fe80::8dc1:9551:6ed8:c618%17]) with mapi id
 14.03.0210.002; Wed, 18 Mar 2015 16:53:00 -0400
Thread-Topic: [std-proposals] virtual constexpr fields
Thread-Index: AQHQYbxwdGJu00ca1kWgvOjM6ZmGsJ0itz7A
In-Reply-To: <DM2PR0301MB0911105FCB640A60230A94E2B0000@DM2PR0301MB0911.namprd03.prod.outlook.com>
Accept-Language: en-CA, en-US
Content-Language: en-US
X-MS-Has-Attach: 
X-MS-TNEF-Correlator: 
x-originating-ip: [10.65.160.251]
X-Original-Sender: tvaneerd@blackberry.com
X-Original-Authentication-Results: mx.google.com;       spf=none (google.com:
 tvaneerd@blackberry.com does not designate permitted sender hosts) smtp.mail=tvaneerd@blackberry.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:17081
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/17081>

--_000_11B5438424E807459A28BD01C92339BA759E907CXMB122CNCrimnet_
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

I would say it needs to be constexpr or static =E2=80=93 at least for it 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)


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-pr=
oposals@isocpp.org]
Sent: Wednesday, March 18, 2015 1:26 PM
To: C++std-ext; ehsan@mozilla.com<mailto:ehsan@mozilla.com>; std-proposals@=
isocpp.org<mailto:std-proposals@isocpp.org>
Subject: [std-proposals] virtual constexpr fields

There are cases where you would like to associate constants with a given ty=
pe. 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. Th=
is would eliminate the double indirection involved in dereferencing a funct=
ion vtable entry, the cost of running that function at runtime, and the cod=
e 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 determined a=
t compile time.

Has this, or something similar, ever been proposed? Is there any interest i=
n it?

-- Botond and Ehsan

--

---
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<mailto:std-proposals+unsubscri=
be@isocpp.org>.
To post to this group, send email to std-proposals@isocpp.org<mailto:std-pr=
oposals@isocpp.org>.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.

--=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/.

--_000_11B5438424E807459A28BD01C92339BA759E907CXMB122CNCrimnet_
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<html xmlns:v=3D"urn:schemas-microsoft-com:vml" xmlns:o=3D"urn:schemas-micr=
osoft-com:office:office" xmlns:w=3D"urn:schemas-microsoft-com:office:word" =
xmlns:m=3D"http://schemas.microsoft.com/office/2004/12/omml" xmlns=3D"http:=
//www.w3.org/TR/REC-html40">
<head>
<meta http-equiv=3D"Content-Type" content=3D"text/html; charset=3Dutf-8">
<meta name=3D"Generator" content=3D"Microsoft Word 14 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
	{font-family:Helvetica;
	panose-1:2 11 6 4 2 2 2 2 2 4;}
@font-face
	{font-family:Helvetica;
	panose-1:2 11 6 4 2 2 2 2 2 4;}
@font-face
	{font-family:Calibri;
	panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
	{font-family:Tahoma;
	panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
	{margin:0in;
	margin-bottom:.0001pt;
	font-size:12.0pt;
	font-family:"Times New Roman","serif";}
a:link, span.MsoHyperlink
	{mso-style-priority:99;
	color:blue;
	text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
	{mso-style-priority:99;
	color:purple;
	text-decoration:underline;}
p
	{mso-style-priority:99;
	mso-margin-top-alt:auto;
	margin-right:0in;
	mso-margin-bottom-alt:auto;
	margin-left:0in;
	font-size:12.0pt;
	font-family:"Times New Roman","serif";}
p.MsoAcetate, li.MsoAcetate, div.MsoAcetate
	{mso-style-priority:99;
	mso-style-link:"Balloon Text Char";
	margin:0in;
	margin-bottom:.0001pt;
	font-size:8.0pt;
	font-family:"Tahoma","sans-serif";}
span.EmailStyle18
	{mso-style-type:personal;
	font-family:"Calibri","sans-serif";
	color:#1F497D;}
span.EmailStyle19
	{mso-style-type:personal;
	font-family:"Calibri","sans-serif";
	color:windowtext;}
span.EmailStyle20
	{mso-style-type:personal-reply;
	font-family:"Calibri","sans-serif";
	color:#1F497D;}
span.BalloonTextChar
	{mso-style-name:"Balloon Text Char";
	mso-style-priority:99;
	mso-style-link:"Balloon Text";
	font-family:"Tahoma","sans-serif";}
..MsoChpDefault
	{mso-style-type:export-only;
	font-size:10.0pt;}
@page WordSection1
	{size:8.5in 11.0in;
	margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
	{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext=3D"edit" spidmax=3D"1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext=3D"edit">
<o:idmap v:ext=3D"edit" data=3D"1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang=3D"EN-US" link=3D"blue" vlink=3D"purple">
<div class=3D"WordSection1">
<p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:&quot;Ca=
libri&quot;,&quot;sans-serif&quot;;color:#1F497D">I would say it needs to b=
e constexpr or static =E2=80=93 at least for it to be stored in the vtable.=
<o:p></o:p></span></p>
<p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:&quot;Ca=
libri&quot;,&quot;sans-serif&quot;;color:#1F497D">(ie assuming the vtable i=
s shared by all instances of the class means that the value is shared by al=
l instances of the class)<o:p></o:p></span></p>
<p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:&quot;Ca=
libri&quot;,&quot;sans-serif&quot;;color:#1F497D"><o:p>&nbsp;</o:p></span><=
/p>
<p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:&quot;Ca=
libri&quot;,&quot;sans-serif&quot;;color:#1F497D"><o:p>&nbsp;</o:p></span><=
/p>
<div style=3D"border:none;border-left:solid blue 1.5pt;padding: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-s=
ize:10.0pt;font-family:&quot;Tahoma&quot;,&quot;sans-serif&quot;"> Gabriel =
Dos Reis [mailto:gdr@microsoft.com]
<br>
<b>Sent:</b> Wednesday, March 18, 2015 4:42 PM<br>
<b>To:</b> 'std-proposals@isocpp.org'; C&#43;&#43;std-ext; ehsan@mozilla.co=
m<br>
<b>Subject:</b> [c&#43;&#43;std-ext-16622] Re: [std-proposals] virtual cons=
texpr fields<o:p></o:p></span></p>
</div>
</div>
<p class=3D"MsoNormal"><o:p>&nbsp;</o:p></p>
<p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:&quot;Ca=
libri&quot;,&quot;sans-serif&quot;;color:#1F497D">Does the non-static data =
member need to be constexpr if it is virtual?&nbsp; Why?<o:p></o:p></span><=
/p>
<p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:&quot;Ca=
libri&quot;,&quot;sans-serif&quot;;color:#1F497D"><o:p>&nbsp;</o:p></span><=
/p>
<p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:&quot;Ca=
libri&quot;,&quot;sans-serif&quot;;color:#1F497D">-- Gaby<o:p></o:p></span>=
</p>
<p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:&quot;Ca=
libri&quot;,&quot;sans-serif&quot;;color:#1F497D"><o:p>&nbsp;</o:p></span><=
/p>
<div>
<div style=3D"border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0in =
0in 0in">
<p class=3D"MsoNormal"><b><span style=3D"font-size:11.0pt;font-family:&quot=
;Calibri&quot;,&quot;sans-serif&quot;">From:</span></b><span style=3D"font-=
size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;"> 'Boton=
d Ballo' via ISO C&#43;&#43; Standard - Future Proposals [<a href=3D"mailto=
:std-proposals@isocpp.org">mailto:std-proposals@isocpp.org</a>]
<br>
<b>Sent:</b> Wednesday, March 18, 2015 1:26 PM<br>
<b>To:</b> C&#43;&#43;std-ext; <a href=3D"mailto:ehsan@mozilla.com">ehsan@m=
ozilla.com</a>; <a href=3D"mailto:std-proposals@isocpp.org">
std-proposals@isocpp.org</a><br>
<b>Subject:</b> [std-proposals] virtual constexpr fields<o:p></o:p></span><=
/p>
</div>
</div>
<p class=3D"MsoNormal"><o:p>&nbsp;</o:p></p>
<div>
<div id=3D"yui_3_16_0_1_1426691947599_108603">
<p class=3D"MsoNormal" style=3D"background:white"><span style=3D"font-size:=
9.0pt;font-family:&quot;Helvetica&quot;,&quot;sans-serif&quot;;color:black"=
>There are cases where you would like to associate constants with a given t=
ype. Here is how you can currently do it in C&#43;&#43;:<br>
<br>
struct Merchandise {<br>
&nbsp;&nbsp;&nbsp; virtual int price() { return 0; }<br>
};<br>
<br>
struct Shoe : Merchandise {<br>
&nbsp;&nbsp;&nbsp; virtual int price() { return 10;<br>
}<br>
<br>
If you could do it this way instead:<br>
<br>
struct Merchandise {<br>
&nbsp;&nbsp;&nbsp; virtual constexpr int price =3D 0;<br>
};<br>
<br>
struct Shoe : Merchandise {<br>
&nbsp;&nbsp;&nbsp; virtual constexpr int price =3D 10;<br>
}<br>
<br>
then the compiler could store the constant value directly in the vtable. Th=
is would eliminate the double indirection involved in dereferencing a funct=
ion vtable entry, the cost of running that function at runtime, and the cod=
e 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 a=
t compile time.<br>
<br>
Has this, or something similar, ever been proposed? Is there any interest i=
n it?<br>
<br>
-- Botond and Ehsan<o:p></o:p></span></p>
</div>
<div id=3D"yui_3_16_0_1_1426691947599_108603">
<p class=3D"MsoNormal" style=3D"background:white"><span style=3D"font-size:=
9.0pt;font-family:&quot;Helvetica&quot;,&quot;sans-serif&quot;;color:black"=
><o:p>&nbsp;</o:p></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&#43;&#43; 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&#43;unsubscribe@isocpp.org">std-proposals&#=
43;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>.<o:p></o:p><=
/p>
</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 />

--_000_11B5438424E807459A28BD01C92339BA759E907CXMB122CNCrimnet_--

.
