]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Avoid including <cstdint> for std::char_traits
authorJonathan Wakely <jwakely@redhat.com>
Thu, 19 May 2022 11:50:28 +0000 (12:50 +0100)
committerJonathan Wakely <jwakely@redhat.com>
Thu, 19 May 2022 22:39:21 +0000 (23:39 +0100)
We should prefer the __UINT_LEAST16_TYPE__ and __UINT_LEAST32_TYPE__
macros, if available, so that we don't need all of <cstdint> in every
header that uses std::char_traits.

libstdc++-v3/ChangeLog:

* include/bits/char_traits.h: Only include <cstdint> when
necessary.
* include/std/stacktrace: Use __UINTPTR_TYPE__ instead of
uintptr_t.
* src/c++11/cow-stdexcept.cc: Include <stdint.h>.
* src/c++17/floating_to_chars.cc: Likewise.
* testsuite/20_util/assume_aligned/1.cc: Include <cstdint>.
* testsuite/20_util/assume_aligned/3.cc: Likewise.
* testsuite/20_util/shared_ptr/creation/array.cc: Likewise.

libstdc++-v3/include/bits/char_traits.h
libstdc++-v3/include/std/stacktrace
libstdc++-v3/src/c++11/cow-stdexcept.cc
libstdc++-v3/src/c++17/floating_to_chars.cc
libstdc++-v3/testsuite/20_util/assume_aligned/1.cc
libstdc++-v3/testsuite/20_util/assume_aligned/3.cc
libstdc++-v3/testsuite/20_util/shared_ptr/creation/array.cc

index cac1326d4b58e9766998575c254ef9d14157a6c5..b856b1da3203faa1afe47328e371e4c7b3f64520 100644 (file)
@@ -40,6 +40,9 @@
 #include <cwchar>               // For WEOF, wmemmove, wmemset, etc.
 #if __cplusplus >= 201103L
 # include <type_traits>
+#if !defined __UINT_LEAST16_TYPE__ || !defined __UINT_LEAST32_TYPE__
+# include <cstdint>
+#endif
 #endif
 #if __cplusplus >= 202002L
 # include <compare>
@@ -728,8 +731,6 @@ _GLIBCXX_END_NAMESPACE_VERSION
 
 #if __cplusplus >= 201103L
 
-#include <cstdint>
-
 namespace std _GLIBCXX_VISIBILITY(default)
 {
 _GLIBCXX_BEGIN_NAMESPACE_VERSION
@@ -738,10 +739,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     struct char_traits<char16_t>
     {
       typedef char16_t          char_type;
-#ifdef _GLIBCXX_USE_C99_STDINT_TR1
-      typedef uint_least16_t    int_type;
-#elif defined __UINT_LEAST16_TYPE__
+#ifdef __UINT_LEAST16_TYPE__
       typedef __UINT_LEAST16_TYPE__        int_type;
+#elif defined _GLIBCXX_USE_C99_STDINT_TR1
+      typedef uint_least16_t    int_type;
 #else
       typedef make_unsigned<char16_t>::type int_type;
 #endif
@@ -859,10 +860,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     struct char_traits<char32_t>
     {
       typedef char32_t          char_type;
-#ifdef _GLIBCXX_USE_C99_STDINT_TR1
-      typedef uint_least32_t    int_type;
-#elif defined __UINT_LEAST32_TYPE__
+#ifdef __UINT_LEAST32_TYPE__
       typedef __UINT_LEAST32_TYPE__        int_type;
+#elif defined _GLIBCXX_USE_C99_STDINT_TR1
+      typedef uint_least32_t    int_type;
 #else
       typedef make_unsigned<char32_t>::type int_type;
 #endif
index 1efaf253abb63d29e2128d4cc657302a4956a91e..39472d7236aa1c99c0a93296c35a4a28e271e315 100644 (file)
@@ -52,20 +52,20 @@ __glibcxx_backtrace_create_state(const char*, int,
 
 int
 __glibcxx_backtrace_simple(__glibcxx_backtrace_state*, int,
-                          int (*) (void*, uintptr_t),
+                          int (*) (void*, __UINTPTR_TYPE__),
                           void(*)(void*, const char*, int),
                           void*);
 int
-__glibcxx_backtrace_pcinfo(__glibcxx_backtrace_state*, uintptr_t,
-                          int (*)(void*, uintptr_t,
+__glibcxx_backtrace_pcinfo(__glibcxx_backtrace_state*, __UINTPTR_TYPE__,
+                          int (*)(void*, __UINTPTR_TYPE__,
                                   const char*, int, const char*),
                           void(*)(void*, const char*, int),
                           void*);
 
 int
-__glibcxx_backtrace_syminfo(__glibcxx_backtrace_state*, uintptr_t addr,
-                           void (*) (void*, uintptr_t, const char*,
-                                     uintptr_t, uintptr_t),
+__glibcxx_backtrace_syminfo(__glibcxx_backtrace_state*, __UINTPTR_TYPE__ addr,
+                           void (*) (void*, __UINTPTR_TYPE__, const char*,
+                                     __UINTPTR_TYPE__, __UINTPTR_TYPE__),
                            void(*)(void*, const char*, int),
                            void*);
 }
@@ -225,6 +225,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     class basic_stacktrace
     {
       using _AllocTraits = allocator_traits<_Allocator>;
+      using uintptr_t = __UINTPTR_TYPE__;
 
     public:
       using value_type = stacktrace_entry;
index 5ccf2ca2d74bd7a90034e55650fd1f5e9e90d9e4..9e8787485eb17e57eca4611d6db2b6a0df7d6b25 100644 (file)
@@ -200,6 +200,10 @@ _GLIBCXX_END_NAMESPACE_VERSION
 #if _GLIBCXX_USE_WEAK_REF
 #ifdef _GLIBCXX_USE_C99_STDINT_TR1
 
+#include <stdint.h>
+
+using std::size_t;
+
 extern "C" {
 
 #ifndef _GLIBCXX_MANGLE_SIZE_T
index 4599d68a39c04af91f6877ec6e6da6abd17855be..b1c915e8a68d2d31e157b2d7c598a4ac1ac3bdd6 100644 (file)
@@ -85,6 +85,8 @@ using F128_type = __float128;
 using F128_type = void;
 #endif
 
+#include <stdint.h>
+
 namespace
 {
 #if defined __SIZEOF_INT128__
index 59379582cf906aa3f49b8fb2b0aa038cb25fc02c..0a1390d18e4cdbbbaacd2ee132485d14504bf9eb 100644 (file)
@@ -19,6 +19,7 @@
 // { dg-do run { target c++2a } }
 
 #include <memory>
+#include <cstdint>
 #include <testsuite_hooks.h>
 
 void
index e1abf17e90a9dad8ecb390c11640d5052424f30c..93ee86c666e1d6e0dd09bd81c2c9451b27cbbc5c 100644 (file)
@@ -20,6 +20,7 @@
 // { dg-final { scan-assembler-not "undefined" } }
 
 #include <memory>
+#include <cstdint>
 
 int* ptr();
 extern "C" void undefined();
index cd614c0ce0a87950fab5996505b70f55120f1101..5c11a8b6285b35260572f04aa19886270a8f459b 100644 (file)
@@ -65,6 +65,7 @@ test02()
 }
 
 #include <vector>
+#include <cstdint>
 
 std::vector<std::uintptr_t> addresses;