This will probably need a gcc-15/porting_to.html entry at some point.
Every time we remove transitive includes of <cstdint> it breaks
somebody!

Tested x86_64-linux. Pushed to trunk.

-- >8 --

We don't need to include all of <stdint.h> when we only need uintptr_t
from it. By using GCC's internal macro we avoid unnecessarily declaring
everything in <stdint.h>. This helps users to avoid accidentally relying
on those names being declared without explicitly including the header.

libstdc++-v3/ChangeLog:

        * include/bits/align.h (align, assume_aligned): Use
        __UINTPTR_TYPE__ instead of uintptr_t. Do not include
        <stdint.h>.
        * include/bits/atomic_base.h (__atomic_ref): Likewise.
        * include/bits/atomic_wait.h (__waiter_pool_base::_S_for):
        Likewise.
        * include/std/atomic: Include <cstdint>.
---
 libstdc++-v3/include/bits/align.h       |  5 ++---
 libstdc++-v3/include/bits/atomic_base.h | 17 ++++++++++++-----
 libstdc++-v3/include/bits/atomic_wait.h |  4 ++--
 libstdc++-v3/include/std/atomic         |  1 +
 4 files changed, 17 insertions(+), 10 deletions(-)

diff --git a/libstdc++-v3/include/bits/align.h 
b/libstdc++-v3/include/bits/align.h
index 1a06b814fbb..0c64584b27f 100644
--- a/libstdc++-v3/include/bits/align.h
+++ b/libstdc++-v3/include/bits/align.h
@@ -31,7 +31,6 @@
 #define _GLIBCXX_ALIGN_H 1
 
 #include <bit>          // std::has_single_bit
-#include <stdint.h>     // uintptr_t
 #include <debug/assertions.h> // _GLIBCXX_DEBUG_ASSERT
 #include <bits/version.h>
 
@@ -62,7 +61,7 @@ align(size_t __align, size_t __size, void*& __ptr, size_t& 
__space) noexcept
 {
   if (__space < __size)
     return nullptr;
-  const auto __intptr = reinterpret_cast<uintptr_t>(__ptr);
+  const auto __intptr = reinterpret_cast<__UINTPTR_TYPE__>(__ptr);
   const auto __aligned = (__intptr - 1u + __align) & -__align;
   const auto __diff = __aligned - __intptr;
   if (__diff > (__space - __size))
@@ -97,7 +96,7 @@ align(size_t __align, size_t __size, void*& __ptr, size_t& 
__space) noexcept
        {
          // This function is expected to be used in hot code, where
          // __glibcxx_assert would add unwanted overhead.
-         _GLIBCXX_DEBUG_ASSERT((uintptr_t)__ptr % _Align == 0);
+         _GLIBCXX_DEBUG_ASSERT((__UINTPTR_TYPE__)__ptr % _Align == 0);
          return static_cast<_Tp*>(__builtin_assume_aligned(__ptr, _Align));
        }
     }
diff --git a/libstdc++-v3/include/bits/atomic_base.h 
b/libstdc++-v3/include/bits/atomic_base.h
index ae6819f119b..7c27bd8c951 100644
--- a/libstdc++-v3/include/bits/atomic_base.h
+++ b/libstdc++-v3/include/bits/atomic_base.h
@@ -34,7 +34,6 @@
 
 #include <bits/c++config.h>
 #include <new> // For placement new
-#include <stdint.h>
 #include <bits/atomic_lockfree_defines.h>
 #include <bits/move.h>
 
@@ -1504,7 +1503,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
       explicit
       __atomic_ref(_Tp& __t) : _M_ptr(std::__addressof(__t))
-      { __glibcxx_assert(((uintptr_t)_M_ptr % required_alignment) == 0); }
+      {
+       __glibcxx_assert(((__UINTPTR_TYPE__)_M_ptr % required_alignment) == 0);
+      }
 
       __atomic_ref(const __atomic_ref&) noexcept = default;
 
@@ -1615,7 +1616,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
       explicit
       __atomic_ref(_Tp& __t) : _M_ptr(&__t)
-      { __glibcxx_assert(((uintptr_t)_M_ptr % required_alignment) == 0); }
+      {
+       __glibcxx_assert(((__UINTPTR_TYPE__)_M_ptr % required_alignment) == 0);
+      }
 
       __atomic_ref(const __atomic_ref&) noexcept = default;
 
@@ -1788,7 +1791,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
       explicit
       __atomic_ref(_Fp& __t) : _M_ptr(&__t)
-      { __glibcxx_assert(((uintptr_t)_M_ptr % required_alignment) == 0); }
+      {
+       __glibcxx_assert(((__UINTPTR_TYPE__)_M_ptr % required_alignment) == 0);
+      }
 
       __atomic_ref(const __atomic_ref&) noexcept = default;
 
@@ -1915,7 +1920,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
       explicit
       __atomic_ref(_Tp*& __t) : _M_ptr(std::__addressof(__t))
-      { __glibcxx_assert(((uintptr_t)_M_ptr % required_alignment) == 0); }
+      {
+       __glibcxx_assert(((__UINTPTR_TYPE__)_M_ptr % required_alignment) == 0);
+      }
 
       __atomic_ref(const __atomic_ref&) noexcept = default;
 
diff --git a/libstdc++-v3/include/bits/atomic_wait.h 
b/libstdc++-v3/include/bits/atomic_wait.h
index 6c98f3963ad..f1c183f9dbb 100644
--- a/libstdc++-v3/include/bits/atomic_wait.h
+++ b/libstdc++-v3/include/bits/atomic_wait.h
@@ -250,9 +250,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       static __waiter_pool_base&
       _S_for(const void* __addr) noexcept
       {
-       constexpr uintptr_t __ct = 16;
+       constexpr __UINTPTR_TYPE__ __ct = 16;
        static __waiter_pool_base __w[__ct];
-       auto __key = (uintptr_t(__addr) >> 2) % __ct;
+       auto __key = ((__UINTPTR_TYPE__)__addr >> 2) % __ct;
        return __w[__key];
       }
     };
diff --git a/libstdc++-v3/include/std/atomic b/libstdc++-v3/include/std/atomic
index 1462cf5ec23..36ff89a146c 100644
--- a/libstdc++-v3/include/std/atomic
+++ b/libstdc++-v3/include/std/atomic
@@ -48,6 +48,7 @@
 #include <bits/version.h>
 
 #include <bits/atomic_base.h>
+#include <cstdint>
 
 namespace std _GLIBCXX_VISIBILITY(default)
 {
-- 
2.45.2

Reply via email to