@@ -1065,13 +1065,15 @@ public:
10651065 basic_string (nullptr_t ) = delete;
10661066# endif
10671067
1068- _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string (const _CharT* __s, size_type __n) {
1068+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string (const _CharT* __s, size_type __n)
1069+ _LIBCPP_DIAGNOSE_NULLPTR_IF(__n != 0 && __s == nullptr , " if n is not zero" ) {
10691070 _LIBCPP_ASSERT_NON_NULL (__n == 0 || __s != nullptr , " basic_string(const char*, n) detected nullptr" );
10701071 __init (__s, __n);
10711072 }
10721073
10731074 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
10741075 basic_string (const _CharT* __s, size_type __n, const _Allocator& __a)
1076+ _LIBCPP_DIAGNOSE_NULLPTR_IF (__n != 0 && __s == nullptr , " if n is not zero" )
10751077 : __alloc_(__a) {
10761078 _LIBCPP_ASSERT_NON_NULL (__n == 0 || __s != nullptr , " basic_string(const char*, n, allocator) detected nullptr" );
10771079 __init (__s, __n);
@@ -1394,7 +1396,8 @@ public:
13941396 return append (__sv.data () + __pos, std::min (__n, __sz - __pos));
13951397 }
13961398
1397- _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& append (const value_type* __s, size_type __n);
1399+ _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& append (const value_type* __s, size_type __n)
1400+ _LIBCPP_DIAGNOSE_NULLPTR_IF(__n != 0 && __s == nullptr , " if n is not zero" );
13981401 _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& append (const value_type* _LIBCPP_DIAGNOSE_NULLPTR __s);
13991402 _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& append (size_type __n, value_type __c);
14001403
@@ -1521,8 +1524,9 @@ public:
15211524 return assign (__sv.data () + __pos, std::min (__n, __sz - __pos));
15221525 }
15231526
1524- _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& assign (const value_type* __s, size_type __n);
1525- _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& assign (const value_type* __s);
1527+ _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& assign (const value_type* __s, size_type __n)
1528+ _LIBCPP_DIAGNOSE_NULLPTR_IF(__n != 0 && __s == nullptr , " if n is not zero" );
1529+ _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& assign (const value_type* _LIBCPP_DIAGNOSE_NULLPTR __s);
15261530 _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& assign (size_type __n, value_type __c);
15271531
15281532 template <class _InputIterator , __enable_if_t <__has_exactly_input_iterator_category<_InputIterator>::value, int > = 0 >
@@ -1593,7 +1597,8 @@ public:
15931597
15941598 _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string&
15951599 insert (size_type __pos1, const basic_string& __str, size_type __pos2, size_type __n = npos);
1596- _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& insert (size_type __pos, const value_type* __s, size_type __n);
1600+ _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& insert (size_type __pos, const value_type* __s, size_type __n)
1601+ _LIBCPP_DIAGNOSE_NULLPTR_IF(__n != 0 && __s == nullptr , " if n is not zero" );
15971602 _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& insert (size_type __pos, const value_type* _LIBCPP_DIAGNOSE_NULLPTR __s);
15981603 _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& insert (size_type __pos, size_type __n, value_type __c);
15991604 _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator insert (const_iterator __pos, value_type __c);
@@ -1673,8 +1678,10 @@ public:
16731678 }
16741679
16751680 _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string&
1676- replace (size_type __pos, size_type __n1, const value_type* __s, size_type __n2);
1677- _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& replace (size_type __pos, size_type __n1, const value_type* __s);
1681+ replace (size_type __pos, size_type __n1, const value_type* __s, size_type __n2)
1682+ _LIBCPP_DIAGNOSE_NULLPTR_IF (__n2 != 0 && __s == nullptr , " if n2 is not zero" );
1683+ _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string&
1684+ replace (size_type __pos, size_type __n1, const value_type* _LIBCPP_DIAGNOSE_NULLPTR __s);
16781685 _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& replace (size_type __pos, size_type __n1, size_type __n2, value_type __c);
16791686
16801687 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string&
@@ -1783,7 +1790,8 @@ public:
17831790 return std::__str_find<value_type, size_type, traits_type, npos>(data (), size (), __sv.data (), __pos, __sv.size ());
17841791 }
17851792
1786- _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type find (const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT {
1793+ _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type find (const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT
1794+ _LIBCPP_DIAGNOSE_NULLPTR_IF(__n != 0 && __s == nullptr , " if n is not zero" ) {
17871795 _LIBCPP_ASSERT_NON_NULL (__n == 0 || __s != nullptr , " string::find(): received nullptr" );
17881796 return std::__str_find<value_type, size_type, traits_type, npos>(data (), size (), __s, __pos, __n);
17891797 }
@@ -1814,7 +1822,8 @@ public:
18141822 return std::__str_rfind<value_type, size_type, traits_type, npos>(data (), size (), __sv.data (), __pos, __sv.size ());
18151823 }
18161824
1817- _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type rfind (const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT {
1825+ _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type rfind (const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT
1826+ _LIBCPP_DIAGNOSE_NULLPTR_IF(__n != 0 && __s == nullptr , " if n is not zero" ) {
18181827 _LIBCPP_ASSERT_NON_NULL (__n == 0 || __s != nullptr , " string::rfind(): received nullptr" );
18191828 return std::__str_rfind<value_type, size_type, traits_type, npos>(data (), size (), __s, __pos, __n);
18201829 }
@@ -1847,7 +1856,8 @@ public:
18471856 }
18481857
18491858 _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type
1850- find_first_of (const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT {
1859+ find_first_of (const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT
1860+ _LIBCPP_DIAGNOSE_NULLPTR_IF (__n != 0 && __s == nullptr , " if n is not zero" ) {
18511861 _LIBCPP_ASSERT_NON_NULL (__n == 0 || __s != nullptr , " string::find_first_of(): received nullptr" );
18521862 return std::__str_find_first_of<value_type, size_type, traits_type, npos>(data (), size (), __s, __pos, __n);
18531863 }
@@ -1881,7 +1891,8 @@ public:
18811891 }
18821892
18831893 _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type
1884- find_last_of (const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT {
1894+ find_last_of (const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT
1895+ _LIBCPP_DIAGNOSE_NULLPTR_IF (__n != 0 && __s == nullptr , " if n is not zero" ) {
18851896 _LIBCPP_ASSERT_NON_NULL (__n == 0 || __s != nullptr , " string::find_last_of(): received nullptr" );
18861897 return std::__str_find_last_of<value_type, size_type, traits_type, npos>(data (), size (), __s, __pos, __n);
18871898 }
@@ -1915,7 +1926,8 @@ public:
19151926 }
19161927
19171928 _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type
1918- find_first_not_of (const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT {
1929+ find_first_not_of (const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT
1930+ _LIBCPP_DIAGNOSE_NULLPTR_IF (__n != 0 && __s == nullptr , " if n is not zero" ) {
19191931 _LIBCPP_ASSERT_NON_NULL (__n == 0 || __s != nullptr , " string::find_first_not_of(): received nullptr" );
19201932 return std::__str_find_first_not_of<value_type, size_type, traits_type, npos>(data (), size (), __s, __pos, __n);
19211933 }
@@ -1949,7 +1961,8 @@ public:
19491961 }
19501962
19511963 _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type
1952- find_last_not_of (const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT {
1964+ find_last_not_of (const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT
1965+ _LIBCPP_DIAGNOSE_NULLPTR_IF (__n != 0 && __s == nullptr , " if n is not zero" ) {
19531966 _LIBCPP_ASSERT_NON_NULL (__n == 0 || __s != nullptr , " string::find_last_not_of(): received nullptr" );
19541967 return std::__str_find_last_not_of<value_type, size_type, traits_type, npos>(data (), size (), __s, __pos, __n);
19551968 }
@@ -2026,7 +2039,8 @@ public:
20262039 }
20272040
20282041 _LIBCPP_CONSTEXPR_SINCE_CXX20 int
2029- compare (size_type __pos1, size_type __n1, const value_type* __s, size_type __n2) const ;
2042+ compare (size_type __pos1, size_type __n1, const value_type* __s, size_type __n2) const
2043+ _LIBCPP_DIAGNOSE_NULLPTR_IF (__n2 != 0 && __s == nullptr , " if n2 is not zero" );
20302044
20312045 // starts_with
20322046
@@ -3564,7 +3578,8 @@ operator==(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
35643578
35653579template <class _CharT , class _Traits , class _Allocator >
35663580inline _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI bool
3567- operator ==(const basic_string<_CharT, _Traits, _Allocator>& __lhs, const _CharT* __rhs) _NOEXCEPT {
3581+ operator ==(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3582+ const _CharT* _LIBCPP_DIAGNOSE_NULLPTR __rhs) _NOEXCEPT {
35683583 _LIBCPP_ASSERT_NON_NULL (__rhs != nullptr , " operator==(basic_string, char*): received nullptr" );
35693584
35703585 using _String = basic_string<_CharT, _Traits, _Allocator>;
0 commit comments