Skip to content

Conversation

@philnik777
Copy link
Contributor

Allocators are generally very cheap to copy, so avoiding copies by having separate overloads is not that useful. Defaulting them significanlty reduces the overload set the compiler has to consider and simplifies the code, since we can remove some functions in the future.

@github-actions
Copy link

github-actions bot commented Nov 28, 2025

⚠️ C/C++ code formatter, clang-format found issues in your code. ⚠️

You can test this locally with the following command:
git-clang-format --diff origin/main HEAD --extensions ,cpp -- libcxx/include/string libcxx/test/std/utilities/optional/optional.specalg/make_optional_explicit.pass.cpp libcxx/test/std/utilities/optional/optional.specalg/make_optional_explicit_initializer_list.pass.cpp --diff_from_common_commit

⚠️
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing origin/main to the base branch/commit you want to compare against.
⚠️

View the diff from clang-format here.
diff --git a/libcxx/include/string b/libcxx/include/string
index ea90be950..133878fa2 100644
--- a/libcxx/include/string
+++ b/libcxx/include/string
@@ -1070,8 +1070,8 @@ public:
   basic_string(nullptr_t) = delete;
 #  endif
 
-  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
-  basic_string(const _CharT* __s, size_type __n, const _Allocator& __a = _Allocator())
+  _LIBCPP_HIDE_FROM_ABI
+  _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string(const _CharT* __s, size_type __n, const _Allocator& __a = _Allocator())
       _LIBCPP_DIAGNOSE_NULLPTR_IF(__n != 0 && __s == nullptr, " if n is not zero")
       : __alloc_(__a) {
     _LIBCPP_ASSERT_NON_NULL(__n == 0 || __s != nullptr, "basic_string(const char*, n, allocator) detected nullptr");
@@ -1168,8 +1168,8 @@ public:
 #  endif
 
 #  ifndef _LIBCPP_CXX03_LANG
-  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
-  basic_string(initializer_list<_CharT> __il, const _Allocator& __a = _Allocator())
+  _LIBCPP_HIDE_FROM_ABI
+  _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string(initializer_list<_CharT> __il, const _Allocator& __a = _Allocator())
       : __alloc_(__a) {
     __init(__il.begin(), __il.end());
   }

@philnik777 philnik777 force-pushed the string_default_allocator_argument branch from 03f92a9 to 191b796 Compare November 28, 2025 12:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant