|
| 1 | +<?xml version='1.0' encoding='utf-8' standalone='no'?> |
| 2 | +<!DOCTYPE issue SYSTEM "lwg-issue.dtd"> |
| 3 | + |
| 4 | +<issue num="4194" status="New"> |
| 5 | +<title><tt>atomic<void*></tt> should use generic class template</title> |
| 6 | +<section><sref ref="[atomics.types.pointer]"/></section> |
| 7 | +<submitter>Gonzalo Brito</submitter> |
| 8 | +<date>16 Jan 2025</date> |
| 9 | +<priority>99</priority> |
| 10 | + |
| 11 | +<discussion> |
| 12 | +<p> |
| 13 | +<sref ref="[atomics.types.pointer]"/> p1 states (emphasis mine): |
| 14 | +</p> |
| 15 | +<blockquote style="border-left: 3px solid #ccc;padding-left: 15px;"> |
| 16 | +<p> |
| 17 | +There is a partial specialization of the `atomic` class template for <b>pointers</b>. |
| 18 | +</p> |
| 19 | +</blockquote> |
| 20 | +<p> |
| 21 | +which requires <tt>atomic<void*></tt> to use the `atomic` class template for pointers. |
| 22 | +However, the `fetch_add`/`_sub` member functions add a `difference_type` to a `T*` |
| 23 | +which requires a pointer-to-object type (these member functions are `constexpr`, |
| 24 | +so trying to support this seems unimplementable). |
| 25 | +<p/> |
| 26 | +For `atomic_ref`, the <sref ref="[atomics.ref.pointer]"/> p1 states (emphasis mine): |
| 27 | +</p> |
| 28 | +<blockquote style="border-left: 3px solid #ccc;padding-left: 15px;"> |
| 29 | +<p> |
| 30 | +There are specializations of the `atomic_ref`` class template for all <b>pointer-to-object types</b>. |
| 31 | +</p> |
| 32 | +</blockquote> |
| 33 | +<p> |
| 34 | +which avoids this issue and applying the same form to <sref ref="[atomics.types.pointer]"/> would make |
| 35 | +<tt>atomic<void*></tt> and <tt>atomic_ref<void*></tt> consistent. |
| 36 | +<p/> |
| 37 | +Technically this would be a breaking change, but all C++ standard library implementations surveyed are broken, |
| 38 | +and the proposed fix would make them compliant: see libstdc++, libc++ and MSVC STL errors |
| 39 | +<a href="https://godbolt.org/z/dso3P6fKf">here</a>. These standard libraries require a |
| 40 | +pointer-to-object type, <tt>atomic<void*></tt> uses the general template. Therefore, no user |
| 41 | +code seems to be impacted. |
| 42 | +</p> |
| 43 | +</discussion> |
| 44 | + |
| 45 | +<resolution> |
| 46 | +<p> |
| 47 | +This wording is relative to <paper num="N5001"/>. |
| 48 | +</p> |
| 49 | + |
| 50 | +<ol> |
| 51 | + |
| 52 | +<li><p>Modify <sref ref="[atomics.types.pointer]"/> as indicated:</p> |
| 53 | + |
| 54 | +<blockquote><p> |
| 55 | +-1- There is a partial specialization of the `atomic` class template for |
| 56 | +<del>pointers</del><ins>pointer-to-object types</ins>. Specializations of this partial |
| 57 | +specialization are standard-layout structs. They each have a trivial destructor. |
| 58 | +</p></blockquote> |
| 59 | +</li> |
| 60 | + |
| 61 | +</ol> |
| 62 | +</resolution> |
| 63 | + |
| 64 | +</issue> |
0 commit comments