]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++, c++/reflection: mark {,de}allocate constexpr
authorMarek Polacek <polacek@redhat.com>
Mon, 2 Feb 2026 16:05:16 +0000 (11:05 -0500)
committerMarek Polacek <polacek@redhat.com>
Tue, 3 Feb 2026 20:15:52 +0000 (15:15 -0500)
[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>
gcc/cp/constexpr.cc
gcc/cp/cp-tree.h
gcc/cp/reflect.cc
libstdc++-v3/include/bits/new_allocator.h

index a31fe6b113a9ea23432e837db920e5a934fd9752..a5ccd276a88f3281c300d85e22d52dbdca4dcfbe 100644 (file)
@@ -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);
index 59ab4e40430d4521cd2b62407aa3bef0ef7aa218..1045dfd60143be73be2e01465190c181f66cc724 100644 (file)
@@ -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);
index bc69bdad73b63a34a9dbd7ffdc38d87bbcded40f..3cf4c31ad627e5e9deb9fc9d73254360f3cdd700 100644 (file)
@@ -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");
index 5701b8dd254779be8a23d0250d9fd762377bf3ed..4fe67f99e5c0df4eae0fa9485f85a13173003723 100644 (file)
@@ -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