3035. std::allocator's constructors should be constexpr

Section: 23.10.10 [default.allocator] Status: Tentatively Ready Submitter: Geoffrey Romer Opened: 2017-11-11 Last modified: 2017-11-25

Priority: Not Prioritized

View all other issues in [default.allocator].

View all issues with Tentatively Ready status.

Discussion:

std::allocator's constructors should be constexpr. It's expected to be an empty class as far as I know, so this should impose no implementation burden, and it would be useful to permit guaranteed static initialization of objects that need to hold a std::allocator, but don't have to actually use it until after construction.

[ 2017-11-25 Moved to Tentatively Ready after 7 positive votes for P0 on c++std-lib. ]

Proposed resolution:

This wording is relative to N4700.

  1. Change in 23.10.10 [default.allocator] as indicated:

    namespace std {
      template <class T> class allocator {
      public:
        using value_type = T;
        using propagate_on_container_move_assignment = true_type;
        using is_always_equal = true_type;
        constexpr allocator() noexcept;
        constexpr allocator(const allocator&) noexcept;
        constexpr template <class U> allocator(const allocator<U>&) noexcept;
        ~allocator();
        T* allocate(size_t n);
        void deallocate(T* p, size_t n);
      };
    }