Title
polymorphic_allocator::allocate_object and new_object should be [[nodiscard]]
Status
dup
Section
[mem.poly.allocator.class]
Submitter
United States

Created on 2019-11-04.00:00:00 last changed 62 months ago

Messages

Date: 2019-11-07.08:20:25

Proposed resolution:

This wording is relative to N4835.

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

    // [mem.poly.allocator.mem], member functions
    [[nodiscard]] Tp* allocate(size_t n);
    void deallocate(Tp* p, size_t n);
    
    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:

    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: 2019-11-07.08:20:25

[ 2019-11 Status to Duplicate during Tuesday morning issue processing in Belfast. ]

Duplicate of 3304.

Date: 2019-11-04.19:27:15

[ Daniel comments ]

This issue is related to LWG 3304.

Date: 2019-11-04.00:00:00

Addresses US 217

Add [[nodiscard]] in front of the return type for allocate_object and new_object in class declaration and in member-function description for polymorphic_allocator template.

History
Date User Action Args
2019-11-07 08:20:25adminsetmessages: + msg10785
2019-11-07 08:20:25adminsetstatus: new -> dup
2019-11-04 19:27:15adminsetmessages: + msg10738
2019-11-04 19:27:15adminsetmessages: + msg10737
2019-11-04 00:00:00admincreate