public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "redi at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/102064] New: Wrong assignable check in uninitialized_fill and uninitialized_fill_n Date: Wed, 25 Aug 2021 12:10:19 +0000 [thread overview] Message-ID: <bug-102064-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102064 Bug ID: 102064 Summary: Wrong assignable check in uninitialized_fill and uninitialized_fill_n Product: gcc Version: 12.0 Status: UNCONFIRMED Keywords: rejects-valid Severity: normal Priority: P3 Component: libstdc++ Assignee: unassigned at gcc dot gnu.org Reporter: redi at gcc dot gnu.org Target Milestone: --- In r204615 I added assignable checks to various algos to fix PR libstdc++/58982. The checks in uninitialized_fill and uninitialized_fill_n use is_copy_assignable, which is wrong because the value being filled doesn't have to be the value type of the output range. This valid code fails to compile with libstdc++: #include <memory> #include <algorithm> struct X { X() = default; X(int) { } X(const X&) = default; X& operator=(const X&) = default; X& operator=(int) = delete; }; static_assert( std::is_trivial<X>::value, "" ); int main() { unsigned char buf[sizeof(X)]; std::uninitialized_fill_n((X*)buf, 1, 99); } /usr/include/c++/11/bits/stl_algobase.h:924:18: error: use of deleted function ‘X& X::operator=(int)’ 924 | *__first = __tmp; | ~~~~~~~~~^~~~~~~ The problem is that we decide it's OK to use std::fill_n because X is trivial and is_copy_assignable<X> is true, but then std::fill_n assigns int to X. We need to check is_assignable<X&, const int&> instead.
next reply other threads:[~2021-08-25 12:10 UTC|newest] Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-08-25 12:10 redi at gcc dot gnu.org [this message] 2021-08-25 12:10 ` [Bug libstdc++/102064] " redi at gcc dot gnu.org 2021-08-25 13:25 ` redi at gcc dot gnu.org 2021-08-25 21:29 ` cvs-commit at gcc dot gnu.org
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-102064-4@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).