From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1464) id BDD3D386F022; Wed, 19 Aug 2020 13:58:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BDD3D386F022 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1597845503; bh=5878uSh9guWjMgA2FNkD/uMYmBZOe0Z3Y7bxcrZFoPE=; h=From:To:Subject:Date:From; b=BjuiyFr/dXzqhFWTPb8wZdCZQs+EwHlo7z2DC6P0gJilBIJUhA0Ofqd38e3JdpHfd 0WlGs3XD+GzSMz3vXh5npd38SBcryd8y5Dqmvvo90SBMSgiAE0esSL2PIAuUv0WvF+ w8U2KB0sawcspxc7pYsJt//X/+4Lf9qzsCFoJZxQ= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Peter Bergner To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc(refs/vendors/ibm/heads/gcc-10-branch)] libstdc++: Fix ambiguous comparisons in __gnu_debug::bitset [PR 96303] X-Act-Checkin: gcc X-Git-Author: Jonathan Wakely X-Git-Refname: refs/vendors/ibm/heads/gcc-10-branch X-Git-Oldrev: 18ce60477b189cb5d26906f0d08235ed9b076a80 X-Git-Newrev: 7e26e4fbd4ee618dd991c6bbf3c5403aa90d2192 Message-Id: <20200819135823.BDD3D386F022@sourceware.org> Date: Wed, 19 Aug 2020 13:58:23 +0000 (GMT) X-BeenThere: libstdc++-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libstdc++-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 19 Aug 2020 13:58:23 -0000 https://gcc.gnu.org/g:7e26e4fbd4ee618dd991c6bbf3c5403aa90d2192 commit 7e26e4fbd4ee618dd991c6bbf3c5403aa90d2192 Author: Jonathan Wakely Date: Fri Aug 7 20:29:11 2020 +0100 libstdc++: Fix ambiguous comparisons in __gnu_debug::bitset [PR 96303] With -pedantic the debug mode bitset has an ambiguous equality comparison operator, because it tries to compare the non-debug base to the debug object. The base object can be converted to another debug bitset, making the same operator== a candidate again. The fix is to do the comparison on both base objects, so the operator for the derived type isn't a candidate. For the inequality operator the same change should be done, but that operator can be removed entirely for C++20 because it can be synthesized by the compiler. I don't think either equality or inequality operators are really needed, because the public _GLIBCXX_STD_C::bitset base class cam always be compared using its own comparison operators. I'm not changing that here though. libstdc++-v3/ChangeLog: PR libstdc++/96303 * include/debug/bitset (bitset::operator==): Call _M_base() on right operand. (bitset::operator!=): Likewise, but don't define it at all when default comparisons are supported by the compiler. * testsuite/23_containers/bitset/operations/96303.cc: New test. (cherry picked from commit de1e3b8795e507c3cfa5b62984272628ca62a9bd) Diff: --- libstdc++-v3/include/debug/bitset | 6 +++-- .../23_containers/bitset/operations/96303.cc | 31 ++++++++++++++++++++++ 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/libstdc++-v3/include/debug/bitset b/libstdc++-v3/include/debug/bitset index fb498012605..1b8dc6d422c 100644 --- a/libstdc++-v3/include/debug/bitset +++ b/libstdc++-v3/include/debug/bitset @@ -353,11 +353,13 @@ namespace __debug bool operator==(const bitset<_Nb>& __rhs) const _GLIBCXX_NOEXCEPT - { return _M_base() == __rhs; } + { return _M_base() == __rhs._M_base(); } +#if __cpp_impl_three_way_comparison < 201907L bool operator!=(const bitset<_Nb>& __rhs) const _GLIBCXX_NOEXCEPT - { return _M_base() != __rhs; } + { return _M_base() != __rhs._M_base(); } +#endif using _Base::test; using _Base::all; diff --git a/libstdc++-v3/testsuite/23_containers/bitset/operations/96303.cc b/libstdc++-v3/testsuite/23_containers/bitset/operations/96303.cc new file mode 100644 index 00000000000..ab31e3c47d5 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/bitset/operations/96303.cc @@ -0,0 +1,31 @@ +// Copyright (C) 2020 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// { dg-options "-std=gnu++2a -pedantic" } +// { dg-do compile { target c++2a } } + +#include + +bool +test01() +{ + __gnu_debug::bitset<1> b; + // PR libstdc++/96303 + bool eq = b == b; + bool ne = b != b; + return eq && !ne; +}