<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
    "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta charset="utf-8">
<title>C++ Standard Library Issues Resolved Directly</title>
<style type="text/css">
  p {text-align:justify}
  li {text-align:justify}
  blockquote.note
  {
    background-color:#E0E0E0;
    padding-left: 15px;
    padding-right: 15px;
    padding-top: 1px;
    padding-bottom: 1px;
  }
  ins {background-color:#A0FFA0}
  del {background-color:#FFA0A0}
  table {border-collapse: collapse;}
</style>
</head>
<body>
<h1>C++ Standard Library Issues Resolved Directly In Jacksonville</h1>
<table>
<tr>
<td align="left">Doc. no.</td>
<td align="left">P0304R0</td>
</tr>
<tr>
<td align="left">Date:</td>
<td align="left"><p>Revised 2016-03-04 at 17:03:35 UTC</p>
</td>
</tr>
<tr>
<td align="left">Project:</td>
<td align="left">Programming Language C++</td>
</tr>
<tr>
<td align="left">Reply to:</td>
<td align="left">Marshall Clow &lt;<a href="mailto:lwgchair@gmail.com">lwgchair@gmail.com</a>&gt;</td>
</tr>
</table>
<h2>Immediate Issues</h2>
<hr>
<h3><a name="2296" href="#2296">2296.</a> <tt>std::addressof</tt> should be <tt>constexpr</tt></h3>
<p><b>Section:</b> 20.7.12.1 [specialized.addressof] <b>Status:</b> <a href="lwg-active.html#Immediate">Immediate</a>
 <b>Submitter:</b> Daryle Walker <b>Opened:</b> 2013-09-08 <b>Last modified:</b> 2016-03-04</p>
<p><b>Priority: </b>3
</p>
<p><b>View all other</b> <a href="lwg-index.html#specialized.addressof">issues</a> in [specialized.addressof].</p>
<p><b>Discussion:</b></p>
<p>
I'm writing a function that needs to be <tt>constexpr</tt> and I wanted to take the address of its input. I was 
thinking of using <tt>std::addressof</tt> to be safe, but it isn't currently <tt>constexpr</tt>. A 
<a href="http://en.cppreference.com/w/cpp/memory/addressof">sample implementation</a> 
couldn't be <tt>constexpr</tt> under the C++11 rules, though.
<p/>
Daniel Kr&uuml;gler:
<p/>
Indeed the core language clarified by <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#1312">CWG 1312</a> 
and by <a href="www.open-std.org/jtc1/sc22/wg21/docs/cwg_closed.html#1384">CWG 1384</a>, that such emulations of <tt>std::addressof</tt>
implementations are not valid in constant expressions, therefore it seems more like a defect than a feature request to ask for 
the guarantee that <tt>std::addressof</tt> is a <tt>constexpr</tt> function. It should be added that a similar requirement
already exists for <tt>offsetof</tt> indirectly via the C99 standard as of 7.17 p3:
</p>
<blockquote>
<p>
The macros are [&hellip;]
</p>
<blockquote><pre>
offsetof(type, member-designator)
</pre></blockquote>
<p>
which expands to an integer constant expression that has type <tt>size_t</tt> [&hellip;]
</p>
</blockquote>

<p>
combined with the noted property in C++11 that:
</p>

<blockquote><p>
"<tt>offsetof</tt> is required to work as specified even if unary <tt>operator&amp;</tt> 
is overloaded for any of the types involved"
</p></blockquote>

<p>
Therefore implementations should already be able without heroic efforts to realize this functionality by
some intrinsic. The wording needs at least to ensure that for any lvalue core constant expression <tt><em>e</em></tt>
the expression <tt>std::addressof(<em>e</em>)</tt> is a core constant expression.
</p>

<p><i>[2013-09 Chicago]</i></p>

<p>
</p>

<p><i>[2014-06-08, Daniel improves wording]</i></p>

<p>
It has been ensured that the wording is in sync with the recent working paper and the usage of "any" has been
improved to say "every" instead (the fix is similar to that applied by LWG <a href="lwg-defects.html#2150">2150</a>).
</p>

<p>
<strong>Previous resolution from Daniel [SUPERSEDED]:</strong>
</p>
<blockquote class="note">
<ol>
<li><p>Change header <tt>&lt;memory&gt;</tt> synopsis, 20.7.2 [memory.syn] as indicated:</p>

<blockquote><pre>
namespace std {
  [&hellip;]
  <i>// 20.7.12 [specialized.algorithms], specialized algorithms:</i>
  template &lt;class T&gt; <ins>constexpr</ins> T* addressof(T&amp; r) noexcept;
  [&hellip;]
}
</pre></blockquote>
</li>

<li><p>Change 20.7.12.1 [specialized.addressof] as indicated:</p>

<blockquote><pre>
template &lt;class T&gt; <ins>constexpr</ins> T* addressof(T&amp; r) noexcept;
</pre><blockquote>
<p>
-1- <i>Returns:</i> The actual address of the object or function referenced by <tt>r</tt>, even in the presence of an
overloaded <tt>operator&amp;</tt>.
<p/>
<ins>-?- <i>Remarks:</i> For every lvalue core constant expression <tt><em>e</em></tt> (5.20 [expr.const]), the expression 
<tt>std::addressof(<em>e</em>)</tt> is a core constant expression.</ins>
</p>
</blockquote>
</blockquote>

</li>
</ol>
</blockquote>

<p><i>[2014-06-09, further improvements]</i></p>

<p>
A new wording form is now used similar to the approach used by LWG <a href="lwg-defects.html#2234">2234</a>, which
is a stricter way to impose the necessary implementation requirements.
</p>

<p><i>[2015-05, Lenexa]</i></p>

<p>
 STL: the intent of this change is good; I think the wording is good<br/>
- I'm a bit worried about asking for a compiler hook<br/>
- if every implementer says: yes they can do it we should be good<br/>
EB: there is missing the word "a" before "subexpression" (in multiple places)<br/>
MC: the editor should do - we rely on our editors<br/>
MC: move to Review with a note stating that we wait for implementation experience first<br/>
- in favor: 13, opposed: 0, abstain: 2
HB: N4430 will bring something which is addressing this issue<br/>
MC: good we didn't go to ready then 
</p>


<p><b>Proposed resolution:</b></p>
<p>This wording is relative to N3936.</p>

<ol>
<li><p>Introduce the following new definition to the existing list in 17.3 [definitions]: [<i>Drafting note</i>:
If LWG <a href="lwg-defects.html#2234">2234</a> is accepted before this issue, the accepted wording for the new definition should be used instead
&mdash; <i>end drafting note</i>]</p>

<blockquote>
<p>
<strong>constant subexpression</strong> [defns.const.subexpr]
<p/>
an expression whose evaluation as a subexpression of a <em>conditional-expression</em> <em>CE</em> (5.16 [expr.cond]) 
would not prevent <em>CE</em> from being a core constant expression (5.20 [expr.const]).
</p>
</blockquote>
</li>

<li><p>Change header <tt>&lt;memory&gt;</tt> synopsis, 20.7.2 [memory.syn] as indicated:</p>

<blockquote><pre>
namespace std {
  [&hellip;]
  <i>// 20.7.12 [specialized.algorithms], specialized algorithms:</i>
  template &lt;class T&gt; <ins>constexpr</ins> T* addressof(T&amp; r) noexcept;
  [&hellip;]
}
</pre></blockquote>
</li>

<li><p>Change 20.7.12.1 [specialized.addressof] as indicated:</p>

<blockquote><pre>
template &lt;class T&gt; <ins>constexpr</ins> T* addressof(T&amp; r) noexcept;
</pre><blockquote>
<p>
-1- <i>Returns:</i> The actual address of the object or function referenced by <tt>r</tt>, even in the presence of an
overloaded <tt>operator&amp;</tt>.
<p/>
<ins>-?- <i>Remarks:</i> An expression <tt>std::addressof(<em>E</em>)</tt> is a constant subexpression (17.3.28 [defns.const.subexpr]), 
if <tt><em>E</em></tt> is an lvalue constant subexpression.</ins>
</p>
</blockquote>
</blockquote>

</li>
</ol>






</body>
</html>
