public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/113294] New: constexpr error from accessing inactive union member in basic_string after move assignment
@ 2024-01-09 17:04 pkeir at outlook dot com
2024-01-10 0:25 ` [Bug libstdc++/113294] " pinskia at gcc dot gnu.org
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: pkeir at outlook dot com @ 2024-01-09 17:04 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113294
Bug ID: 113294
Summary: constexpr error from accessing inactive union member
in basic_string after move assignment
Product: gcc
Version: 14.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: libstdc++
Assignee: unassigned at gcc dot gnu.org
Reporter: pkeir at outlook dot com
Target Milestone: ---
The C++20 program below fails to compile. A call to `basic_string::clear()` in
the move assignment operator leads to an access of inactive union member
`_M_local_buf`.
#include <string>
constexpr bool string_test1()
{
{
std::string str1; // = "1"; // also a problem when small (less than 16)
std::string str2 = "1234567890123456"; // 16 chars
str1 = std::move(str2);
}
return true;
}
static_assert(string_test1());
Changing `__str._M_data(__str._M_local_buf);` to
`__str._M_data(__str._M_use_local_data());` in basic_string.h seems to fix it,
though I've not had time to test it fully. With this solution, the function
below also remains functional:
constexpr bool string_test2()
{
{
std::string str = "1234567890123456"; // 16 chars
str = std::string{"1234567890123456"}; // rvalue assignment
}
return true;
}
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug libstdc++/113294] constexpr error from accessing inactive union member in basic_string after move assignment
2024-01-09 17:04 [Bug libstdc++/113294] New: constexpr error from accessing inactive union member in basic_string after move assignment pkeir at outlook dot com
@ 2024-01-10 0:25 ` pinskia at gcc dot gnu.org
2024-01-23 16:45 ` ppalka at gcc dot gnu.org
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-01-10 0:25 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113294
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Note this might be a front-end issue ...
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug libstdc++/113294] constexpr error from accessing inactive union member in basic_string after move assignment
2024-01-09 17:04 [Bug libstdc++/113294] New: constexpr error from accessing inactive union member in basic_string after move assignment pkeir at outlook dot com
2024-01-10 0:25 ` [Bug libstdc++/113294] " pinskia at gcc dot gnu.org
@ 2024-01-23 16:45 ` ppalka at gcc dot gnu.org
2024-02-12 23:19 ` cvs-commit at gcc dot gnu.org
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: ppalka at gcc dot gnu.org @ 2024-01-23 16:45 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113294
Patrick Palka <ppalka at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Last reconfirmed| |2024-01-23
Status|UNCONFIRMED |NEW
Ever confirmed|0 |1
CC| |ppalka at gcc dot gnu.org
--- Comment #2 from Patrick Palka <ppalka at gcc dot gnu.org> ---
The front end started rejecting the testcase (with libstdc++ 12, 13 and 14
headers) after the active union member change tracking improvements r14-4771.
Clang also rejects the testcase with libstdc++ 13 headers, which points to this
being a library bug unlike the other related PRs about constexpr std::string.
Your proposed fix looks good to me.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug libstdc++/113294] constexpr error from accessing inactive union member in basic_string after move assignment
2024-01-09 17:04 [Bug libstdc++/113294] New: constexpr error from accessing inactive union member in basic_string after move assignment pkeir at outlook dot com
2024-01-10 0:25 ` [Bug libstdc++/113294] " pinskia at gcc dot gnu.org
2024-01-23 16:45 ` ppalka at gcc dot gnu.org
@ 2024-02-12 23:19 ` cvs-commit at gcc dot gnu.org
2024-02-16 15:21 ` cvs-commit at gcc dot gnu.org
2024-02-16 15:31 ` ppalka at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-02-12 23:19 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113294
--- Comment #3 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Patrick Palka <ppalka@gcc.gnu.org>:
https://gcc.gnu.org/g:065dddc6e07a917c57c7955db13b1fe77abbcabc
commit r14-8943-g065dddc6e07a917c57c7955db13b1fe77abbcabc
Author: Paul Keir <paul.keir@uws.ac.uk>
Date: Mon Feb 12 18:15:49 2024 +0000
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>
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug libstdc++/113294] constexpr error from accessing inactive union member in basic_string after move assignment
2024-01-09 17:04 [Bug libstdc++/113294] New: constexpr error from accessing inactive union member in basic_string after move assignment pkeir at outlook dot com
` (2 preceding siblings ...)
2024-02-12 23:19 ` cvs-commit at gcc dot gnu.org
@ 2024-02-16 15:21 ` cvs-commit at gcc dot gnu.org
2024-02-16 15:31 ` ppalka at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-02-16 15:21 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113294
--- Comment #4 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-13 branch has been updated by Patrick Palka
<ppalka@gcc.gnu.org>:
https://gcc.gnu.org/g:ebe00c9d3a0436dec5c354a62d98e444d763ff95
commit r13-8335-gebe00c9d3a0436dec5c354a62d98e444d763ff95
Author: Paul Keir <paul.keir@uws.ac.uk>
Date: Mon Feb 12 18:15:49 2024 +0000
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)
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug libstdc++/113294] constexpr error from accessing inactive union member in basic_string after move assignment
2024-01-09 17:04 [Bug libstdc++/113294] New: constexpr error from accessing inactive union member in basic_string after move assignment pkeir at outlook dot com
` (3 preceding siblings ...)
2024-02-16 15:21 ` cvs-commit at gcc dot gnu.org
@ 2024-02-16 15:31 ` ppalka at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: ppalka at gcc dot gnu.org @ 2024-02-16 15:31 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113294
Patrick Palka <ppalka at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |FIXED
Target Milestone|--- |13.3
Status|NEW |RESOLVED
--- Comment #5 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Fixed for GCC 13.3/14 thanks for the report and patch!
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2024-02-16 15:31 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-09 17:04 [Bug libstdc++/113294] New: constexpr error from accessing inactive union member in basic_string after move assignment pkeir at outlook dot com
2024-01-10 0:25 ` [Bug libstdc++/113294] " pinskia at gcc dot gnu.org
2024-01-23 16:45 ` ppalka at gcc dot gnu.org
2024-02-12 23:19 ` cvs-commit at gcc dot gnu.org
2024-02-16 15:21 ` cvs-commit at gcc dot gnu.org
2024-02-16 15:31 ` ppalka at gcc dot gnu.org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).