<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 3508: atomic_ref&lt;cv T&gt; is not well-specified</title>
<meta property="og:title" content="Issue 3508: atomic_ref&lt;cv T&gt; is not well-specified">
<meta property="og:description" content="C++ library issue. Status: Resolved">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue3508.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#Resolved">Resolved</a> status.</em></p>
<h3 id="3508"><a href="lwg-defects.html#3508">3508</a>. <code>atomic_ref&lt;<i>cv</i> T&gt;</code> is not well-specified</h3>
<p><b>Section:</b> 32.5.7.1 <a href="https://wg21.link/atomics.ref.generic.general">[atomics.ref.generic.general]</a> <b>Status:</b> <a href="lwg-active.html#Resolved">Resolved</a>
 <b>Submitter:</b> Casey Carter <b>Opened:</b> 2020-12-02 <b>Last modified:</b> 2025-02-07</p>
<p><b>Priority: </b>2
</p>
<p><b>View all issues with</b> <a href="lwg-status.html#Resolved">Resolved</a> status.</p>
<p><b>Discussion:</b></p>
<p>
<code>atomic_ref&lt;T&gt;</code> requires only that its template parameter <code>T</code> is trivially copyable,
which is not sufficient to implement many of the class template's member functions. Consider, for example:
</p>
<blockquote><pre>
int main() {
  static const int x = 42;
  std::atomic_ref&lt;const int&gt; meow{x};
  meow.store(0);
  return meow.load();
}
</pre></blockquote>
<p>
Since <code>const int</code> is trivially copyable, this is a well-formed C++20 program that returns <code>0</code>.
That said, the <code>store</code> call that mutates the value of a constant object is (a) not implementable with
library technology, and (b) pure madness that violates the language semantics. <code>atomic_ref::store</code>
should presumably require <code>is_copy_assignable_v&lt;T&gt;</code>, and other operations need to have their
requirements audited as well. (Related: LWG <a href="lwg-defects.html#3012" title="atomic&lt;T&gt; is unimplementable for non-is_trivially_copy_constructible T (Status: C++20)">3012</a><sup><a href="https://cplusplus.github.io/LWG/issue3012" title="Latest snapshot">(i)</a></sup> made similar changes to <code>atomic</code>.)
<p/>
As a related issue, <code>volatile atomic&lt;T&gt;</code> recently had its member functions deprecated when they
are not lock-free. Presumably <code>atomic_ref&lt;volatile T&gt;</code> should require that atomic operations on
<code>T</code> be lock-free for consistency.
<p/>
<b>Jonathan:</b>
<p/>
The last point is related to LWG <a href="lwg-active.html#3417" title="Missing volatile atomic deprecations (Status: SG1)">3417</a><sup><a href="https://cplusplus.github.io/LWG/issue3417" title="Latest snapshot">(i)</a></sup> (another case where we screwed up the <code>volatile</code>
deprecations).
</p>

<p><i>[2020-12-19; Reflector prioritization]</i></p>

<p>
Set priority to 2 during reflector discussions. 
</p>

<p><i>[2024-06; Related to issue <a href="lwg-defects.html#4069" title="std::atomic&lt;volatile T&gt; should be ill-formed (Status: Resolved)">4069</a><sup><a href="https://cplusplus.github.io/LWG/issue4069" title="Latest snapshot">(i)</a></sup>.]</i></p>


<p><i>[St. Louis 2024-06-28; SG1 feedback]</i></p>

<p>
SG1 forwarded <a href="https://wg21.link/P3323R0" title=" cv-qualified types in atomic and atomic_ref">P3323R0</a> to LEWG to resolve LWG issues
<a href="lwg-defects.html#3508" title="atomic_ref&lt;cv T&gt; is not well-specified (Status: Resolved)">3508</a><sup><a href="https://cplusplus.github.io/LWG/issue3508" title="Latest snapshot">(i)</a></sup> and <a href="lwg-defects.html#4069" title="std::atomic&lt;volatile T&gt; should be ill-formed (Status: Resolved)">4069</a><sup><a href="https://cplusplus.github.io/LWG/issue4069" title="Latest snapshot">(i)</a></sup>.
</p>

<p><i>[2025-02-07 Status changed: Open &rarr; Resolved.]</i></p>

<p>Resolved by <a href="https://wg21.link/P3323R0" title=" cv-qualified types in atomic and atomic_ref">P3323R0</a> in Wrocław.</p>



<p id="res-3508"><b>Proposed resolution:</b></p>





</body>
</html>
