From 2ef83da01b9a8849fb94c32608819b51bbbb91a7 Mon Sep 17 00:00:00 2001
From: Damien L-G <dalg24@gmail.com>
Date: Wed, 22 May 2024 17:43:45 -0400
Subject: [PATCH] libstdc++: the specialization atomic_ref<bool> should use the
 primary template

Per [[atomics.ref.int]](https://eel.is/c++draft/atomics.ref.generic#atomics.ref.int)
`bool` is excluded from the list of integral types for wich there is a
specialization of the `atomic_ref` class template and
[*Note 1*](https://eel.is/c++draft/atomics.ref.generic#atomics.ref.int-note-1)
clearly states that `atomic_ref<bool>` "uses the primary template"
instead.

```c++
void test() {
    bool x = true;
    std::atomic_ref const a{x};
    a &= false;  // error should indicate that the compiler
                 // could not find a matching 'operator&='
                 // but currently fails in the instantiation
                 // of implementation details.
}
```
I also expect that one should be able to detect that all the
`fetch_<key>` member functions and other arithmetic operators are not
valid expressions.  Maybe that could be the basis for testing the
correct behavior is implemented.  See https://godbolt.org/z/1eor9TbYj

Signed-off-by: Damien L-G <dalg24@gmail.com>
---
 libstdc++-v3/include/bits/atomic_base.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libstdc++-v3/include/bits/atomic_base.h b/libstdc++-v3/include/bits/atomic_base.h
index 062f1549740..7c342d3bcd0 100644
--- a/libstdc++-v3/include/bits/atomic_base.h
+++ b/libstdc++-v3/include/bits/atomic_base.h
@@ -1478,7 +1478,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 #undef _GLIBCXX20_INIT
 
   template<typename _Tp,
-	   bool = is_integral_v<_Tp>, bool = is_floating_point_v<_Tp>>
+           bool = is_integral_v<_Tp> && !is_same_v<_Tp, bool>,
+           bool = is_floating_point_v<_Tp>>
     struct __atomic_ref;
 
   // base class for non-integral, non-floating-point, non-pointer types
-- 
2.39.3 (Apple Git-146)

