From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 7A2FF3858D39; Wed, 25 Aug 2021 13:25:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7A2FF3858D39 From: "redi at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/102064] Wrong assignable check in uninitialized_fill and uninitialized_fill_n Date: Wed, 25 Aug 2021 13:25:27 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: libstdc++ X-Bugzilla-Version: 12.0 X-Bugzilla-Keywords: rejects-valid X-Bugzilla-Severity: normal X-Bugzilla-Who: redi at gcc dot gnu.org X-Bugzilla-Status: ASSIGNED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: redi at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 25 Aug 2021 13:25:27 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D102064 --- Comment #1 from Jonathan Wakely --- The assignable checks are also missing for C++98, but there are types which= can be constructed via std::uninitialized_foo that cannot be assigned to by std::foo #include #include struct X; struct Y { operator X() const; }; struct X { private: void operator=3D(const Y&); }; Y::operator X() const { return X(); } int main() { unsigned char buf[sizeof(X)]; Y y; std::uninitialized_fill_n((X*)buf, 1, y); } This should copy-construct an X from the result of the conversion operator.= But we optimize it to std::fill_n which tries to use the inaccessible assignmen= t. /usr/include/c++/11/bits/stl_algobase.h:912:18: error: =E2=80=98void X::ope= rator=3D(const Y&)=E2=80=99 is private within this context 912 | *__first =3D __value; | ~~~~~~~~~^~~~~~~~~=