libstdc++: Avoid including <cstdint> for std::char_traits

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.
This commit is contained in:
Jonathan Wakely 2022-05-19 12:50:28 +01:00
parent f3e22baec0
commit 6f038efd93
7 changed files with 25 additions and 14 deletions

View File

@ -40,6 +40,9 @@
#include <cwchar> // For WEOF, wmemmove, wmemset, etc. #include <cwchar> // For WEOF, wmemmove, wmemset, etc.
#if __cplusplus >= 201103L #if __cplusplus >= 201103L
# include <type_traits> # include <type_traits>
#if !defined __UINT_LEAST16_TYPE__ || !defined __UINT_LEAST32_TYPE__
# include <cstdint>
#endif
#endif #endif
#if __cplusplus >= 202002L #if __cplusplus >= 202002L
# include <compare> # include <compare>
@ -728,8 +731,6 @@ _GLIBCXX_END_NAMESPACE_VERSION
#if __cplusplus >= 201103L #if __cplusplus >= 201103L
#include <cstdint>
namespace std _GLIBCXX_VISIBILITY(default) namespace std _GLIBCXX_VISIBILITY(default)
{ {
_GLIBCXX_BEGIN_NAMESPACE_VERSION _GLIBCXX_BEGIN_NAMESPACE_VERSION
@ -738,10 +739,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
struct char_traits<char16_t> struct char_traits<char16_t>
{ {
typedef char16_t char_type; typedef char16_t char_type;
#ifdef _GLIBCXX_USE_C99_STDINT_TR1 #ifdef __UINT_LEAST16_TYPE__
typedef uint_least16_t int_type;
#elif defined __UINT_LEAST16_TYPE__
typedef __UINT_LEAST16_TYPE__ int_type; typedef __UINT_LEAST16_TYPE__ int_type;
#elif defined _GLIBCXX_USE_C99_STDINT_TR1
typedef uint_least16_t int_type;
#else #else
typedef make_unsigned<char16_t>::type int_type; typedef make_unsigned<char16_t>::type int_type;
#endif #endif
@ -859,10 +860,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
struct char_traits<char32_t> struct char_traits<char32_t>
{ {
typedef char32_t char_type; typedef char32_t char_type;
#ifdef _GLIBCXX_USE_C99_STDINT_TR1 #ifdef __UINT_LEAST32_TYPE__
typedef uint_least32_t int_type;
#elif defined __UINT_LEAST32_TYPE__
typedef __UINT_LEAST32_TYPE__ int_type; typedef __UINT_LEAST32_TYPE__ int_type;
#elif defined _GLIBCXX_USE_C99_STDINT_TR1
typedef uint_least32_t int_type;
#else #else
typedef make_unsigned<char32_t>::type int_type; typedef make_unsigned<char32_t>::type int_type;
#endif #endif

View File

@ -52,20 +52,20 @@ __glibcxx_backtrace_create_state(const char*, int,
int int
__glibcxx_backtrace_simple(__glibcxx_backtrace_state*, int, __glibcxx_backtrace_simple(__glibcxx_backtrace_state*, int,
int (*) (void*, uintptr_t), int (*) (void*, __UINTPTR_TYPE__),
void(*)(void*, const char*, int), void(*)(void*, const char*, int),
void*); void*);
int int
__glibcxx_backtrace_pcinfo(__glibcxx_backtrace_state*, uintptr_t, __glibcxx_backtrace_pcinfo(__glibcxx_backtrace_state*, __UINTPTR_TYPE__,
int (*)(void*, uintptr_t, int (*)(void*, __UINTPTR_TYPE__,
const char*, int, const char*), const char*, int, const char*),
void(*)(void*, const char*, int), void(*)(void*, const char*, int),
void*); void*);
int int
__glibcxx_backtrace_syminfo(__glibcxx_backtrace_state*, uintptr_t addr, __glibcxx_backtrace_syminfo(__glibcxx_backtrace_state*, __UINTPTR_TYPE__ addr,
void (*) (void*, uintptr_t, const char*, void (*) (void*, __UINTPTR_TYPE__, const char*,
uintptr_t, uintptr_t), __UINTPTR_TYPE__, __UINTPTR_TYPE__),
void(*)(void*, const char*, int), void(*)(void*, const char*, int),
void*); void*);
} }
@ -225,6 +225,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
class basic_stacktrace class basic_stacktrace
{ {
using _AllocTraits = allocator_traits<_Allocator>; using _AllocTraits = allocator_traits<_Allocator>;
using uintptr_t = __UINTPTR_TYPE__;
public: public:
using value_type = stacktrace_entry; using value_type = stacktrace_entry;

View File

@ -200,6 +200,10 @@ _GLIBCXX_END_NAMESPACE_VERSION
#if _GLIBCXX_USE_WEAK_REF #if _GLIBCXX_USE_WEAK_REF
#ifdef _GLIBCXX_USE_C99_STDINT_TR1 #ifdef _GLIBCXX_USE_C99_STDINT_TR1
#include <stdint.h>
using std::size_t;
extern "C" { extern "C" {
#ifndef _GLIBCXX_MANGLE_SIZE_T #ifndef _GLIBCXX_MANGLE_SIZE_T

View File

@ -85,6 +85,8 @@ using F128_type = __float128;
using F128_type = void; using F128_type = void;
#endif #endif
#include <stdint.h>
namespace namespace
{ {
#if defined __SIZEOF_INT128__ #if defined __SIZEOF_INT128__

View File

@ -19,6 +19,7 @@
// { dg-do run { target c++2a } } // { dg-do run { target c++2a } }
#include <memory> #include <memory>
#include <cstdint>
#include <testsuite_hooks.h> #include <testsuite_hooks.h>
void void

View File

@ -20,6 +20,7 @@
// { dg-final { scan-assembler-not "undefined" } } // { dg-final { scan-assembler-not "undefined" } }
#include <memory> #include <memory>
#include <cstdint>
int* ptr(); int* ptr();
extern "C" void undefined(); extern "C" void undefined();

View File

@ -65,6 +65,7 @@ test02()
} }
#include <vector> #include <vector>
#include <cstdint>
std::vector<std::uintptr_t> addresses; std::vector<std::uintptr_t> addresses;