This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of New status.

4451. make_shared should not refer to a type U[N] for runtime N

Section: 20.3.2.2.7 [util.smartptr.shared.create] Status: New Submitter: Jonathan Wakely Opened: 2025-11-05 Last modified: 2025-11-06

Priority: Not Prioritized

View other active issues in [util.smartptr.shared.create].

View all other issues in [util.smartptr.shared.create].

View all issues with New status.

Discussion:

Addresses US 76-139

The overloads of make_shared and allocate_shared for creating shared_ptr<T[]> refer to an object a type U[N] where N is a function parameter not a constant expression.

Proposed resolution:

This wording is relative to N5014.

  1. Modify 20.3.2.2.7 [util.smartptr.shared.create], as indicated:

    template<class T>
      constexpr shared_ptr<T> make_shared(size_t N); // T is U[]
    template<class T, class A>
      constexpr shared_ptr<T> allocate_shared(const A& a, size_t N); // T is U[]
    

    -12- Constraints: T is of the form U[] an array of unknown bound.

    -13- Returns: A shared_ptr to an object of type U[N] array of N elements of type remove_extent_t<T> with a default initial value, where U is remove_extent_t<T>.

    -14- [Example 2: ...]

    template<class T>
      constexpr shared_ptr<T> make_shared(); // T is U[N]
    template<class T, class A>
      constexpr shared_ptr<T> allocate_shared(const A& a); // T is U[N]
    

    -15- Constraints: T is of the form U[N] an array of known bound.

    -16- Returns: A shared_ptr to an object of type T with a default initial value.

    -17- [Example 3: ...]

    template<class T>
      constexpr shared_ptr<T> make_shared(size_t N,
                                             const remove_extent_t<T>& u); // T is U[]
    template<class T, class A>
      constexpr shared_ptr<T> allocate_shared(const A& a, size_t N,
                                                 const remove_extent_t<T>& u); // T is U[]
    

    -18- Constraints: T is of the form U[] an array of unknown bound.

    -19- Returns: A shared_ptr to an object of type U[N] array of N elements of type remove_extent_t<T> where U is remove_extent_t<T> and each array element has an initial value of u.

    -20- [Example 4: ...]

    template<class T>
      constexpr shared_ptr<T> make_shared(const remove_extent_t<T>& u); // T is U[N]
    template<class T, class A>
      constexpr shared_ptr<T> allocate_shared(const A& a,
                                          const remove_extent_t<T>& u); // T is U[N]
    

    -21- Constraints: T is of the form U[N] an array of known bound.

    -22- Returns: A shared_ptr to an object of type T, where each array element of type remove_extent_t<T> has an initial value of u.

    -23- [Example 5: ...]

    template<class T>
      constexpr shared_ptr<T> make_shared_for_overwrite(); // T is U[N]
    template<class T, class A>
      constexpr shared_ptr<T> allocate_shared_for_overwrite(const A& a); // T is U[N]
    

    -24- Constraints: T is not an array of unknown bound.

    -25- Returns: A shared_ptr to an object of type T.

    -26- [Example 6: ...]

    template<class T>
      constexpr shared_ptr<T> make_shared_for_overwrite(size_t N); // T is U[]
    template<class T, class A>
      constexpr shared_ptr<T> allocate_shared_for_overwrite(const A& a, size_t N); // T is U[]
    

    -27- Constraints: T is an array of unknown bound.

    -28- Returns: A shared_ptr to an object of type U[N] array of N elements of type remove_extent_t<T> , where U is remove_extent_t<T>.

    -29- [Example 7: ...]