<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 4138: is_within_lifetime should mandate is_object</title>
<meta property="og:title" content="Issue 4138: is_within_lifetime should mandate is_object">
<meta property="og:description" content="C++ library issue. Status: New">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue4138.html">
<meta property="og:type" content="website">
<meta property="og:image" content="http://cplusplus.github.io/LWG/images/cpp_logo.png">
<meta property="og:image:alt" content="C++ logo">
<style>
  p {text-align:justify}
  li {text-align:justify}
  pre code.backtick::before { content: "`" }
  pre code.backtick::after { content: "`" }
  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.issues-index { border: 1px solid; border-collapse: collapse; }
  table.issues-index th { text-align: center; padding: 4px; border: 1px solid; }
  table.issues-index td { padding: 4px; border: 1px solid; }
  table.issues-index td:nth-child(1) { text-align: right; }
  table.issues-index td:nth-child(2) { text-align: left; }
  table.issues-index td:nth-child(3) { text-align: left; }
  table.issues-index td:nth-child(4) { text-align: left; }
  table.issues-index td:nth-child(5) { text-align: center; }
  table.issues-index td:nth-child(6) { text-align: center; }
  table.issues-index td:nth-child(7) { text-align: left; }
  table.issues-index td:nth-child(5) span.no-pr { color: red; }
  @media (prefers-color-scheme: dark) {
     html {
        color: #ddd;
        background-color: black;
     }
     ins {
        background-color: #225522
     }
     del {
        background-color: #662222
     }
     a {
        color: #6af
     }
     a:visited {
        color: #6af
     }
     blockquote.note
     {
        background-color: rgba(255, 255, 255, .10)
     }
  }
</style>
</head>
<body>
<hr>
<p><em>This page is a snapshot from the LWG issues list, see the <a href="lwg-active.html">Library Active Issues List</a> for more information and the meaning of <a href="lwg-active.html#New">New</a> status.</em></p>
<h3 id="4138"><a href="lwg-active.html#4138">4138</a>. <code>is_within_lifetime</code> should mandate <code>is_object</code></h3>
<p><b>Section:</b> 21.3.12 <a href="https://wg21.link/meta.const.eval">[meta.const.eval]</a> <b>Status:</b> <a href="lwg-active.html#New">New</a>
 <b>Submitter:</b> Corentin <b>Opened:</b> 2024-08-09 <b>Last modified:</b> 2024-08-11</p>
<p><b>Priority: </b>Not Prioritized
</p>
<p><b>View all issues with</b> <a href="lwg-status.html#New">New</a> status.</p>
<p><b>Discussion:</b></p>
<blockquote><pre>
int f();
std::is_within_lifetime&lt;int()&gt;(f);
</pre></blockquote>
<p>
This is currently well-formed, and only fails when evaluated because 
<code>is_within_lifetime</code> is not constrained. However talking of lifetime 
of a non-object does not make sense, and the lack of constraint makes the 
implementation and use of that function and underlying built-in more 
convoluted than necessary.
</p>


<p id="res-4138"><b>Proposed resolution:</b></p>
<p>
This wording is relative to <a href="https://wg21.link/N4988" title=" Working Draft, Programming Languages — C++">N4988</a>.
</p>

<ol>

<li><p>Modify 21.3.3 <a href="https://wg21.link/meta.type.synop">[meta.type.synop]</a>, header <code>&lt;type_traits&gt;</code> synopsis, as indicated:</p>

<blockquote>
<pre>
[&hellip;]
// <i>21.3.12 <a href="https://wg21.link/meta.const.eval">[meta.const.eval]</a>, constant evaluation context</i>
constexpr bool is_constant_evaluated() noexcept;
<ins>template&lt;class T&gt;</ins>
consteval bool is_within_lifetime(const <ins>T</ins><del>auto</del>*) noexcept;
</pre>
</blockquote>

</li>


<li><p>Modify 21.3.12 <a href="https://wg21.link/meta.const.eval">[meta.const.eval]</a> as indicated:</p>

<blockquote>
<pre>
<ins>template&lt;class T&gt;</ins>
consteval bool is_within_lifetime(const <ins>T</ins><del>auto</del>* p) noexcept;
</pre>
<blockquote>
<p>
<ins>-?- <i>Mandates</i>: <code>is_object_v&lt;T&gt;</code> is <code>true</code>.</ins>
<p/>
-3- <i>Returns</i>: <code>true</code> if <code>p</code> is a pointer to an object that is 
within its lifetime (6.8.4 <a href="https://wg21.link/basic.life">[basic.life]</a>); otherwise, <code>false</code>.
<p/>
-4- <i>Remarks</i>: During the evaluation of an expression <code>E</code> as a core 
constant expression, a call to this function is ill-formed unless <code>p</code> 
points to an object that is usable in constant expressions or whose complete
object's lifetime began within <code>E</code>.
</p>
</blockquote>
</blockquote>

</li>

</ol>





</body>
</html>
