This patch implements LWG3662 for both ABIs of strings.
libstdc++-v3/ChangeLog:
* include/bits/basic_string.h(append, assign): Add new
overloads.
* include/bits/cow_string.h(append, assign): Ditto.
* testsuite/21_strings/basic_string/modifiers/append/char/2.cc:
Test new overloads.
* testsuite/21_strings/basic_string/modifiers/append/wchar_t/2.cc:
Ditto.
* testsuite/21_strings/basic_string/modifiers/assign/char/3.cc:
Ditto.
* testsuite/21_strings/basic_string/modifiers/assign/wchar_t/3.cc:
Ditto.
+ std::__sv_check(__sv.size(), __pos, "basic_string::append"),
std::__sv_limit(__sv.size(), __pos, __n));
}
+
+ // _GLIBCXX_RESOLVE_LIB_DEFECTS
+ // 3662. basic_string::append/assign(NTBS, pos, n) suboptimal
+ /**
+ * @brief Append a C substring.
+ * @param __s The C string to append.
+ * @param __pos The position in the C string to append from.
+ * @param __n The number of characters to append.
+ * @return Reference to this string.
+ */
+ _GLIBCXX20_CONSTEXPR
+ basic_string&
+ append(const _CharT* __s, size_type __pos, size_type __n)
+ { return append(__sv_type(__s).substr(__pos, __n)); }
#endif // C++17
/**
+ std::__sv_check(__sv.size(), __pos, "basic_string::assign"),
std::__sv_limit(__sv.size(), __pos, __n));
}
+
+ // _GLIBCXX_RESOLVE_LIB_DEFECTS
+ // 3662. basic_string::append/assign(NTBS, pos, n) suboptimal
+ /**
+ * @brief Set value to a C substring.
+ * @param __s The C string to use.
+ * @param __pos The position in the C string to assign from.
+ * @param __n Number of characters to use.
+ * @return Reference to this string.
+ */
+ _GLIBCXX20_CONSTEXPR
+ basic_string&
+ assign(const _CharT* __s, size_type __pos, size_type __n)
+ { return assign(__sv_type(__s).substr(__pos, __n)); }
#endif // C++17
#if __cplusplus >= 201103L
+ std::__sv_check(__sv.size(), __pos, "basic_string::append"),
std::__sv_limit(__sv.size(), __pos, __n));
}
+
+ // _GLIBCXX_RESOLVE_LIB_DEFECTS
+ // 3662. basic_string::append/assign(NTBS, pos, n) suboptimal
+ /**
+ * @brief Append a C substring.
+ * @param __s The C string to append.
+ * @param __pos The position in the C string to append from.
+ * @param __n The number of characters to append.
+ * @return Reference to this string.
+ */
+ basic_string&
+ append(const _CharT* __s, size_type __pos, size_type __n)
+ { return append(__sv_type(__s).substr(__pos, __n)); }
#endif // C++17
/**
+ std::__sv_check(__sv.size(), __pos, "basic_string::assign"),
std::__sv_limit(__sv.size(), __pos, __n));
}
+
+ // _GLIBCXX_RESOLVE_LIB_DEFECTS
+ // 3662. basic_string::append/assign(NTBS, pos, n) suboptimal
+ /**
+ * @brief Set value to a C substring.
+ * @param __s The C string to use.
+ * @param __pos The position in the C string to assign from.
+ * @param __n Number of characters to use.
+ * @return Reference to this string.
+ */
+ basic_string&
+ assign(const _CharT* __s, size_type __pos, size_type __n)
+ { return assign(__sv_type(__s).substr(__pos, __n)); }
#endif // C++17
/**
// 21.3.5 string modifiers
+#include <stdexcept>
#include <string>
#include <testsuite_hooks.h>
// append(const _CharT* __s, size_type __n)
// append(const _CharT* __s)
+// append(const _CharT* __s, size_type __pos, size_type __n)
void
test02()
{
two.append(two.c_str(), 3);
VERIFY( two == "Written in your eyeseyesWri" );
+
+ two.append(two.c_str(), 8, 2);
+ VERIFY( two == "Written in your eyeseyesWriin" );
+
+ try {
+ two.append("a\0b", 2, 1);
+ VERIFY( false );
+ }
+ catch(std::out_of_range& fail) {
+ VERIFY( true );
+ }
+ catch(...) {
+ VERIFY( false );
+ }
}
int main()
// 21.3.5 string modifiers
+#include <stdexcept>
#include <string>
#include <testsuite_hooks.h>
// append(const _CharT* __s, size_type __n)
// append(const _CharT* __s)
+// append(const _CharT* __s, size_type __pos, size_type __n)
void
test02()
{
two.append(two.c_str(), 3);
VERIFY( two == L"Written in your eyeseyesWri" );
+
+ two.append(two.c_str(), 8, 2);
+ VERIFY( two == L"Written in your eyeseyesWriin" );
+
+ try {
+ two.append(L"a\0b", 2, 1);
+ VERIFY( false );
+ }
+ catch(std::out_of_range& fail) {
+ VERIFY( true );
+ }
+ catch(...) {
+ VERIFY( false );
+ }
}
int main()
// 21.3.5 string modifiers
+#include <stdexcept>
#include <string>
#include <testsuite_hooks.h>
// assign(const _CharT* __s, size_type __n)
// assign(const _CharT* __s)
+// assign(const _CharT* __s, size_type __pos, size_type __n)
void
test03()
{
one.assign(one.c_str() + 8, 6);
VERIFY( one == "by the" );
+
+ one.assign(one.c_str(), 3, 3);
+ VERIFY( one == "the" );
+
+ try {
+ one.assign("a\0b", 2, 1);
+ VERIFY( false );
+ }
+ catch(std::out_of_range& fail) {
+ VERIFY( true );
+ }
+ catch(...) {
+ VERIFY( false );
+ }
}
int main()
// 21.3.5 string modifiers
+#include <stdexcept>
#include <string>
#include <testsuite_hooks.h>
// assign(const _CharT* __s, size_type __n)
// assign(const _CharT* __s)
+// assign(const _CharT* __s, size_type __pos, size_type __n)
void
test03()
{
one.assign(one.c_str() + 8, 6);
VERIFY( one == L"by the" );
+
+ one.assign(one.c_str(), 3, 3);
+ VERIFY( one == L"the" );
+
+ try {
+ one.assign(L"a\0b", 2, 1);
+ VERIFY( false );
+ }
+ catch(std::out_of_range& fail) {
+ VERIFY( true );
+ }
+ catch(...) {
+ VERIFY( false );
+ }
}
int main()