aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Wakely <jwakely@redhat.com>2024-03-27 11:07:17 +0000
committerJonathan Wakely <redi@gcc.gnu.org>2024-08-01 21:56:55 +0100
commit6586b015f1211ccd6e3e89b44dcb2116347edf89 (patch)
treefff5c46c67c1ea2412481d92c248fd81df4160fe
parentf15cd1802129454029f7fcc8ee3ddd56a86cdad8 (diff)
downloadgcc-6586b015f1211ccd6e3e89b44dcb2116347edf89.zip
gcc-6586b015f1211ccd6e3e89b44dcb2116347edf89.tar.gz
gcc-6586b015f1211ccd6e3e89b44dcb2116347edf89.tar.bz2
libstdc++: Remove noexcept from non-const std::basic_string::data() [PR99942]
The C++17 non-const overload of data() allows modifying the string contents directly, so for the COW string we must do a copy-on-write to unshare it. That means allocating, which can throw, so it shouldn't be noexcept. libstdc++-v3/ChangeLog: PR libstdc++/99942 * include/bits/cow_string.h (data()): Change to noexcept(false).
-rw-r--r--libstdc++-v3/include/bits/cow_string.h7
1 files changed, 6 insertions, 1 deletions
diff --git a/libstdc++-v3/include/bits/cow_string.h b/libstdc++-v3/include/bits/cow_string.h
index 5d81bfc..75a2d88 100644
--- a/libstdc++-v3/include/bits/cow_string.h
+++ b/libstdc++-v3/include/bits/cow_string.h
@@ -2267,9 +2267,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
*
* This is a pointer to the character sequence held by the string.
* Modifying the characters in the sequence is allowed.
+ *
+ * The standard requires this function to be `noexcept` but for the
+ * Copy-On-Write string implementation it can throw. This function
+ * allows modifying the string contents directly, which means we
+ * must copy-on-write to unshare it, which requires allocating memory.
*/
_CharT*
- data() noexcept
+ data() noexcept(false)
{
_M_leak();
return _M_data();