<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 4069: std::atomic&lt;volatile T&gt; should be ill-formed</title>
<meta property="og:title" content="Issue 4069: std::atomic&lt;volatile T&gt; should be ill-formed">
<meta property="og:description" content="C++ library issue. Status: Resolved">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue4069.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="4069"><a href="lwg-defects.html#4069">4069</a>. <code>std::atomic&lt;volatile T&gt;</code> should be ill-formed</h3>
<p><b>Section:</b> 32.5.8 <a href="https://wg21.link/atomics.types.generic">[atomics.types.generic]</a> <b>Status:</b> <a href="lwg-active.html#Resolved">Resolved</a>
 <b>Submitter:</b> Jonathan Wakely <b>Opened:</b> 2024-04-19 <b>Last modified:</b> 2025-02-07</p>
<p><b>Priority: </b>2
</p>
<p><b>View all other</b> <a href="lwg-index.html#atomics.types.generic">issues</a> in [atomics.types.generic].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#Resolved">Resolved</a> status.</p>
<p><b>Discussion:</b></p>
<p>
As a result of <a href="https://wg21.link/cwg2094" title="2094. Trivial copy/move constructor for class with volatile member. Status: C++17">Core DR 2094</a>
(concerning triviality of volatile-qualified subobjects),
<code>is_trivially_copyable_v&lt;volatile int&gt;</code> is now true,
which means that <code class='backtick'>volatile int</code> is a valid type for <code class='backtick'>std::atomic</code>.
</p>
<p>
Libstdc++ and libc++ can't actually compile that type though,
and that seems very sensible to me.
</p>

<p>
Even worse is that <code>std::atomic&lt;volatile int&gt;</code> will not
select the specialization for <code class='backtick'>int</code>, because that is clearly specified by
32.5.8.3 <a href="https://wg21.link/atomics.types.int">[atomics.types.int]</a> to only be for cv-unqualified types.
32.5.8.4 <a href="https://wg21.link/atomics.types.float">[atomics.types.float]</a> also says it's only for cv-unqualified
floating-point types. And 32.5.8.5 <a href="https://wg21.link/atomics.types.pointer">[atomics.types.pointer]</a> will only
match cv-unqualified pointer types.
This means that even when <code>std::atomic&lt;volatile int&gt;</code>
compiles (as with MSVC) you can't use members like <code class='backtick'>fetch_add</code> because that
only exists on the specialization, not the primary template.
</p>

<p>
Should we add something to <code class='backtick'>std::atomic</code> to make it not valid again,
as was the case (and presumably the original intent) before CWG DR 2094?
</p>

<p>
A similar question exists for <code>std::atomic_ref&lt;volatile int&gt;</code>
although there are apparently valid uses for that type. However, the
<code class='backtick'>atomic_ref</code> specializations for integers, floats, and pointers are only
for cv-unqualified types, so it doesn't work usefully.
For <code class='backtick'>atomic_ref</code> we might want to allow <code class='backtick'>volatile</code>-qualified types <em>and</em>
make the specializations match them.
</p>

<p><i>[2024-04-29; Reflector poll]</i></p>

<p>
Set priority to 2 after reflector poll and send to SG1.
</p>

<p><i>[2024-06; Related to issue <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>.]</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-4069"><b>Proposed resolution:</b></p>
<p>
</p>





</body>
</html>
