diff --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt index 3431ea7dab386b..d37bfe57e22112 100644 --- a/libcxx/include/CMakeLists.txt +++ b/libcxx/include/CMakeLists.txt @@ -754,6 +754,7 @@ set(files __type_traits/decay.h __type_traits/dependent_type.h __type_traits/desugars_to.h + __type_traits/diagnostic_utilities.h __type_traits/disjunction.h __type_traits/enable_if.h __type_traits/extent.h diff --git a/libcxx/include/__memory/allocator.h b/libcxx/include/__memory/allocator.h index cd146da8e7eb5c..e65f308afa8c1d 100644 --- a/libcxx/include/__memory/allocator.h +++ b/libcxx/include/__memory/allocator.h @@ -14,11 +14,10 @@ #include <__memory/addressof.h> #include <__memory/allocate_at_least.h> #include <__memory/allocator_traits.h> -#include <__type_traits/is_const.h> +#include <__type_traits/diagnostic_utilities.h> #include <__type_traits/is_constant_evaluated.h> #include <__type_traits/is_same.h> #include <__type_traits/is_void.h> -#include <__type_traits/is_volatile.h> #include <__utility/forward.h> #include #include @@ -76,8 +75,7 @@ struct __non_trivial_if { template class _LIBCPP_TEMPLATE_VIS allocator : private __non_trivial_if::value, allocator<_Tp> > { - static_assert(!is_const<_Tp>::value, "std::allocator does not support const types"); - static_assert(!is_volatile<_Tp>::value, "std::allocator does not support volatile types"); + static_assert(__allocator_requirements::value); public: typedef size_t size_type; @@ -170,6 +168,8 @@ inline _LIBCPP_HIDE_FROM_ABI bool operator!=(const allocator<_Tp>&, const alloca #endif +_LIBCPP_DEFINE__ALLOCATOR_VALUE_TYPE_REQUIREMENTS(allocator, "allocate"); + _LIBCPP_END_NAMESPACE_STD #endif // _LIBCPP___MEMORY_ALLOCATOR_H diff --git a/libcxx/include/__type_traits/diagnostic_utilities.h b/libcxx/include/__type_traits/diagnostic_utilities.h new file mode 100644 index 00000000000000..2f3037e010d862 --- /dev/null +++ b/libcxx/include/__type_traits/diagnostic_utilities.h @@ -0,0 +1,94 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP___TYPE_TRAITS_DIAGNOSTIC_UTILITIES_H +#define _LIBCPP___TYPE_TRAITS_DIAGNOSTIC_UTILITIES_H + +#include <__config> +#include <__type_traits/decay.h> +#include <__type_traits/integral_constant.h> +#include <__type_traits/is_bounded_array.h> +#include <__type_traits/is_const.h> +#include <__type_traits/is_function.h> +#include <__type_traits/is_reference.h> +#include <__type_traits/is_same.h> +#include <__type_traits/is_unbounded_array.h> +#include <__type_traits/is_void.h> +#include <__type_traits/is_volatile.h> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +// Many templates require their type parameters to be cv-unqualified objects. +template