diff options
author | Jonathan Wakely <jwakely@redhat.com> | 2020-08-07 20:29:11 +0100 |
---|---|---|
committer | Jonathan Wakely <jwakely@redhat.com> | 2020-08-07 20:29:11 +0100 |
commit | de1e3b8795e507c3cfa5b62984272628ca62a9bd (patch) | |
tree | 6f23a36ecf57b28a78f87cec837069e3eabe5147 /libstdc++-v3/include/debug | |
parent | a1ee6d507b0c26466be519d177f5a08b22f63647 (diff) |
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.
Diffstat (limited to 'libstdc++-v3/include/debug')
-rw-r--r-- | libstdc++-v3/include/debug/bitset | 6 |
1 files changed, 4 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; |