Title
Allocate functions of std::polymorphic_allocator should require [[nodiscard]]
Status
c++20
Section
[mem.poly.allocator.class]
Submitter
Hiroaki Ando

Created on 2019-10-16.00:00:00 last changed 46 months ago

Messages

Date: 2020-01-07.16:01:55

Proposed resolution:

This wording is relative to N4835.

  1. Modify [mem.poly.allocator.class], class template polymorphic_allocator synopsis, as indicated:

    namespace std::pmr {
      template<class Tp = byte> class polymorphic_allocator {
        […]
        // [mem.poly.allocator.mem], member functions
        [[nodiscard]] Tp* allocate(size_t n);
        void deallocate(Tp* p, size_t n);
    
        [[nodiscard]] void* allocate_bytes(size_t nbytes, size_t alignment = alignof(max_align_t));
        void deallocate_bytes(void* p, size_t nbytes, size_t alignment = alignof(max_align_t));
        template<class T> [[nodiscard]] T* allocate_object(size_t n = 1);
        template<class T> void deallocate_object(T* p, size_t n = 1);
        template<class T, class... CtorArgs> [[nodiscard]] T* new_object(CtorArgs&&... ctor_args);
        template<class T> void delete_object(T* p);  
        […]
      };  
    }
    
  2. Modify [mem.poly.allocator.mem] as indicated:

    [[nodiscard]] void* allocate_bytes(size_t nbytes, size_t alignment = alignof(max_align_t));
    

    -5- Effects: Equivalent to: return memory_rsrc->allocate(nbytes, alignment);

    […]

    […]
    template<class T>
      [[nodiscard]] T* allocate_object(size_t n = 1);
    

    -8- Effects: Allocates memory suitable for holding an array of n objects of type T, as follows:

    1. (8.1) — if SIZE_MAX / sizeof(T) < n, throws length_error,

    2. (8.2) — otherwise equivalent to:

      return static_cast<T*>(allocate_bytes(n*sizeof(T), alignof(T)));
      

    […]

    template<class T, class CtorArgs...>
      [[nodiscard]] T* new_object(CtorArgs&&... ctor_args);
    

    -11- Effects: Allocates and constructs an object of type T, as follows. Equivalent to:

    T* p = allocate_object<T>();
    try {
      construct(p, std::forward<CtorArgs>(ctor_args)...);
    } catch (...) {
      deallocate_object(p);
      throw;
    }
    return p;
    

    […]

Date: 2020-01-07.16:01:55

[ 2019-11; Friday AM in Belfast. Status changed to "Ready" ]

Date: 2019-11-15.00:00:00

[ 2019-11-4; Daniel comments ]

This issue is related to LWG 3312.

Date: 2019-11-04.14:01:07

[ 2019-11 After discussion with LEWG, assigning to LEWG ]

Date: 2019-11-04.13:23:43

[ 2019-11 Priority to 3 during Monday issue prioritization in Belfast ]

Date: 2019-10-16.00:00:00

[[nodiscard]] is specified for std::polymorphic_allocator<>::allocate().

But the allocate functions added with P0339R6 doesn't have it.

Isn't [[nodiscard]] necessary for these functions?

History
Date User Action Args
2021-02-25 10:48:01adminsetstatus: wp -> c++20
2020-02-24 16:02:59adminsetstatus: voting -> wp
2020-01-17 04:54:50adminsetstatus: ready -> voting
2020-01-07 16:01:55adminsetmessages: + msg10921
2020-01-07 16:01:55adminsetstatus: lewg -> ready
2019-11-04 19:27:52adminsetmessages: + msg10739
2019-11-04 14:01:07adminsetmessages: + msg10730
2019-11-04 14:01:07adminsetstatus: new -> lewg
2019-11-04 13:23:43adminsetmessages: + msg10724
2019-10-19 12:06:05adminsetmessages: + msg10705
2019-10-16 00:00:00admincreate