diff options
| author | Marek Polacek <polacek@redhat.com> | 2026-02-02 11:05:16 -0500 |
|---|---|---|
| committer | Marek Polacek <polacek@redhat.com> | 2026-02-03 15:15:52 -0500 |
| commit | 7197d0cce705254d0779a81bdad82d5a71b7f63b (patch) | |
| tree | 9c957cfce0bef1383a0e5dfd6917b2a93b7498da | |
| parent | 3c3c7f6519f54d26afdb9bd810cc7bc11b395a53 (diff) | |
| download | gcc-trunk.zip gcc-trunk.tar.gz gcc-trunk.tar.bz2 | |
[allocator.members] says that allocator::{,de}allocate should be
constexpr but currently we don't mark them as such. I had to
work around that in the Reflection code, but it would be better to
clean this up. (I see no allocation_result so I'm not changing that.)
gcc/cp/ChangeLog:
* constexpr.cc (is_std_allocator): Don't check for __new_allocator.
(is_std_allocator_allocate): Make static.
* cp-tree.h (is_std_allocator_allocate): Remove declaration.
* reflect.cc (check_out_of_consteval_use): Don't call
is_std_allocator_allocate.
(check_consteval_only_fn): Likewise.
libstdc++-v3/ChangeLog:
* include/bits/new_allocator.h (__new_allocator::allocate,
__new_allocator::deallocate): Add missing constexpr.
Reviewed-by: Jason Merrill <jason@redhat.com>
Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
| -rw-r--r-- | gcc/cp/constexpr.cc | 6 | ||||
| -rw-r--r-- | gcc/cp/cp-tree.h | 1 | ||||
| -rw-r--r-- | gcc/cp/reflect.cc | 9 | ||||
| -rw-r--r-- | libstdc++-v3/include/bits/new_allocator.h | 4 |
4 files changed, 7 insertions, 13 deletions
diff --git a/gcc/cp/constexpr.cc b/gcc/cp/constexpr.cc index a31fe6b..a5ccd27 100644 --- a/gcc/cp/constexpr.cc +++ b/gcc/cp/constexpr.cc @@ -3247,14 +3247,12 @@ is_std_class (tree ctx, const char *name) bool is_std_allocator (tree ctx) { - return (is_std_class (ctx, "allocator") - || (flag_reflection - && is_std_class (ctx, "__new_allocator"))); + return is_std_class (ctx, "allocator"); } /* Return true if FNDECL is std::allocator<T>::{,de}allocate. */ -bool +static bool is_std_allocator_allocate (tree fndecl) { tree name = DECL_NAME (fndecl); diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index 59ab4e4..1045dfd 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -9259,7 +9259,6 @@ extern bool is_nondependent_static_init_expression (tree); extern bool is_static_init_expression (tree); extern bool is_std_class (tree, const char *); extern bool is_std_allocator (tree); -extern bool is_std_allocator_allocate (tree); extern bool potential_rvalue_constant_expression (tree); extern bool require_potential_constant_expression (tree); extern bool require_constant_expression (tree); diff --git a/gcc/cp/reflect.cc b/gcc/cp/reflect.cc index bc69bda..3cf4c31 100644 --- a/gcc/cp/reflect.cc +++ b/gcc/cp/reflect.cc @@ -8152,11 +8152,9 @@ check_out_of_consteval_use (tree expr, bool complain/*=true*/) if (!consteval_only_p (t)) return NULL_TREE; + /* Already escalated? */ if (current_function_decl - /* Already escalated. */ - && (DECL_IMMEDIATE_FUNCTION_P (current_function_decl) - /* These functions are magic. */ - || is_std_allocator_allocate (current_function_decl))) + && DECL_IMMEDIATE_FUNCTION_P (current_function_decl)) { *walk_subtrees = false; return NULL_TREE; @@ -8298,8 +8296,7 @@ check_consteval_only_fn (tree decl) if (!DECL_IMMEDIATE_FUNCTION_P (decl) && consteval_only_p (decl) /* But if the function can be escalated, merrily we roll along. */ - && !immediate_escalating_function_p (decl) - && !is_std_allocator_allocate (decl)) + && !immediate_escalating_function_p (decl)) error_at (DECL_SOURCE_LOCATION (decl), "function of consteval-only type must be declared %qs", "consteval"); diff --git a/libstdc++-v3/include/bits/new_allocator.h b/libstdc++-v3/include/bits/new_allocator.h index 5701b8d..4fe67f9 100644 --- a/libstdc++-v3/include/bits/new_allocator.h +++ b/libstdc++-v3/include/bits/new_allocator.h @@ -122,7 +122,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // NB: __n is permitted to be 0. The C++ standard says nothing // about what the return value is when __n == 0. - _GLIBCXX_NODISCARD _Tp* + _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR _Tp* allocate(size_type __n, const void* = static_cast<const void*>(0)) { #if __cplusplus >= 201103L @@ -152,7 +152,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } // __p is not permitted to be a null pointer. - void + _GLIBCXX20_CONSTEXPR void deallocate(_Tp* __p, size_type __n __attribute__ ((__unused__))) { #if __cpp_sized_deallocation |
