[libcxx-commits] [libcxx] [libc++] Default the allocator argument for most string constructors (PR #169901)

via libcxx-commits libcxx-commits at lists.llvm.org
Wed Jul 8 08:03:46 PDT 2026


bgra8 wrote:

@philnik777 this CL is breaking code using strings with custom allocators.

This code no longer compiles after this revision:

```c++
#include <cstddef>
#include <memory>
#include <scoped_allocator>
#include <string>
#include <type_traits>

template <typename T>
struct Alloc {
  using value_type = T;
  using size_type = size_t;
  using difference_type = ptrdiff_t;

  constexpr Alloc(int) {}

  template <typename U>
  constexpr Alloc(Alloc<U>) {}

  friend constexpr bool operator==(Alloc, Alloc) { return true; }

  T* allocate(size_t);
  void deallocate(void*, size_t);
};

using AllocString =
    std::basic_string<char, std::char_traits<char>, Alloc<char>>;

int main() {
  printf("is_constructible<AllocString, char*>=%d\n",
         std::is_constructible_v<AllocString, char*>);
}
```

The error we get is:

```
src/libcxx/include/string:1010:84: error: no matching constructor for initialization of 'Alloc<char>'
 1010 |   basic_string(const _CharT* _LIBCPP_DIAGNOSE_NULLPTR __s, const _Allocator& __a = _Allocator())
      |                                                                                    ^
src/libcxx/include/__type_traits/is_constructible.h:27:71: note: in instantiation of default function argument expression for 'basic_string<0>' required here
   27 | _LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_constructible_v = __is_constructible(_Tp, _Args...);
```

Can you please take a look?

https://github.com/llvm/llvm-project/pull/169901


More information about the libcxx-commits mailing list