From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id D15873858D20; Thu, 30 May 2024 10:24:07 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D15873858D20 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1717064647; bh=bnn7JRrQyO1z5by4jmE+uq1IOCoxo7ci6zmB5nPuAQE=; h=From:To:Subject:Date:In-Reply-To:References:From; b=TmELc8c6oq4Pj5gWSFokQddA5cpjedIPEldLwTy3/1AX81jlIm6Z0VXf+JMGUVTww w50V0b/A/JDn2lPS5pC6gRCN6Trr43RnUy8HUqgAy9i3qq6sHbxHxJr/qrMueaMLLG QS219bBsCwxwn6a7dqffyx9sJFytDOhaBL/baTTs= From: "redi at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/115285] [12/13/14/15 Regression] std::unordered_set can have duplicate value Date: Thu, 30 May 2024 10:24:07 +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: 15.0 X-Bugzilla-Keywords: needs-bisection 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: 12.4 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 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D115285 --- Comment #9 from Jonathan Wakely --- (In reply to Andrew Pinski from comment #7) > I am suspecting it was > https://gcc.gnu.org/git/?p=3Dgcc.git;a=3Dcommit; > h=3D2c43f5ec9db163696de8691eb529df06c4999bcc which caused the issue. Ah no, I think you're right about this. The problem is not std::equal_to, but in std::hash, because it takes an argument of type std::string not TrimmedStr. This means that hashing "foo "s does not convert to a TrimmedStr first, so = it hashes the un-trimmed string. This fixes the code: template<> struct hash { bool operator()(const TrimmedStr& s) const noexcept { return std::hash{}(s); } }; I'm not sure if the code is valid or not. It certainly seems like a problem that a plain std::string can be compared to a TrimmedStr using std::equal_to *and* can be hashed using std::hash, = when a plain std::string is *not* a TrimmedStr. Using inheritance this way is a bad idea, certainly for the std::hash specialization. IMHO also for the TrimmedStr itself.=