<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 2731: Existence of lock_guard&lt;MutexTypes...&gt;::mutex_type typedef unclear</title>
<meta property="og:title" content="Issue 2731: Existence of lock_guard&lt;MutexTypes...&gt;::mutex_type typedef unclear">
<meta property="og:description" content="C++ library issue. Status: C++23">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue2731.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#C++23">C++23</a> status.</em></p>
<h3 id="2731"><a href="lwg-defects.html#2731">2731</a>. Existence of <code>lock_guard&lt;MutexTypes...&gt;::mutex_type</code> typedef unclear</h3>
<p><b>Section:</b> 32.6.5.2 <a href="https://wg21.link/thread.lock.guard">[thread.lock.guard]</a> <b>Status:</b> <a href="lwg-active.html#C++23">C++23</a>
 <b>Submitter:</b> Eric Fiselier <b>Opened:</b> 2016-06-13 <b>Last modified:</b> 2023-11-22</p>
<p><b>Priority: </b>3
</p>
<p><b>View all other</b> <a href="lwg-index.html#thread.lock.guard">issues</a> in [thread.lock.guard].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#C++23">C++23</a> status.</p>
<p><b>Discussion:</b></p>
<p>
In the synopsis of 32.6.5.3 <a href="https://wg21.link/thread.lock.scoped">[thread.lock.scoped]</a> the <code>mutex_type</code> typedef is specified as follows:
</p>
<blockquote>
<pre>
template &lt;class... MutexTypes&gt;
class scoped_lock {
public:
  typedef Mutex mutex_type; <i>// If</i> MutexTypes... <i>consists of the single type</i> Mutex
  [&hellip;]
};
</pre>
</blockquote>
<p>
The comment seems ambiguous as it could mean either:
</p>
<ol>
<li><code>sizeof...(MutexTypes) == 1</code>.</li>
<li><code>sizeof...(MutexTypes) &gt;= 1</code> and every type in <code>MutexTypes...</code> is the same type.</li>
</ol>
<p>
I originally took the language to mean (2), but upon further review it seems that (1) is the intended interpretation, 
as suggested in the LEWG discussion in <a href="http://wiki.edg.com/bin/view/Wg21lenexa/N4470">Lenexa</a>.
<p/>
I think the language should be clarified to prevent implementation divergence.
</p>

<p><i>[2016-07, Toronto Saturday afternoon issues processing]</i></p>

<p>General feeling that <code>sizeof(MutexTypes...) == 1</code> is a better way to state the requirement.</p>
<p>Reworked the text to refer to <code>scoped_lock</code> instead of <code>lock_guard</code></p>
<p>Marshall and Eric to reword and discuss on reflector. Status to Open</p>

<p><i>[2018-3-14 Wednesday evening issues processing; general agreement to adopt once the wording is updated.]</i></p>

<p>2018-03-18 Marshall provides updated wording.</p>

<strong>Previous resolution: [SUPERSEDED]</strong>
<blockquote class="note">
<p>This wording is relative to N4594.</p>
<ol>
<li><p>Edit 32.6.5.2 <a href="https://wg21.link/thread.lock.guard">[thread.lock.guard]</a>/1, class template <code>lock_guard</code> synopsis, as indicated:</p>

<blockquote>
<pre>
template &lt;class... MutexTypes&gt;
class lock_guard {
public:
  typedef Mutex mutex_type; <i>// <ins>Only i</ins><del>I</del>f</i> MutexTypes... <i><del>consists of the</del><ins>expands to a</ins> single type</i> <code>Mutex</code>
  [&hellip;]
};
</pre>
</blockquote>
</li>
</ol>
</blockquote>

<strong>Previous resolution: [SUPERSEDED]</strong>
<blockquote class="note">
<p>This wording is relative to N4727.</p>
<ol>
<li><p>Edit 32.6.5.2 <a href="https://wg21.link/thread.lock.guard">[thread.lock.guard]</a>/1, class template <code>lock_guard</code> synopsis, as indicated:</p>

<blockquote>
<pre>
template &lt;class... MutexTypes&gt;
class scoped_lock {
public:
  using mutex_type = Mutex; <i>// <ins>Only i</ins><del>I</del>f</i> <ins><code>sizeof(MutexTypes...) == 1</code></ins> <del><code>MutexTypes...</code> <i>consists of the single type</i> <code>Mutex</code></del>
  [&hellip;]
};
</pre>
</blockquote>
</li>
</ol>
</blockquote>

<p><i>[2020-05-11; Daniel provides improved wording]</i></p>


<p><i>[2020-05-16 Reflector discussions]</i></p>

<p>Status to Tentatively Ready after five positive votes on the reflector.</p>
<p><i>[2020-11-09 Approved In November virtual meeting. Status changed: Tentatively Ready &rarr; WP.]</i></p>



<p id="res-2731"><b>Proposed resolution:</b></p>
<p>This wording is relative to <a href="https://wg21.link/n4861">N4861</a>.</p>

<ol>
<li><p>Edit 32.6.5.3 <a href="https://wg21.link/thread.lock.scoped">[thread.lock.scoped]</a>, class template <code>scoped_lock</code> synopsis, as indicated:</p>

<blockquote>
<blockquote>
<pre>
template &lt;class... MutexTypes&gt;
class scoped_lock {
public:
  <del>using mutex_type = Mutex; <i>// If</i> MutexTypes... <i>consists of the single type</i> Mutex</del>
  <ins>using mutex_type = <i>see below</i>; <i>// Only if </i> sizeof...(MutexTypes) == 1</ins>
  [&hellip;]
};
</pre>
</blockquote>
<p>
-1- An object of type <code>scoped_lock</code> controls the ownership of lockable objects within a scope. A 
<code>scoped_lock</code> object maintains ownership of lockable objects throughout the <code>scoped_lock</code> 
object's lifetime (6.8.4 <a href="https://wg21.link/basic.life">[basic.life]</a>). The behavior of a program is undefined if the lockable 
objects referenced by <code>pm</code> do not exist for the entire lifetime of the <code>scoped_lock</code> object.
</p>
<ul>
<li><p><del>When</del><ins>If</ins> <code>sizeof...(MutexTypes)</code> is <del><code>1</code></del><ins>one, let <code>Mutex</code> 
denote the sole type constituting the pack <code>MutexTypes</code>.</ins><del>, the supplied</del> <code>Mutex</code> 
<del>type</del> shall meet the <i>Cpp17BasicLockable</i> requirements (32.2.5.2 <a href="https://wg21.link/thread.req.lockable.basic">[thread.req.lockable.basic]</a>).
<ins>The member <i>typedef-name</i> <code>mutex_type</code> denotes the same type as <code>Mutex</code>.</ins></p></li>
<li><p>Otherwise, <del>each of the mutex types</del><ins>all types in the template parameter pack <code>MutexTypes</code></ins> 
shall meet the <i>Cpp17Lockable</i> requirements (32.2.5.3 <a href="https://wg21.link/thread.req.lockable.req">[thread.req.lockable.req]</a>) <ins>and there is 
no member <code>mutex_type</code></ins>.</p></li>
</ul> 
</blockquote>
</li>
</ol>





</body>
</html>
