From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id DD956385DDFB; Mon, 15 Jul 2024 14:34:14 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DD956385DDFB DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1721054054; bh=afpI/tUgdNMdwAK5NwtXAbLTdgK0ajeoJK3EpKYrgss=; h=From:To:Subject:Date:In-Reply-To:References:From; b=nCdW5U1kVH9ybLDxTi/mfuFAokvJhBgya/J7F8o5r2+ZxIVYr0e/vpd5J+aK6XrOZ Ej8Wm7r8f7yulnCPOUSfi+49+kqfxkw8x3FFkXWCZQbcdKAEkv443gKKgdASMIKPA0 CvcfuDT3eiR4p4a+ww/07MZx14EFuSp0jDX7BS3s= From: "redi at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/115939] Cannot unambiguously compare iterators in std::unordered_map with mapped type std::expected> Date: Mon, 15 Jul 2024 14:34:14 +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: 14.1.1 X-Bugzilla-Keywords: rejects-valid X-Bugzilla-Severity: normal X-Bugzilla-Who: redi at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: cf_reconfirmed_on bug_status everconfirmed 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 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D115939 Jonathan Wakely changed: What |Removed |Added ---------------------------------------------------------------------------- Last reconfirmed| |2024-07-15 Status|UNCONFIRMED |NEW Ever confirmed|0 |1 --- Comment #1 from Jonathan Wakely --- I think this is the expected (no pun intended) behaviour. It's a consequenc= e of std::any being constructible from anything, so the operator=3D=3D for expec= ted is a candidate for ... well ... anything. Your std::expected c= an be constructed from nearly every possible type, so the equality comparison considers a conversion to std::expected to be viable, and then= use the operator=3D=3D for std::expected. It doesn't help that the operator=3D=3D is a hidden friend, so only found b= y ADL, because your unordered_map::iterator has std::expected as an associated class, so the hidden friend is a candidate. The way libstdc++ defines the equality operator for unordered_map::iterator also involves conversions, from unordered_map::iterator to its _Node_iterator_base base class, so the C++ standard considers them ambiguou= s. Without -pedantic GCC does the right thing. I see two possible solutions to this, but neither of them is possible for y= ou. Firstly, I have a C++ standard proposal to constrain operator=3D=3D(expecte= d, U), so that it will not be viable if std::expected is not equality comparable with U (which ti isn't in this case, because U is the unordered_map::iterator). Secondly, we could add operator=3D=3D for the actual iterator type, so that= there's no derived-to-base conversion needed to find a candidate. I think the only workarounds available to you are to not use -pedantic, and= to not use std::any in this way, where it greedily converts from anything.=