]> git.ipfire.org Git - thirdparty/gcc.git/commit
libstdc++: Fix constexpr basic_string union member [PR113294]
authorPaul Keir <paul.keir@uws.ac.uk>
Mon, 12 Feb 2024 18:15:49 +0000 (18:15 +0000)
committerPatrick Palka <ppalka@redhat.com>
Fri, 16 Feb 2024 15:19:33 +0000 (10:19 -0500)
commitebe00c9d3a0436dec5c354a62d98e444d763ff95
tree449b82d3a4fcab09a40fcd888c03e486a025574a
parent3a72c717b311ce8093042d927a1f2f2b940a969c
libstdc++: Fix constexpr basic_string union member [PR113294]

A call to `basic_string::clear()` in the std::string move assignment
operator leads to a constexpr error from an access of inactive union
member `_M_local_buf` in the added test (`test_move()`). Changing
`__str._M_local_buf` to `__str._M_use_local_data()` in
`operator=(basic_string&& __str)` fixes this.

PR libstdc++/113294

libstdc++-v3/ChangeLog:

* include/bits/basic_string.h (basic_string::operator=): Use
_M_use_local_data() instead of _M_local_buf on the moved-from
string.
* testsuite/21_strings/basic_string/modifiers/constexpr.cc
(test_move): New test.

Signed-off-by: Paul Keir <paul.keir@uws.ac.uk>
Reviewed-by: Patrick Palka <ppalka@redhat.com>
Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
(cherry picked from commit 065dddc6e07a917c57c7955db13b1fe77abbcabc)
libstdc++-v3/include/bits/basic_string.h
libstdc++-v3/testsuite/21_strings/basic_string/modifiers/constexpr.cc